Jump to content

  • Log In with Google      Sign In   
  • Create Account


[HLSL] Cleaning out specular artifacts in normal maps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 generaleskimo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 August 2007 - 09:23 AM

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]

Sponsor:

#2 remigius   Members   -  Reputation: 1168

Like
0Likes
Like

Posted 07 August 2007 - 09:40 AM

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!

#3 generaleskimo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 August 2007 - 05:47 PM

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).

#4 remigius   Members   -  Reputation: 1168

Like
0Likes
Like

Posted 07 August 2007 - 06:36 PM

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!

#5 generaleskimo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 August 2007 - 07:09 PM

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[i] * max(0,dot(Normal, LightVec[i]));
float Scale = 1;
float temp = dot(In.Normal,g_LightDir[i])-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 surfaces
if (temp < 0)
Scale = pow(1+temp,FALLOFF);
Reflection = reflect(-LightVec[i],Normal);
vTotalSpec+= pow(max(0,dot(Reflection,ViewVec)),Power)*SpotAt*g_LightDiffuse[i]*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]

#6 remigius   Members   -  Reputation: 1168

Like
0Likes
Like

Posted 07 August 2007 - 07:31 PM

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!

#7 Schrompf   Prime Members   -  Reputation: 950

Like
0Likes
Like

Posted 07 August 2007 - 11:09 PM

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[i].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

#8 generaleskimo   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 August 2007 - 10:00 AM

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[i].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.


#9 Schrompf   Prime Members   -  Reputation: 950

Like
0Likes
Like

Posted 09 August 2007 - 01:24 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS