有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java OpenGL ES 2.0镜面反射光生成黑色边框

我一直在为一个应用程序研究光力学,漫反射光(环境光和方向光)工作得很好,但镜面反射光会产生一些奇怪的效果。就好像它使围绕它的条带中的漫反射光无效一样

下面是镜面反射光的计算

vec3 directionToEye = normalize(u_eyePos - position);
vec3 reflectDirection = normalize(reflect(direction, normal));

float specularFactor = dot(directionToEye, reflectDirection);
specularFactor = pow(specularFactor, u_specularExponent);

if(specularFactor > 0.0){
    specularColor = vec4(base.color, 1.0) * u_specularIntensity * specularFactor;
}

然后,整体灯光计算函数返回这个值

return diffuseColor + specularColor;

在main()函数中,我只是将它们相乘

gl_FragColor = baseColor * textureColor * returnedValueOfTheLightCalcFunction;

它们都是vec4值

以下是没有(1)的截图和(2)镜面反射灯亮起:

one two

编辑:通过将pow函数放入if语句中,问题已得到修复。我基本上忘记了我必须检查点积是否>;0,而不是pow函数。这是更新后的代码

diffuseColor = vec4(base.color, 1.0) * base.intensity * diffuseFactor;

vec3 directionToEye = normalize(u_eyePos - position);
vec3 reflectDirection = normalize(reflect(direction, normal));

float specularFactor = dot(directionToEye, reflectDirection);

if(specularFactor > 0.0){
    specularColor = vec4(base.color, 1.0) * u_specularIntensity * pow(specularFactor, u_specularExponent);
}

共 (1) 个答案

  1. # 1 楼答案

    两件事:

    1. 你是否在任何地方将镜面颜色初始化为零?如果你是,你还没有发布
    2. pow功能的第一个输入必须为>;=0,否则您将获得未定义的行为。(见第8.2节)