矩阵分量和点积
我有以下 GLSL 代码:
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)
);*/
}
例程 RGBtoXYZ 具有三个代码块(最后两个已注释)。第一个按预期工作,而其他评论的则不起作用。
问题是我认为它们是等价的。为什么他们不是?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我简直不敢相信!
Paul-Jan 编辑解决了我的问题!
GLSL 编译器不会在矩阵初始化时发出错误! 我简直不敢相信!
我很好奇您在这里的评论,我正在考虑就这个问题提出另一个问题。
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.