Automatic environment texture coordinate generation

Source: Internet
Author: User

Normal Map
Normal map is suitable for rendering scenarios with fixed light sources and diffuse reflection. The Unit-method vectors NX, NY, and NZ in their eye coordinates serve as their texture coordinates S, R, and T.

 

Reflection Map
Similar to sphere map, it is very suitable for Environment ing. The implementation method is to use the Unit Reflection vector as its texture coordinates S, R, and T.
The reflection vector can be obtained through the incident vector and the normal vector: r = u-2 * transpose (n) * (U dot n ). You can call the reflect function in glsl.

 

Vec3 reflectionmap (in vec3 ecposition3, in vec3 normal) <br/>{< br/> float ndotu, M; <br/> vec3 U; <br/> U = normalize (ecposition3); <br/> return (reflect (u, normal); <br/>}

 

Sphere Map
Only S and T are generated for spherical environment textures.

(1) the X and Y components of the reflection vector are projected onto the Unit Circle of the Rz = 0 plane.
Scale the X component RX and Y component ry of the reflection vector according to the specific reflection vector length m, where M = 2 * SQRT (RX * RX + Ry * ry + (RZ + 1) (RZ + 1 )). RX and ry divided by m, the two components are projected to a unit circle on the Rz = 0 plane.

(2) obtain the two texture coordinates in the range of [0, 1.
After scaling, multiply RX and ry in the unit circle by 0.5 and offset 0.5 to get the S and T coordinates in the range of [0, 1.

Vec2 spheremap (in vec3 ecposition3, in vec3 normal) <br/>{< br/> float m; <br/> vec3 R, U; <br/> U = normalize (ecposition3); // U is a unit vector (Eye coordinate) pointing from the origin point to the vertex. <br/> r = reflect (u, normal ); // R is the reflection vector (Eye coordinate) <br/> M = 2.0 * SQRT (R. x * r. X + R. y * r. Y + (R. Z + 1.0) * (R. Z + 1.0); <br/> return vec2 (R. x/m + 0.5, R. y/m + 0.5); <br/>}

 

Related Article

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.