Advertisement Jump to content
Sign in to follow this  

OpenGL Problem with DOT3 Bump Mapping implementation

This topic is 4964 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 written an OpenGL program to implement DOT3 bump mapping. It uses a normalization cube map and dot3 texture combiner function. However there seems to be some compatibility issues related to cube map. To avoid artifacts around the intersecting lines of the six cube map faces, I tried two methods: (1) Use no texture borders and use GL_CLAMP_TO_EDGE wrapping mode; (2) Use texture borders and use GL_CLAMP wrapping mode. On my work computer with NVidia Quadro FX 3400, both methods work. On my home computer with NVidia GeForce Ti 4200, method (1) works. However method (2) results in totally wrong lighting effects. On my laptop with ATI Mobility Radeon 9000. Method (1) results in wrong lighting effects. Method (2) produces the correct effects, however the performace is horribly slow. The program would take 3 seconds to respond to keyboard and mouse inputs. So is there anyway to make the program work on all computers? The program is written in VC++ 6.0 and uses GLUT. The following is the code for creating normalization cube map: GLuint create_normalization_cube_map(int size, bool use_border) { GLuint tex_cube_map; GLfloat *image_buffer; int buffer_size; GLenum target[6]={ GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z }; int i, j, k, counter; // Create temporary image buffer if (use_border) size+=2; buffer_size=4*size*size; image_buffer=new GLfloat [buffer_size]; for (i=0; i<buffer_size; ++i) { if (i%4==3) image_buffer=1.0; else image_buffer=0.0; } // Generate texture object and set texture parameters glGenTextures(1, &tex_cube_map); glBindTexture(GL_TEXTURE_CUBE_MAP, tex_cube_map); GLenum wrap_mode; if (use_border) wrap_mode=GL_CLAMP; else wrap_mode=GL_CLAMP_TO_EDGE; glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, wrap_mode); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, wrap_mode); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, wrap_mode); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Create each of the six faces of the cube map for (i=0; i<6; ++i) { float s, t, r[3]; // s, t: texture coordinates // r[3]: normalized direction vector counter=0; for (j=0; j<size; ++j) { if (use_border) { t=((float)j-1.0)/(float)(size-2); if (j==0) t=0.0; else if (j==size-1) t=1.0; } else t=(float)j/(float)size; t=2.0*t-1.0; for (k=0; k<size; ++k) { if (use_border) { s=((float)k-1.0)/(float)(size-2); if (k==0) s=0.0; else if (k==size-1) s=1.0; } else s=(float)k/(float)size; s=2.0*s-1.0; // Obtain direction vector switch (i) { case 0://+x r[0]=1.0; r[1]=-t; r[2]=-s;break; case 1://-x r[0]=-1.0; r[1]=-t; r[2]=s;break; case 2://+y r[0]=s; r[1]=1.0; r[2]=t;break; case 3://-y r[0]=s; r[1]=-1.0; r[2]=-t;break; case 4://+z r[0]=s; r[1]=-t; r[2]=1.0;break; case 5://-z r[0]=-s; r[1]=-t; r[2]=-1.0;break; } // Normalize direction vector and store it // as color values in cube map texture float ftmp=sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]); ftmp=1.0/ftmp; for (int kk=0; kk<3; ++kk) { r[kk]*=ftmp; r[kk]=0.5*(r[kk]+1.0); image_buffer[counter+kk]=r[kk]; } counter+=4; } } // Specify one face of the cube map texture int border; if (use_border) border=1; else border=0; glTexImage2D(target, 0, GL_RGBA, size, size, border, GL_RGBA, GL_FLOAT, image_buffer); } delete [] image_buffer; return tex_cube_map; } Any help would be appreciated. Thanks.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!