我正在片段着色器中为球体实现简单的光线追踪。目前,我正在研究计算漫反射球体颜色的函数。我遇到的问题是我正在尝试使用以下方程计算表面点的法线向量: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
。您将向量除以整数并将其分配给 float 。您可能需要 vec3ambient =material/5.0;
来进行正确的类型和计算。
关于opengl-es - 使用具有球体 Material 属性和 float 的 '/' 运算符时出错 (glsl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32730556/