• 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
lipsryme

Normal Mapping black spots problem

8 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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

Share this post


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

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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!

0

Share this post


Link to post
Share on other sites

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