Question

Blinn-phong shading...?

Normals Blinn-phong

So the issue I'm having, as the above image hopefully illustrates, is that I can't seem to get my specular highlights to shade smoothly. The problem is the abrupt cutoff along face edges, which shouldn't be happening. The diffuse lighting appears to be working quite well, and it uses the same interpolated values. Here's the code for the blinn-phong specular highlights:

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 is constant, it's infinitely far away (ie. the sun). As for viewRay, it's computed in the vertex shader like so, using the projection matrix:

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

I'm using deferred rendering, which is where the UV values come from (rendering to a full screen texture).

The only thing I can think of is that the normal interpolation just isn't smooth enough. But if that's the case, how would I go about fixing it? (I'm storing the normals as 16-bit floats, but upping it to 32 bits didn't make a difference).

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top