[HLSL] Cleaning out specular artifacts in normal maps

Started by
7 comments, last by Schrompf 16 years, 8 months ago
I know the title is a mouthful. Basically, I have been playing around with normal maps in the last few days, trying to find a preferable system to implement. One issue I have come across regarding specular lighting. I am using the basic phong lighting model over a standard normal map, and everything is looking great, until the light source is BEHIND the surface being lit. At the right angles, you get an odd effect as the light is reflected off the surface, even though the surface is facing away from the light source. GOOD: BAD: As you can see, you get specular reflections on occluded surfaces, which easily artifact when observing at sharp angles. My first instinct was to hide specular highlights if the surface was occluded, by simply taking the dot product of the vertex's normal and the light direction. However, when the light source is MOVING from in front of the surface to behind it, this creates a very sharp and unflattering falloff from 100% to 0% the moment the light source becomes perpendicular. Does anyone have any ideas as to how to achieve a gradual falloff? [Edited by - generaleskimo on August 7, 2007 11:48:14 PM]
===========================";" is the best key ever; you can use it to end lines when you are too lazy to use ENTER;
Advertisement
I'm not entirely sure what you're asking and the images won't open either, so I'll just chip in a guess. To achieve a gradual falloff of the specular highlight, you'll probably need to tweak the specular exponent. High values make for sharp and small highlights, low values give you smoother highlights but may light too much of the surface, resulting in overly bright areas.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
I'm not entirely sure what you're asking and the images won't open either, so I'll just chip in a guess. To achieve a gradual falloff of the specular highlight, you'll probably need to tweak the specular exponent. High values make for sharp and small highlights, low values give you smoother highlights but may light too much of the surface, resulting in overly bright areas.


Um... no. I am talking about specular highlights ON OCCLUDED GEOMETRY, which means PLACES WHERE THE LIGHT CANNOT POSSIBLY HIT BECAUSE THE SURFACE IS FACING THE OTHER DIRECTION.

Goodness with the normal map:



Badness as the light has moved BEHIND the surface:



As you can see, specular highlights appear on the dark side of the surface, as you view the reflected light from the perturbed surface normals of the normal map.

Again, the problem is that when i simply do not light surfaces whose vertex normal is facing away from the light source, I get a problem with falloff. Not specular falloff, mind you, but falloff as the LIGHT'S DIRECTION reaches AN ANGLE PERPENDICULAR TO THE SURFACE VERTEX NORMAL (ie, 90 degree angle with the disc in the image).
===========================";" is the best key ever; you can use it to end lines when you are too lazy to use ENTER;
No need to EMPHASIZE THAT DRAMATICALLY, I'd say the lack of other replies do indicate your problem wasn't too clear [wink]

Can't you just use your current diffuse intensity (normalFromNormalMap (dot) light) and multiply that with the specular intensity? Provided your tangent space transformation is set up correctly, this should take the surface normal into account and it would produce a more detailed falloff. Modulating the specular with the diffuse intensity this way works for me.

If I understand you correctly this time, I think you could also tweak the falloff some more by messing around with the surfaceNormal (dot) light term. You know the dotproduct gets close to 0 as the light/surface angle approaches 90 degrees, so you could remap it to a quadratic function (dotProduct * dotProduct) to 'ease' it in and out gradually.

Hope this DOES help :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
No need to EMPHASIZE THAT DRAMATICALLY, I'd say the lack of other replies do indicate your problem wasn't too clear [wink]

Can't you just use your current diffuse intensity (normalFromNormalMap (dot) light) and multiply that with the specular intensity? Provided your tangent space transformation is set up correctly, this should take the surface normal into account and it would produce a more detailed falloff. Modulating the specular with the diffuse intensity this way works for me.

If I understand you correctly this time, I think you could also tweak the falloff some more by messing around with the surfaceNormal (dot) light term. You know the dotproduct gets close to 0 as the light/surface angle approaches 90 degrees, so you could remap it to a quadratic function (dotProduct * dotProduct) to 'ease' it in and out gradually.

Hope this DOES help :)


Sorry, I didn't mean to offend. I guess I haven't been active on forums in a while, and I am not used to using bold.

