将“/”运算符与球体 material 属性和浮点数一起使用时出错 (glsl)
Error when using '/' operator with sphere material attribute and a float (glsl)
我正在片段着色器中为球体实现简单的光线追踪。在这一点上,我目前正在研究为漫射阴影球体计算颜色的函数。我遇到的问题是我正在尝试使用以下等式从表面点计算法向量:N = (S - sph.xyz) / sph.r
但是,当我尝试将其转换为 glsl 时,出现了这些操作数不能与“/”运算符一起使用的错误(即
ERROR: 0:37: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'in mediump 3-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion) )
除了修复这个明显的错误之外,我什至不确定如何构建这个函数来对正在渲染的球体进行漫反射着色,因此非常感谢任何关于这方面的指导。该函数的代码如下(可能充满错误):
vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material) {
vec3 color = vec3(1.,2.,3.);
vec3 N = (point - sphere.xyz) / sphere.w;
float diffuse = max(dot(Ldir, N), 0.0);
float ambient = material/5;
color = ambient + Lrgb * diffuse * max(0, N * Ldir);
return color;
}
嗯,错误是你的material/5
。您将一个向量除以一个整数并将其分配给一个浮点数。您可能需要 vec3 ambient = material/5.0;
进行正确的类型和计算。
我正在片段着色器中为球体实现简单的光线追踪。在这一点上,我目前正在研究为漫射阴影球体计算颜色的函数。我遇到的问题是我正在尝试使用以下等式从表面点计算法向量:N = (S - sph.xyz) / sph.r 但是,当我尝试将其转换为 glsl 时,出现了这些操作数不能与“/”运算符一起使用的错误(即
ERROR: 0:37: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'in mediump 3-component vector of float' and a right operand of type 'const int' (or there is no acceptable conversion) )
除了修复这个明显的错误之外,我什至不确定如何构建这个函数来对正在渲染的球体进行漫反射着色,因此非常感谢任何关于这方面的指导。该函数的代码如下(可能充满错误):
vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material) {
vec3 color = vec3(1.,2.,3.);
vec3 N = (point - sphere.xyz) / sphere.w;
float diffuse = max(dot(Ldir, N), 0.0);
float ambient = material/5;
color = ambient + Lrgb * diffuse * max(0, N * Ldir);
return color;
}
嗯,错误是你的material/5
。您将一个向量除以一个整数并将其分配给一个浮点数。您可能需要 vec3 ambient = material/5.0;
进行正确的类型和计算。