我正在片段着色器中为球体实现简单的光线跟踪。此时,我正在研究为漫反射阴影球体计算颜色的函数。我遇到的问题是我正在尝试使用以下公式从表面点计算法向量: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;
}
答案 0 :(得分:3)
嗯,错误是你的material/5
。您将向量除以整数并将其指定给浮点数。您可能希望vec3 ambient = material/5.0;
获得正确的类型和计算。