The problem I have found with that approach is that it dulls sharp-angle specular highlights which are brought out by the fresnel term used in my lighting. To adjust for this, I tried scaling your extra term by adding an exponent to it (pow(TERM,X)), and thus took its n'th root. The problem with this is that, while it preserves fesnel reflections, it tends to add specular highlights to already-lit portions of the surface, giving an "overbright" effect where diffuse light is still seen.

As you can see here, dimly lit surfaces are brightened by specular highlights, while darker surfaces remain untouched:
Good-bad


However, I have found an alternate solution! :)

In this solution, you can scale the falloff exponent using FALLOFF

vTotalLightDiffuse += g_LightDiffuse * max(0,dot(Normal, LightVec));float Scale = 1;float temp = dot(In.Normal,g_LightDir)-0.1; //<--- Vertex's normal, NOT FROM NORMAL MAP//The -0.1 adds a bit of bias to the calculation to reduce sharp-angle glare on partially-occluded surfacesif (temp < 0)	Scale = pow(1+temp,FALLOFF);Reflection = reflect(-LightVec,Normal);vTotalSpec+= pow(max(0,dot(Reflection,ViewVec)),Power)*SpotAt*g_LightDiffuse*Scale;


What I do is allow it to fade by a factor of (VertexNormal (DOT) LightVec). This means that specular highlights from light sources facing the local surface will remain entirely unaffected, while lighting sources perpendicular to and beyond will be gradually effected, in an easily scalable manner!

[Edited by - generaleskimo on August 8, 2007 1:09:18 AM]
===========================";" is the best key ever; you can use it to end lines when you are too lazy to use ENTER;
Quote:Original post by generaleskimo

Sorry, I didn't mean to offend. I guess I haven't been active on forums in a while, and I am not used to using bold.


None taken, in my early-morning-caffeine-less crankiness I just felt like pointing it out [smile]

That looks like a nice solution, glad you got it to work & thanks for sharing it.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
I do this by simply scaling down the light influence when the light vector is nearly parallel to the surface. Note: the surface, not the normal from the bump map. In tangent space normal mapping, you can simply use the tangent space light vector's Z component to do this check. It's similar to what you do, but easier to calculate.

light *= saturate( LightVex.z * 5.0f - 0.5f);


Basically one instruction, doesn't hurt the fillrate like a pow() does. It serves multiple purposes:

a) Cuts off the light when the light shines from the back of the surface.
b) Dims the diffuse lighting from shallow light directions. Due to the normal mapping even lights at or behind the surface light up some pixels - the formula above smoothly fades out the light in this situation. Some sort of easy self shadowing.
c) Reduces those sawtooth cutoff artifacts when using shadow mapping.

Hope that helps.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
Quote:Original post by Schrompf
I do this by simply scaling down the light influence when the light vector is nearly parallel to the surface. Note: the surface, not the normal from the bump map. In tangent space normal mapping, you can simply use the tangent space light vector's Z component to do this check. It's similar to what you do, but easier to calculate.

light *= saturate( LightVex.z * 5.0f - 0.5f);


Basically one instruction, doesn't hurt the fillrate like a pow() does. It serves multiple purposes:

a) Cuts off the light when the light shines from the back of the surface.
b) Dims the diffuse lighting from shallow light directions. Due to the normal mapping even lights at or behind the surface light up some pixels - the formula above smoothly fades out the light in this situation. Some sort of easy self shadowing.
c) Reduces those sawtooth cutoff artifacts when using shadow mapping.

Hope that helps.

Bye, Thomas


That helps a bunch. This is a good solution, although when you subtract 0.5f, you force the light to be dimmer before the lights are parallel to the surface. My issue with that is that I loose the fresnel reflection highlights. But, this can be remedied by adding 0.5f instead of subtracting.
===========================";" is the best key ever; you can use it to end lines when you are too lazy to use ENTER;
Quote:
That helps a bunch. This is a good solution, although when you subtract 0.5f, you force the light to be dimmer before the lights are parallel to the surface. My issue with that is that I loose the fresnel reflection highlights. But, this can be remedied by adding 0.5f instead of subtracting.


Hmm... I was sure I had a reason for that bias but I don't remember what it was. If it works for you, great to hear. I'll take it as a hint to recheck my shaders wether this bias is of any use at all :-)

Bye, Thomas

----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

This topic is closed to new replies.

Advertisement