Sign in to follow this  

Normal Maps

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Well, practically, you won't get very good normal maps from standard textures, since the colors don't really carry any height information.

You can use the NVidia DDS plugin or some other Photoshop plugin to create a normal map.

Usually normal maps are created from hi-res 3d-model.

Share this post


Link to post
Share on other sites
actualy if you mean somthing like creating brick wall normals fro ma standard texture, for walls and not for characters and such. then you want to use a greyscale bumpmap texture. then use the nvidia normalmap filter

Share this post


Link to post
Share on other sites
I'm using the dot3, in the pipeline of directx 9, no shaders, i have a sample c++ file on the normal mapping, and it was color rather than greyscale, because of the different way of handling it(dot3) i suspect.

And yeah, i want some sort of brick wall/cracks in the floor type bumps.


is it like red is x, and green is y, blue is z?

Share this post


Link to post
Share on other sites
Calculate a greyscale.
Then take the dot product of the red and green values, the blue value is always 255.

I think that's all you need to create the normal map.

Adding depth to the image the way the Nvidia plugin does is beyond me, unless it's just the normal map being embossed or something.

Share this post


Link to post
Share on other sites
It depends on how you want to use it. If you just want to use the color by itself as a normal, it will look strange. To do this, though, it's ((COLOR * 2.0f) - 1.0f), so you need to scale from 0to1 to -1to1 (this is inside your pixel program). The problem is that color information isn't necesarily direction, so you need to prepare a texture instead.

The basic approach is to treat the image as a height map (and having an actual height map works even better). You then filter it, sampling each pixel and it's neighbor, to find the normal of that pixel. This is simple considering each pixel is a height, you just calculate the normal from one height to the other, averaging from all it's neighbors. This makes a normal map facing up (you're calculating the delta height in the XY of the image, and you assume a Z of 1), with that normal (values of -1to1), scale it to 0to255 (((Normal + 1.0f) / 2.0f) * 255.0f), and store it in your normal map texture. Inside your pixel program, convert back to -1to1 (since it's still color information here), and use the normal however you want.

Offhand, I don't have any links, but a quick search and you should be able to find some code that actually does that (that's mostly how the NVidia filter for Photoshop does it, too).

Share this post


Link to post
Share on other sites
I don't remember, which tutorial i got this from but here's a sample of what i want to be able to do:



It was from some Bummapping tutorial or something.
Here is some of the code that came with it:

g_pd3dDevice->SetTexture( 0, g_pNormalMapTexture );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DOTPRODUCT3 ); // Perform a Dot3 operation...
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // between the N (of N.L) which is stored in a normal map texture...
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); // with the L (of N.L) which is stored in the vertex's diffuse color.

//
// STAGE 1
//
// Modulate the base texture by N.L calculated in STAGE 0.
//

g_pd3dDevice->SetTexture( 1, g_pTexture );
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 1 );

g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); // Modulate...
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); // the texture for this stage with...
g_pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); // the current argument passed down from stage 0


Share this post


Link to post
Share on other sites
For that, you would need normalized values, scaled to 0to255, in the normal map texture data. This means getting normals for every pixel, and scaling from -1to1 to 0to255 (int)(((Normal + 1.0f) / 2.0f) * 255.0f). When doing Dot3 like that, Direct3D converts the color values in the input texture back to -1to1, then does the Dot3 calculation.

edit: This means that just using the color by itself, though it technically works, doesn't produce any visually correct results, as the color information by itself has nothing to do with direction, so when scaled to -1to1, can look really strange.

Share this post


Link to post
Share on other sites

This topic is 4201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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