XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Vertex normals and normal maps

Last post 6/18/2007 5:30 PM by BardPT. 4 replies.
  • 6/18/2007 4:41 AM

    Vertex normals and normal maps

    Hi i'm building a terrain engine and i want to add per pixel lightning. I'm still a newby in normal maps, so i have a very basic question (i think). Why do i need to pass the vertex normals if i have a normal map ? What is the diference between the vertex normal and the corresponding normal in the normal map ?

    Another thing that is bugging me is if the vertex normal can be stored in a texture, and if yes what is the diference between this texture and a normal map texture ?

    Tnks in advance for any help

  • 6/18/2007 8:19 AM In reply to

    Re: Vertex normals and normal maps

    Yep, you do need vertex normals and additionnally you'll need vertex tangents and bitangents (aka binormals). That is because a typical tangent-space normal map encodes only the difference between the per-vertex normal and the per-pixel normal, which means it's not dependent on the geometry and the same normalmap can be applied to multiple models.

    I don't really see why you'd want to put vertex normals in a texture though, it's simpler to add it in the vertex format (as well as the tangents/bitangents). Usually you'll have many other textures to sample to get that nex-gen feel (specular mask, heightmap, maybe texture splatting...) so spare them if you can. :P
  • 6/18/2007 10:43 AM In reply to

    Re: Vertex normals and normal maps

    Ok there's a very valid reason for that :-). I'm using vertex textures to displace the geometry. Since i'm using vertex textures i only need to send a position in the 0 to 1 range to the vertex shader because i'm scaling and offseting each tile in there. Saying this in another way i'm not passing individual height values per vertex to vertex shader. I' only sending x and z values between 0 and 1. The y value (height) is calculated each frame in the vertex shader using tex2D and the x and z values are transformed with shader parameters (witch i have called bias and scale). The main advantage is that the vertex buffer only contains vertices by tilesize. For example for a tile of 5x5 i only send 25 vertices to the vertex shader even if i have 257x257 terrain

    So i have two ways of handling this situation:

    - Calculating the normals in the vertex shader

    - Sending a texture with the vertex normals to the vertex shader

    I'm trying to implement the second way because the first way is too expensive but i don't really understand the diference between this map and the normap map and how i can calculate it.

  • 6/18/2007 3:05 PM In reply to

    Re: Vertex normals and normal maps

    There are many different ways to do normalmapping. The most common are object space or tangent space.

    In an object space normalmap, your texture stores normal values directly in the same coordinate system as the object itself. The shader just looks up a normal value from the texture, and uses it directly in the lighting computation.
    • Conceptually very simple and easy to understand.
    • Plays well with dynamic geometry systems like terrain generation, vertex displacement, progressive meshes, etc.
    • Cannot reuse a texture on different parts of the model (if a texture holds normals for a brick wall that faces east, these normals would be wrong if that texture was also mapped onto a brick wall that faced north)
    • Not easy to update normals to account for objects that deform (eg. skinned animation)
    • Normalmaps contain values pointing in all possible directions, so are not easy to compress

    Tangent space normalmapping, on the other hand, only stores the difference between the non-normalmapped surface normal and the desired normal into the texture. To decode this information it must also store the vertex normal, tangent, and binormal. In the shader, it looks up a value from the normalmap texture, then multiplies this with a 3x3 matrix formed from the vertex normal, tangent, and binormal, which moves the normal value from tangent space into object space prior to the lighting computation.
    • More complex to implement.
    • If not careful, can cause popping when used with dynamic geometry systems.
    • Can reuse a single normalmap texture regardless of which way the surface is facing.
    • Easy to support deformable meshes.
    • Normalmap data points mostly straight out, with only small deviations from that, so they compress very well.

    The normalmapping sample on this website implements tangent space normalmapping, as do most games today: that is generally considered to be the most flexible and efficient approach.

    For your scenario, though, I suspect object space normalmaps would be a lot simpler.
    XNA Framework Developer - blog - homepage
  • 6/18/2007 5:30 PM In reply to

    Re: Vertex normals and normal maps

    Tnks you Shawn now i understand it. But i still have a question, how can i generate this object space normal maps in XNA ? Or there is some kind of tool to generate this kind of maps from an heightfield ?

    tnks in advance

Page 1 of 1 (5 items) Previous Next