Question about normal mapping & spherical harmonics

Oct 26, 2012 at 3:05 PM

Hi there,

While developing my own engine/game I have run across the standard issue with illuminating large dynamic outdoor scenes. Simulating the sun with a directional light causes the parts of objects that are facing away from the light to be dark and lacking detail.

The darkness can be reduced by increasing the ambient light intensity, but nothing can be done about the flatness of the surfaces. The parts that are facing away have only flat ambient lighting, lacking the shading detail that is so important for the illusion of 3D.

Even worse, back sides also lack the normal mapping effect.

But while testing the XNA Final Engine, I did not run into this problem. Even when deactivating all lights, the normal mapping effect is still visible, albeit less pronounced than when the objects are directly illuminated.

How is this possible? I have two theories:

1. The spherical harmonics based ambient illumination also does normal mapping.

2. The deferred lighting engine somehow does normal mapping based on the normal G-buffer, even in the absence of light.

Could you please elaborate on how normal mapping is possible on the backsides of objects/without any lights?

If the effect is due to the spherical harmonics ambient lighting, could this be achieved in forward rendering? Actually, can the Final Engine run in a forward rendering mode?

Thank you!

Coordinator
Oct 26, 2012 at 5:53 PM
Edited Oct 26, 2012 at 5:55 PM

The spherical harmonics information is sampled using the normals and I use the G-Buffer normal map that has the normal mapping applied.

The engine can not run in forward mode but it is possible to do spherical harmonic lighting in a forward renderer. Your ambient term should be replaced with the following:

float3 N = // Here you have your normals.
ambientTerm = SampleSphericalHarmonics(N); //you can see the SampleSphericalHarmonics function in the SphericalHarmonics.fxh file.

The difficult part is to calculate the Spherical Harmonic constants. This constant are used to recreate a low frequency cube map of the environment. It is just like to read a cube map very blured using the normals instead of the reflection vector but incredible faster and friendly with texture fetching (because you don´t do any fetch).
  In my source code there is a class to read this information from a cube map. But try to use a HDR cube map (I encoded them in RGBM so probably the reader assume that it is RGBM) because the result are far superior.

I talk about a lot of concepts. If you have another question just ask.

Bye! José.

 

 

Oct 29, 2012 at 1:14 PM

Hi José!

Thank you very much for the quick reply! This was easier than expected! I need to study a little to make sure I understand things better, but I did manage to get an early prototype working with hardcoded constants. Before shot with one directional light:

http://dl.dropbox.com/u/45638513/12_05.png

After shot:

http://dl.dropbox.com/u/45638513/12_08.png

Looks very promising! And with some specular highlights:

http://dl.dropbox.com/u/45638513/12_16.png

One more question: do I need to do Blinn-Phong forward rendering as usual (only without an ambient factor) or do I need to adjust it?

Also, I noticed that this technique doesn't like a mix of flat shaded faces with smooth shaded faces, as seen near the bottom of the stone stool, the black highlights:

http://dl.dropbox.com/u/45638513/12_14.png

I'll continue experimenting! I also tested the whole engine and it might be the right choice for me, but not right now, because I would need to recreate a ton of shades written for forward rendering, like terrain, billboards, grass, animation, etc. for deferred lighting. It is deferred lighting (light pre-pass), not deferred rendering as far as I can tell.

Thank you very much!

 

 

Coordinator
Oct 29, 2012 at 1:31 PM

"One more question: do I need to do Blinn-Phong forward rendering as usual (only without an ambient factor) or do I need to adjust it?"

You can use your typical Blinn Phong BRDF or whatever BRDF you want.

"Also, I noticed that this technique doesn't like a mix of flat shaded faces with smooth shaded faces, as seen near the bottom of the stone stool, the black highlights:"

The technique does not work wrong, you just need something else. Ambient Occlusion is a good technique to add with spherical harmonics lighting.

"It is deferred lighting (light pre-pass), not deferred rendering as far as I can tell."

Deferred lighting is a deferred renderer, a deferred renderer is not always a deferred lighting. Another deferred renderers are deferred shading, inferred rendering, etc.

You are welcome. Good luck!!!

Oct 29, 2012 at 2:48 PM

Sorry to bother you again with this: so you are saying that the dark outline like effect that is visible inside the red ellipse I highlighted with Paint is working as intended? What exactly is causing this and is there a way compensate for this?

http://dl.dropbox.com/u/45638513/test03.png

Thank you!

Coordinator
Oct 29, 2012 at 2:51 PM

Maybe you have a problem with your normals or something. Because if everything works ok, the spherical lighting technique should not produce any artifact.

Can you show me your normals?

Oct 29, 2012 at 3:29 PM

Taking into consideration what the shader does, mesh normals are not important. I even tested it to make sure.

So this leaves only the model's normal texture. I modified the shader to amplify the normal 40 times, giving a rough overview of the intensity differences between the texels, and this is what I got:

http://dl.dropbox.com/u/45638513/test04.png

So my guess is that the ambient lighting works fine and the normal map has some issues.

Thank you!