Cube mapping

xiaoxiao2021-03-06  112

Note: There is an unpleasant good information on Cube mapping, and it is deeply understood that it can be understood after this article. The specific address is: http://developer.nvidia.com/ Object / cube_map_ogl_tutorial.html. At first I didn't think this article was how good (but when I read it, I didn't understand the time). I found it very good when I read it. Let's talk about my thoughts according to this article. 1. Conventional 2D texture mapping is a map corresponding to a point of the object surface and a point in a 2-dimensional coordinate system. Environment Mapping is a mapping that corresponds to some points of the object surface and a vector in a 3-dimensional space. 2. Cube mapping is an environmental mapping, and other environmental mappings include Sphere mapping and dual daraboloid mapping. Sphere Mapping can be implemented by specifying in OpenGL texture coordinate generator mode GL_SPHERE_MAP, the specific code is as follows: glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); Dual Daraboloid Mapping needed to achieve the following two conditions: two texture units; // this can be realized by texture object or two texture passes; // this can be achieved by multitexture issues also need to specify the coordinate generating mode GL_REFLECTION_MAP, specific code as follows: glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); GLTEXGENI (GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP); 3. Cube mapping is existing in the form of ext_texture_cube_map in OpenGL, which appeared in OpenGL 1.3. 4. Cube mapping includes: Stable Specular Highlights, Skylight Illumination, Dynamic Cube Map Reflections, Fancy Per-Pixel Lighting. Cube mapping main purpose is to normalize vector, below is specific Step: The coordinates of any point on the surface of the cube are set (x, y, z), and the vector from the cube origin to this point is V = (x, y, z), and normalize this vector After that, the vector after setting is V '= (x', y ', z'), where -1 <= x ', y', z '<= 1, in the use of color information, indicating this unit vector In the process, special processing is required, and the size of X ', Y', Z 'is required to [0,255], and the specific conversion formula is: V' '= (V' (1, 1) ) /2.0*255; Then use the same method to assign each point on the surface of the cube to a pixel value. This is actually the establishment of a unit vector query table, any direction, any direction, and any length of the arbitrary length can correspond to a pixel value on the surface of the cube, and the color information of this pixel value is the unit vector corresponding to this vector.

The following is a complete Cube Mapping code I wrote: static GLenum faceTarget [6] = {GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT}; / * Pre-generated cube map images * / char * faceFile [6]. = {"cm_left.bmp", "cm_right.bmp", "cm_top.bmp", "cm_bottom.bmp", "cm_back.bmp", "cm_front.bmp"}; void makecubemap () {glenable (GL_TEXTURE_CUBE_MAP_EXT);

For (int i = 0; i <6; i ) {loadBMPFF (Facefile [i], facetarget [i]);

glTexParameteri (GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glEnable (GL_TEXTURE_GEN_S); glEnable (GL_TEXTURE_GEN_T); glEnable (GL_TEXTURE_GEN_R); glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT); glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT) GLTEXGENI (GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_EXT);

转载请注明原文地址:https://www.9cbs.com/read-103093.html

New Post(0)