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

Is my normal mapping abnormal?

Last post 05/11/2009 12:31 by Joopsy. 5 replies.
  • 03/11/2009 13:28

    Is my normal mapping abnormal?

    Hello all!

    I am still having a lovely time writing my terrain engine doodad.
    (I don't know why, I just find it really enjoyable).

    anyhoo, I just tried generating a normal map for it (I am using geomipmapping, so the further away bits where looking a bit undetailed).

    And I just got it working (yay!).

    I just wanted to ask if the way I am doing it is a bit crazed.

    Using the high-res height map, I am greating an array of normals. (normalised, xyz in the range -1 to 1).

    I am then adding 1 and dividing by 2, so it is in the range 0 to 1.

    Then I create an image, with the values encoded as colours.

    In my shader, I read the texture sample, normalise it,  then subtract 1 and multiply by 2 (so xyz are in the range -1 to 1 again).
    (I think I then normalise it again)

    And then I have my lovely per pixel normal.

    Just wonderered if there is a less convulted way of achieving this?

    J.
    In playtest Flite
  • 03/11/2009 13:47 In reply to

    Re: Is my normal mapping abnormal?

    Answer
    Reply Quote
    That sounds almost correct.  For unpacking a normal, it's going to come out of the texture in the range of 0 to 1.  If you subtract 1 from that you're going to be left with -1 to 0.  What you really want is to be left with -0.5 to 0.5, so that you can then multiply by 2 to put it in the range of -1 to 1.

    In summary:

    to pack: N * 0.5 + 0.5
    to unpack: (N - 0.5) * 2
  • 03/11/2009 16:50 In reply to

    Re: Is my normal mapping abnormal?

    Answer
    Reply Quote
    Or you could use one of the SurfaceFormat.Normalized* texture formats, which can directly encode signed values.
    XNA Framework Developer - blog - homepage
  • 04/11/2009 11:20 In reply to

    Re: Is my normal mapping abnormal?

    Thank you both for your replies.

    Shawn, will I be able to save a texture with that kind of format?
     I am having trouble picturing how it will work
    (Sorry if the answer is incredibly obvious, first time I have heard of that kind of feature)

    J.
    In playtest Flite
  • 04/11/2009 16:21 In reply to

    Re: Is my normal mapping abnormal?

    Answer
    Reply Quote
    Joopsy:

    Shawn, will I be able to save a texture with that kind of format?


    Most image formats (.png, .bmp, etc) do not support signed data, but .dds files do, as obviously do .xnb files, or you could just save the image bits out in a raw format.

    Converting scale+bias format normalmap data from a .bmp file into a signed GPU texture format would be a perfect thing to do in a content processor.
    XNA Framework Developer - blog - homepage
  • 05/11/2009 12:31 In reply to

    Re: Is my normal mapping abnormal?

    Thanks very much for that guidance, the whole concept of signed values was a bit new to me and unnerving.

    Currently I am just playing around learning new bits, but when I come to package this up a bit, I will look at wrapping it up in a content processor.

    Cheers again

    JB
    In playtest Flite
Page 1 of 1 (6 items) Previous Next