Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniform arrays of mat4 type are set incorrectly when an Array of Transform3D is supplied #64051

Closed
cdemirer opened this issue Aug 7, 2022 · 2 comments · Fixed by #74937
Closed

Comments

@cdemirer
Copy link
Contributor

cdemirer commented Aug 7, 2022

Godot version

3b39f00

System information

Linux

Issue description

While you can set a uniform mat4 x; using a Transform3D, you can't set a uniform mat4 x[N]; using an Array of Transform3Ds (the values visible to the shader will be corrupted / incorrect). Instead, currently you have to convert the Array of Transform3Ds to a flattened PackedFloat32Array and use that as the parameter of set_shader_param.

I think the reason might be that the conversion in this line doesn't work as expected:

const PackedFloat32Array &a = value;

Somewhat related: #63064

Steps to reproduce

Given this uniform:

uniform mat4 x[1];

This doesn't work (results in bad values in shader):

my_shader_material.set_shader_param("x", [global_transform])

This works:

my_shader_material.set_shader_param("x", global_transform_as_16_floats_in_packed_array)

Minimal reproduction project

No response

@Calinou Calinou added this to the 4.0 milestone Aug 7, 2022
@clayjohn
Copy link
Member

Implementation here:

if (p_array_size > 0) {
const PackedFloat32Array &a = value;
int s = a.size();
for (int i = 0; i < p_array_size * 16; i += 16) {

the conditional checks whether an array is passed, if so, it reads the data like an array of floats, otherwise, if the variant is a transform, it will read the transform directly. I guess we need another conditional within the array branch to see if the array contains Transform3Ds, or we need to at least to error in the case that an array other than a PackedFloat32Array is used

@faylite
Copy link

faylite commented Mar 25, 2023

I've encountered the same issue with arrays of mat3 and Basis. But I see @bitsawer is already ahead of the curve here 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants