Material-cube Mapping__ext

Source: Internet
Author: User

1. The traditional 2D texture mapping is a mapping that corresponds to a point in the surface of an object and a point in a 2-dimensional coordinate system. An environment map (environment Mapping) is a mapping of a point on the surface of an object 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 in OpenGL by specifying the texture coordinate generation pattern for Gl_sphere_map, 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 requires the following two conditions:
Two texture units; This can be done by texture object.
or two texture passes; This can be done by multitexture.
You also need to specify the problem coordinate generation mode as GL_REFLECTION_MAP, with the following specific code:
Gltexgeni (gl_s, Gl_texture_gen_mode,gl_reflection_map);
Gltexgeni (gl_t, Gl_texture_gen_mode,gl_reflection_map);


3.Cube Mapping in OpenGL is in the form of Ext_texture_cube_map extension , the earliest appeared in OpenGL 1.3.
4.Cube mapping Other uses include: Stable specular highlights,skylight illumination,dynamic Cube Map reflections,fancy Per-pixel lighting. In Per-pixel lighting, the main purpose of Cube mapping is to normalized vectors, the following are specific steps :


The coordinates of any point on the surface of a cube (cube) are (x,y,z), then the vector from the cube origin to this point is v= (x,y,z), after normalization, the normalized vector is V ' = (x ', y ', Z '), where -1<=x ', y ', Z ' <=1 , in the process of representing the unit vector with color information, special processing is required to convert the size of x ', y ', z ' to [0,255], and the specific conversion formula is:
V ' = (V ' + (1,1,1))/2.0*255;
The same method is then used to assign each point on the cube surface to a pixel value. In fact, it is to establish a unit vector query table for any vector, any direction, any length of the vector can be on the surface of the cube corresponding to a pixel value, the pixel value of the color information is the vector corresponding to the unit vector.

Here's a complete cube mapping code I wrote:

View plain Copy to clipboard print? StaticGlenum Facetarget[6] = {gl_texture_cube_map_positive_x_ext, gl_texture_cube_map_negative_x_ext, GL_TEXTURE_CU Be_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"}; voidMakecubemap () {glenable (gl_texture_cube_map_ext); for( int  i=0; i<6; i++ )     {     loadbmpff (Facefile[i], Facetarget[i]);    &nbsp}     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);     gltexparameteri (Gl_texture_cube_map_ext, gl_texture_wrap_s, gl_clamp_to_edge);     gltexparameteri (Gl_texture_cube_map_ext, gl_texture_wrap_t, gl_clamp_to_edge);    &nbsP;gltexparameteri (Gl_texture_cube_map_ext, gl_texture_wrap_r, gl_clamp_to_edge);   } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.