• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
generaleskimo

[HLSL] Cleaning out specular artifacts in normal maps

8 posts in this topic

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]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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).
0

Share this post


Link to post
Share on other sites
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 :)
0

Share this post


Link to post
Share on other sites
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]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0