Advertisement Jump to content


This topic is now archived and is closed to further replies.


Getting vector info out of a DoT3 map?

This topic is 6331 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

I have a DOT3 bump map from which I want to get vector information. (I will read it in as a plain file into memory. ignore the header and all that for now). So, I want to be able to convert one 32 bit (correct, 32 bits per vector?) into a D3DXVECTOR. Anybody know how to do this? Thanks! Greg.

Share this post

Link to post
Share on other sites
I''m not completly familiar with dot3 bump mapping, but as far as I know each color represents the value for one of the axis of the vector. So R might map to X, G to Y, and B to Z. If thats the case you can just load the texture and inspect the values and build a vector from that.

Someone correct me if I''m wrong

FaceHat Software -- Wear the hat.

Share this post

Link to post
Share on other sites
So if that''s the case, then you mean that I should scale 0-255 into 0-1, and THEN normalize the whole thing? I thought that perhaps the values had to somehow already be "normalized" inside the bitmap?



Share this post

Link to post
Share on other sites
I think it would be useful for you too see the process from the other side - creation of a normal map from a height map...

#define UL_EPS 1e-12

typedef union
DWORD pixel;
struct {
BYTE nz, ny, nx, m;

void gfxRawToNMap( DWORD* data, int width, int height )
NMAPNORMAL* nmap = new NMAPNORMAL [width*height];

float scale = 8.0f;
float sqlen, reciplen, nx, ny, nz;
float c, cx, cy, dcx, dcy;
const float oneOver255 = 1.0f/255.0f;
DWORD read;

for (int i=0; i<height; ++i)
for (int j=0; j<width; ++j)
// read current 8888 greyscale pixel

// get green value for pixel

// scale value so that range changes from 0-255 to 0-1

read = data[ i*width + j ];
c = ((read>>8)&0xFF) * oneOver255;

// read and scale the pixel right of the current

read = data[ i*width + (j+1)%width];
cx = ((read>>8)&0xFF) * oneOver255;

// read and scale the pixel above the current pixel

read = data[((i+1)%height)*width + j];
cy = ((read>>8)&0xFF) * oneOver255;

// get x and y slopes/gradients for pixel (its orientation)

dcx = scale * (c - cx);
dcy = scale * (c - cy);

// normalise into normal vector

sqlen = dcx*dcx + dcy*dcy + 1;
reciplen = 1.0f/sqrtf(sqlen);

nx = dcy*reciplen;
ny = -dcx*reciplen;
nz = reciplen;

// Repack the normalized vector into an RGB unsigned byte vector

nmap[i*width+j].nx = (BYTE)(128 + 127*nx);
nmap[i*width+j].ny = (BYTE)(128 + 127*ny);
nmap[i*width+j].nz = (BYTE)(128 + 127*nz);

nmap[i*width+j].m = 255;

Because the components of the vector are signed (-1 to 1), and colours are unsigned (0 to 255), the values have a bias of 128 added (so 0 = -1 and 255 = +1).

So to go from 3 bytes in a colour to a vector the process would be something like:

1. cast a colour byte (R,G or B) to a float
2. subtract 128
3. divide by 127

which is the opposite of the encoding procedure.

Simon O''''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
Thanks very much Simon. You''ve actually replied to several of my messages over the last month or two. You''ve been a great help regarding my game demo, which I''m creating in the hopes of getting into the industry, and of course, to provide a free game for people to play, and simply to learn new things.

Keep educating and thanks,


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!