KhronosGroup / KhronosGroup/WebGL

row_major qualifier for square matrices works strangely.

Open
#3,062 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
HTML
Stars
2.9k
Forks
703
Avg merge
2d 9h
Merged PRs (30d)
4

Description

I just wrote a demo from :
```


Row-major matrix test





#version 300 es
out vec2 pos;
in vec4 vPosition;
in vec2 texCoord0;
void main()
{
pos = texCoord0;
pos.y = 1.0 - pos.y;
gl_Position = vPosition;
}

#version 300 es
precision mediump float;
in highp vec2 pos;
layout (location = 0) out vec4 my_FragColor;
uniform vec4 m[4];
layout(std140, row_major) uniform type_m2 {
mat4 mat;
} m2;
void main()
{
my_FragColor = vec4(m2.mat[int(floor(pos.x * 4.0))][int(floor(pos.y * 4.0))], 0.0, 0.0, 1.0);
}


"use strict";
description("Row-major matrix layouts should work.");

GLSLConformanceTester.runRenderTests([
{
vShaderId: 'vshaderUniformMatrixRowMajor',
vShaderSuccess: true,
fShaderId: 'fshaderUniformMatrixRowMajor',
fShaderSuccess: true,
linkSuccess: true,
passMsg: '',
uniformBlocks: [{
name: "type_m2", value: new Float32Array([
0, 0.2, 0.4, 0.6,
1, 0.1, 0.3, 0.5,
0, 0, 0, 0,
1, 1, 1, 1,
])
}]
}
], 2);

```
On win10 Chrome 81.0.4044.129

I got the result: Shader with row_major qualifier

![Shader with row_major qualifier][1]

I cannot figure out why it looks like this.

When I remove the row_major qualifier, I got another result:

Shader without row_major qualifier ( **Do not care about the html wording in the image below, this is column_major** )

![Shader without row_major qualifier][2]

And this is expected result.

------------------------------------------------------------------------------

To make things clear:
My question is that two result should be transposed from each other since they use the same matrix data. The shader tries to paint each float number in matrix which ranges from 0 to 1 to the red channel. However shader with row_major (the first result) shows that the element in matrix is either 0 or 1, but this is not the fact. And the second result exactly do what is expected.

[1]: https://i.stack.imgur.com/K4PtK.png
[2]: https://i.stack.imgur.com/8EDeh.png

Contributor guide

Open the contributing guide

Research direction

Start by running the linked Khronos matrix-row-major conformance test and comparing the inline vertex and fragment shaders with and without row_major. Check whether the observed output matches the same matrix data under the two layouts; done means the discrepancy is explained and the relevant WebGL behavior or regression coverage is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.