在 glsl 片段着色器中实现 phong 反射的问题
Issue with implementing phong reflectance in glsl fragment shader
我已经编写了一个使用光线对球体进行着色的片段着色器 tracing.I我现在正在尝试实现镜面反射的 phong 模型,该模型使用一个方程:R = 2 (N • L) N - L 其中 L 是光线方向,N 是表面法线。然后将反射向量 R 的值代入: s_rgb max(0, E • R)^p 其中 E 是观察者的眼睛方向(在这种情况下它是 -w 或光线的负方向), p 是镜面反射强度,s_rgb 是镜面反射的颜色。在我当前用于确定球体颜色的函数实现中,我遇到了 max 和 power 函数的错误。这是函数的代码:
vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material,vec3 eyeDir) {
vec3 color = vec3(1.,2.,4.);
vec3 N = (point - sphere.xyz) / sphere.w;
float diffuse = max(dot(Ldir, N), 0.0);
vec3 ambient = material/5.0;
vec3 R = 2.*(dot(N, Ldir))*(N - Ldir);
float reflect = max(0.0,dot(eyeDir,R));
float phong= pow(reflect, 2);
color = phong + ambient + Lrgb *diffuse * max(0.0, dot(N , Ldir));
return color;
}
出于某种原因,pow()
函数返回错误
错误:0:49:'pow':找不到匹配的重载函数```
我认为 max 函数的第二个参数可能会导致问题,但它似乎应该有效。谁能发现函数的问题?
看起来您只是错过了那个点。 "There's no overload" 用于带有 int 的浮点数的 pow。
float phong= pow(reflect, 2); // nope
float phong= pow(reflect, 2.); // ok
我已经编写了一个使用光线对球体进行着色的片段着色器 tracing.I我现在正在尝试实现镜面反射的 phong 模型,该模型使用一个方程:R = 2 (N • L) N - L 其中 L 是光线方向,N 是表面法线。然后将反射向量 R 的值代入: s_rgb max(0, E • R)^p 其中 E 是观察者的眼睛方向(在这种情况下它是 -w 或光线的负方向), p 是镜面反射强度,s_rgb 是镜面反射的颜色。在我当前用于确定球体颜色的函数实现中,我遇到了 max 和 power 函数的错误。这是函数的代码:
vec3 shadeSphere(vec3 point, vec4 sphere, vec3 material,vec3 eyeDir) {
vec3 color = vec3(1.,2.,4.);
vec3 N = (point - sphere.xyz) / sphere.w;
float diffuse = max(dot(Ldir, N), 0.0);
vec3 ambient = material/5.0;
vec3 R = 2.*(dot(N, Ldir))*(N - Ldir);
float reflect = max(0.0,dot(eyeDir,R));
float phong= pow(reflect, 2);
color = phong + ambient + Lrgb *diffuse * max(0.0, dot(N , Ldir));
return color;
}
出于某种原因,pow()
函数返回错误
错误:0:49:'pow':找不到匹配的重载函数```
我认为 max 函数的第二个参数可能会导致问题,但它似乎应该有效。谁能发现函数的问题?
看起来您只是错过了那个点。 "There's no overload" 用于带有 int 的浮点数的 pow。
float phong= pow(reflect, 2); // nope
float phong= pow(reflect, 2.); // ok