Jump to content

  • Log In with Google      Sign In   
  • Create Account


Normal Mapping black spots problem


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 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 23 April 2013 - 05:13 AM

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 ?

Edited by lipsryme, 23 April 2013 - 05:29 AM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 27567

Like
0Likes
Like

Posted 23 April 2013 - 05:42 AM

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?



#3 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 23 April 2013 - 06:23 AM

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



#4 Tasty Texel   Members   -  Reputation: 1188

Like
0Likes
Like

Posted 23 April 2013 - 06:41 AM

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


#5 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 23 April 2013 - 06:47 AM

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

 

Now it looks like this:

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



#6 kauna   Crossbones+   -  Reputation: 2156

Like
0Likes
Like

Posted 23 April 2013 - 07:20 AM

 
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!

Edited by kauna, 23 April 2013 - 07:21 AM.


#7 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 23 April 2013 - 07:36 AM

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

Edited by lipsryme, 23 April 2013 - 07:43 AM.


#8 kauna   Crossbones+   -  Reputation: 2156

Like
0Likes
Like

Posted 23 April 2013 - 07:53 AM

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!



#9 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 23 April 2013 - 08:10 AM

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


Edited by lipsryme, 27 April 2013 - 09:22 AM.





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