1

Blinn-phong 阴影...?

法线 布林蓬

所以我遇到的问题,如上图所示,我似乎无法让镜面高光平滑地着色。问题是沿面边缘的突然切断,这不应该发生。漫反射照明似乎工作得很好,它使用相同的插值。这是 blinn-phong 高光的代码:

vec3 halfAngle = normalize(lightDirection.xyz + viewRay);

float blinnTerm = dot(normal.xyz, halfAngle);
blinnTerm = clamp(blinnTerm, 0.0f, 1.0f);
blinnTerm = pow(blinnTerm, 300.0f);

float specIntensity = intensity * blinnTerm;

vec4 specColour = specIntensity * specColour;

lightDirection是恒定的,它是无限远的(即太阳)。至于 viewRay,它是在顶点着色器中计算的,使用投影矩阵:

viewRay = vec3(-(UV.x * 2.0f - 1.0f) / projection[0].x,
               -(UV.y * 2.0f - 1.0f) / projection[1].y,
                     1.0f);

我正在使用延迟渲染,这是 UV 值的来源(渲染到全屏纹理)。

我唯一能想到的是正常的插值不够平滑。但如果是这样的话,我将如何解决它?(我将法线存储为 16 位浮点数,但将其提高到 32 位并没有什么不同)。

4

1 回答 1

3

enter image description here

And the teapot is now fixed! There was an issue with interpolating the normals, but thankfully it was an easy fix; I was normalizing the normals in my vertex shader, then interpolating, rather than interpolating first and then normalizing. It's still not perfect, but it's certainly an improvement!

The lesson here: if your image looks flat, you're probably doing something you shouldn't be doing in the vertex shader.

于 2014-02-26T18:20:35.357 回答