矢量 vec3 和浮点数的 GLSL 总和
GLSL sum of vector vec3 and float
这可能很奇怪,因为据我所知,矢量和标量不能相加。但是我发现 this sample 并在第 157 行执行以下操作:
hsv.x + vec3(0.,2./3.,1./3.)
其中 hsv.x
恰好是一个 float
数字,该值来自鼠标 X 坐标,其余为 vec3
.
我的问题是该操作的结果是什么?
如果将标量添加到向量,则标量将添加到向量的每个分量,因为 The OpenGL Shading Language 规范(版本 4.6,第 5 章运算符和表达式)说:
One operand is a scalar, and the other is a vector or matrix. In this case, the scalar operation is
applied independently to each component of the vector or matrix, resulting in the same size vector
or matrix.
这可能很奇怪,因为据我所知,矢量和标量不能相加。但是我发现 this sample 并在第 157 行执行以下操作:
hsv.x + vec3(0.,2./3.,1./3.)
其中 hsv.x
恰好是一个 float
数字,该值来自鼠标 X 坐标,其余为 vec3
.
我的问题是该操作的结果是什么?
如果将标量添加到向量,则标量将添加到向量的每个分量,因为 The OpenGL Shading Language 规范(版本 4.6,第 5 章运算符和表达式)说:
One operand is a scalar, and the other is a vector or matrix. In this case, the scalar operation is applied independently to each component of the vector or matrix, resulting in the same size vector or matrix.