Matrix components and dot product
I have the following GLSL code:
uniform mat3x3 rgb2xyz = mat3x3(
vec3(DEFAULT_RGB2XYZ_XR, DEFAULT_RGB2XYZ_XG, DEFAULT_RGB2XYZ_XB),
vec3(DEFAULT_RGB2XYZ_YR, DEFAULT_RGB2XYZ_YG, DEFAULT_RGB2XYZ_YB),
vec3(DEFAULT_RGB2XYZ_ZR, DEFAULT_RGB2XYZ_ZG, DEFAULT_RGB2XYZ_ZB)
);
vec3 RGBtoXYZ(vec3 rgb)
{
// Works
float X = DEFAULT_RGB2XYZ_XR * rgb.r + DEFAULT_RGB2XYZ_XG * rgb.g + DEFAULT_RGB2XYZ_XB * rgb.b;
float Y = DEFAULT_RGB2XYZ_YR * rgb.r + DEFAULT_RGB2XYZ_YG * rgb.g + DEFAULT_RGB2XYZ_YB * rgb.b;
float Z = DEFAULT_RGB2XYZ_ZR * rgb.r + DEFAULT_RGB2XYZ_ZG * rgb.g + DEFAULT_RGB2XYZ_ZB * rgb.b;
开发者_开发问答 return vec3(X, Y, Z);
// Don't work
/*float X = rgb2xyz[0][0] * rgb.r + rgb2xyz[0][1] * rgb.g + rgb2xyz[0][2] * rgb.b;
float Y = rgb2xyz[1][0] * rgb.r + rgb2xyz[1][1] * rgb.g + rgb2xyz[1][2] * rgb.b;
float Z = rgb2xyz[2][0] * rgb.r + rgb2xyz[2][1] * rgb.g + rgb2xyz[2][2] * rgb.b;
return vec3(X, Y, Z);*/
// Don't work
/*return vec3(
dot(rgb2xyz[0], rgb),
dot(rgb2xyz[1], rgb),
dot(rgb2xyz[2], rgb)
);*/
}
The routine RGBtoXYZ have three code blocks (the last two commented). The first one work as expected, while the other commented ones does not work.
The problem is that I think they are equivalent. Why they are not?
I can't believe it!
The Paul-Jan edit has resolved my issue!
Simply the GLSL compiler do not emit error on matrix initialization! I can't believe it!
I'm curious of your comments here, I'm thinking to open another question on this issue.
精彩评论