Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problems about the construction of normalization cubemap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Moonloki   Members   -  Reputation: 111

Like
0Likes
Like

Posted 16 June 2013 - 06:52 AM

Hi, guys
I want to implement a normalization cubemap which transforms the arbitary directional vectors into its normal form, and
I have studied the following reference sources:

paul's projects:
http://www.paulsprojects.net/tutoria...implebump.html

openGL cubemap specification:
http://oss.sgi.com/projects/ogl-samp...e_cube_map.txt

The problem is that I don't understand the following code snippet from paul's project for the construction of normalization cubemap:

normalization cubemap:
    unsigned char * data=new unsigned char[32*32*3];

    if(!data)

    {

        printf("Unable to allocate memory for texture data for cube map\n");

        return false;

    }



    //some useful variables

    int size=32;

    float offset=0.5f;

    float halfSize=16.0f;

    VECTOR3D tempVector;

    unsigned char * bytePtr;



    //positive x

    bytePtr=data;



    for(int j=0; j<size; j++)

    {

        for(int i=0; i<size; i++)

        {

            tempVector.SetX(halfSize);

            tempVector.SetY(-(j+offset-halfSize));

            tempVector.SetZ(-(i+offset-halfSize));



            tempVector.Normalize();

            tempVector.PackTo01();



            bytePtr[0]=(unsigned char)(tempVector.GetX()*255);

            bytePtr[1]=(unsigned char)(tempVector.GetY()*255);

            bytePtr[2]=(unsigned char)(tempVector.GetZ()*255);



            bytePtr+=3;

        }

    }

    glTexImage2D(    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,

                    0, GL_RGBA8, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

I have two questions here:
1. We all know the first element of array which is supplied as texture data corresponds to the lower-left corner of texture image, but in this
case the for loop just start by adding the directional vector with x > 0 , y > 0 and z > 0 to the first element of array, and the direction pointed
by that vector is not the lower-left corner if when we think the face of cubemap as texture image and view it from positive x-axis to the
negative x-axis. Is this code error or do I misunderstand something?

2. Why do we need to add the offset to change the components of directional vector?

I got stuck for this problem about two days, any suggestions or reference source will be appreciated.



Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 8276

Like
0Likes
Like

Posted 16 June 2013 - 09:27 AM

The Doom 3 normalization cubemap code might be clearer for you; see https://github.com/id-Software/DOOM-3/blob/master/neo/renderer/Image_init.cpp#L648 (and the getCubeVector function above it).

 

If you compare this with how cubemap texture lookups work (e.g. see http://www.nvidia.com/object/cube_map_ogl_tutorial.html - in particular the section headed "Mapping Texture Coordinates to Cube Map Faces") you'll see that it's just working through the face-selection and texcoord generation process in reverse.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS