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

[glsl-in] Matrix construction inconsistencies and errors #4897

Open
Vipitis opened this issue Dec 19, 2023 · 0 comments
Open

[glsl-in] Matrix construction inconsistencies and errors #4897

Vipitis opened this issue Dec 19, 2023 · 0 comments
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working

Comments

@Vipitis
Copy link

Vipitis commented Dec 19, 2023

Description
The GLSL Documentation Wiki for Matrix construction isn't that clear to me: https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Matrix_constructors and the spec goes into further detail: https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.50.pdf (chapter 5.4.2, pp. 98..101)

The observation is as follows:

// identity matrix works
mat2 a = mat2(0.1);
    
// from vec2 both work
mat2 b1 = mat2(vec2(0.2));
mat2 b2 = mat2(vec2(0.2), vec2(0.2));

// with floats works
mat2 c = mat2(0.3, 0.3, 0.3, 0.3);
    
//with a vec4 - does not work!
mat2 d = mat2(vec4(0.4));

// some mixture of vec2 and float: e1 and e2 aren't enough components, e3-e5 work, e6 does not
// mat2 e1 = mat2(vec2(0.5), 0.5);
// mat2 e2 = mat2(0.5, vec2(0.5));
mat2 e3 = mat2(vec2(0.5), 0.5, 0.5);
mat2 e4 = mat2(0.5, vec2(0.5), 0.5);
mat2 e5 = mat2(0.5, 0.5, vec2(0.5));
mat2 e6 = mat2(0.5, 0.5, 0.5, vec2(0.5));

Constructing mat2 d throws an error: Composing 0's component type is not expected.
Constructing mat2 e6 also throws and error: Composing expects 2 components but 1 were given (somewhat misleading error)

My reference is Shadertoy where b1 does not work but d works (and e6 as well). Example: https://www.shadertoy.com/view/4cl3Wn
I have no tried matrices of other shapes.
Since a lot of shaders on Shadertoy use mat2 construction in combination with swizzling, this seemingly account for 10% of validation errors pygfx/shadertoy#15.

Platform
using naga-cli 0.14.0 and wgpu-native 0.18.1.3 (all recent glsl commits are missed, it might be addressed already)

@Vipitis Vipitis changed the title [glsl-in] Matrix construction from inconsistencies and errors [glsl-in] Matrix construction inconsistencies and errors Dec 19, 2023
@teoxoy teoxoy added type: bug Something isn't working naga Shader Translator area: naga front-end lang: GLSL OpenGL Shading Language labels Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants