这可能很奇怪,因为据我了解,向量和标量无法相加。然而我发现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.
关于opengl - 向量 vec3 和 float 的 GLSL 总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45499944/