Normal Mapping black spots problem

Started by
7 comments, last by lipsryme 11 years ago

Hey guys, I'm having a small problem with my normal mapping.

Here's how it looks:

http://d.pr/i/yszc

Now when I comment out this line here (computing of the z component instead of reading it from the file):


	// Sample the normal map, and convert the normal to world space
	normalTS.xyz = NormalMap.Sample(AnisotropicSampler, input.UV).xyz * 2.0f - 1.0f;
	//normalTS.z = sqrt(1.0f - ((normalTS.x * normalTS.x) + (normalTS.x * normalTS.y)));
	normalWS = mul(normalTS, tangentToWorld);
	normalWS = normalWS * rsqrt(dot(normalWS, normalWS));

It seems to look fine:

http://d.pr/i/UokG

Why is that ? Does the z reconstruction only work for 3Dc compressed normal maps ? But shouldn't this algorithm work for anything ?

Well looking at it in PIX it seems to generate NaN.

normalTS ( 0.811, 0.685, -1.#IO ) float3
So basically it's doing a sqrt(something negative). What am I doing wrong ?
Advertisement

normalWS = normalWS * rsqrt(dot(normalWS, normalWS));

seems like a very long winded way of saying

normalWS = normalize(normalWS);

Unless you've got a specific reason for the former, I'd just use the explicit normalize version.

Why is that ? Does the z reconstruction only work for 3Dc compressed normal maps ?

Wait, are you actually using 3Dc/BC5/ATI2? If so, it's a two-channel format, so there will only be x/y values and no z values, so yes, you'd have to reconstruct z.

If not, can you post your texture file?

http://www.humus.name/Articles/Persson_LowLevelThinking.pdf (page 34)

The map I'm using here is just DXT5 compressed but it should still work, correct ?

It's basically from the POM sample in the DX SDK June 2010 but converted to DDS(dxt5) (was tga before).

http://d.pr/f/l7A8

You've made a small mistake:


normalTS.z = sqrt(1.0f - ((normalTS.x * normalTS.x) + (normalTS.x * normalTS.y)));

should be:


normalTS.z = sqrt(1.0f - ((normalTS.x * normalTS.x) + (normalTS.y * normalTS.y)));
//normalTS.z = sqrt(1.0f - (dot(normalTS.xy, normalTS.xy)));

You are right, had a typo there, doesn't fix the issue though :/

Now it looks like this:

http://d.pr/i/6Wuy

If your x and y components are (0.811, 0.685) then the 1-(x*x + y*y) will be negative (1 - 1.1269).
Just an idea : have you normalized your mipmaps?
Cheers!

Um I don't think so...how would I do that ?

Using SampleLevel and going through every mip map and normalizing it ?

normalTS seems fine:

http://d.pr/i/pGwC

Here's the complete PS code for the normal mapping:

VS code is just transforming to world space and normalizing it.


	// Normal Mapping
	float3 normalWS = input.Normal * rsqrt(dot(input.Normal, input.Normal)); // normalize
	float3 tangentWS = input.Tangent * rsqrt(dot(input.Tangent, input.Tangent)); // normalize
	float3 biTangentWS = cross(input.Normal, input.Tangent);

	float3 normalTS = float3(0, 0, 1);
	float3x3 tangentToWorld = float3x3(tangentWS, biTangentWS, normalWS);

	// Sample the normal map, and convert the normal to world space
	normalTS.xyz = NormalMap.Sample(AnisotropicSampler, input.UV).xyz * 2.0f - 1.0f;
	normalTS.z = sqrt(1.0f - ((normalTS.x * normalTS.x) + (normalTS.y * normalTS.y)));
	normalWS = mul(normalTS, tangentToWorld);
	normalWS = normalWS * rsqrt(dot(normalWS, normalWS)); // normalize

Typically the normal maps are normalized in image editing software such as Photoshop, and if your normal map works fine elsewhere, then there shouldn't be problem with the normal map.

Why don't you use normalize() instead of dots and rsqrts etc? If not anything else, it makes the code and your intentions easier to read.

Have you tried to change the filtering to bilinear / none?

Cheers!

You mean like so ?

http://d.pr/i/Z5Jo

Didn't seem to help.

And yes I've tried linear sampling, also no help.

UPDATE: saturate made it a bit better, still black spots there when comparing it to just sampling xyz from the normal map.

I'm gonna do that for now, if anyone has an idea please go ahead and tell me tongue.png

This topic is closed to new replies.

Advertisement