DOC PREVIEW
OSU CS 519 - Cube Mapping

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1mjb – January 22, 2013Oregon State UniversityComputer GraphicsCube MappingMike BaileyOregon State Universitymjb – January 22, 2013Oregon State UniversityComputer GraphicsWhat is Cube Mapping?Cube Mapping is the process of creating a representation of an object’s surrounding environment as a collection of 6 images, grouped together as a single “cube map texture”. mjb – January 22, 2013Oregon State UniversityComputer GraphicsThink of it as a Folding Boxmjb – January 22, 2013Oregon State UniversityComputer GraphicsBackBottomLeftTopFront Righthttp://codemonsters.de/home/content.php?show=cubemapsUsing Cube Mapping toModel an Environmentmjb – January 22, 2013Oregon State UniversityComputer GraphicsKelley Engineering Centermjb – January 22, 2013Oregon State UniversityComputer GraphicsCube Map Texture Lookup:Given an (s,t,p) direction vector , what (r,g,b) does that correspond to?• Let L be the texture coordinate of (s, t, and p) with the largest magnitude• L determines which of the 6 2D texture “walls” is being hit by the vector (-X in this case)• The texture coordinates in that texture are the remaining two texture coordinates divided by L: (a/L,b/L)vec3 ReflectVector = reflect( vec3 eyeDir, vec3 normal );vec3 RefractVector = refract( vec3 eyeDir, vec3 normal, float Eta );-Z-Y+Y-X+XBuilt-in GLSL functions2mjb – January 22, 2013Oregon State UniversityComputer GraphicsCube Map of the World-Y+Z-Z+Y-X +Xmjb – January 22, 2013Oregon State UniversityComputer GraphicsCreating a Globe from the World Cubemap(some shapes map better than others…)Use the normal (nx,ny,nz) as the (s,t,p) for the lookup(some shapes map better than others…)mjb – January 22, 2013Oregon State UniversityComputer Graphicsout vec3 vNormal;void main( ){vNormal = normalize( aNormal );gl_Position = uModelViewProjectionMatrix * aVertex;}uniform samplerCube uTexUnit;in vec3 vNormal;out vec4 fFragColor;void main( ){vec4 newcolor = textureCube( uTexUnit, normalize(vNormal) );fFragColor = newcolor;}Creating a Globe from the World Cubemapmjb – January 22, 2013Oregon State UniversityComputer GraphicsUsing the Cube Map for Reflectionmjb – January 22, 2013Oregon State UniversityComputer GraphicsUsing the Cube Map for Reflectionout vec3 vReflectVector;void main( ){vec3 ECposition = ( uModelViewMatrix * aVertex ).xyz;vec3 eyeDir = ECposition – vec3(0.,0.,0.); // vector from eye to ptvec3 normal = normalize( uNormalMatrix * aNormal );vReflectVector = reflect( eyeDir, normal );gl_Position = uModelViewProjectionMatrix * aVertex;}in vec3 vReflectVector;uniform samplerCube uReflectUnit;out vec4 fFragColor;void main( ){vec4 newcolor = textureCube(u ReflectUnit, vReflectVector );fFragColor = newcolor;}mjb – January 22, 2013Oregon State UniversityComputer GraphicsUsing the Cube Map for Refraction3mjb – January 22, 2013Oregon State UniversityComputer GraphicsUsing the Cube Map for Refractionout vec3 vRefractVector;out vec3 vReflectVector;uniform float uEta;void main( ){vec3 ECposition = vec3( uModelViewMatrix * aVertex );vec3 eyeDir = normalize( ECposition – vec3(0.,0.,0. ) ); // vector from eye to ptvec3 normal = normalize( uNormalMatrix * aNormal );vRefractVector = refract( eyeDir, normal, uEta );vReflectVector = reflect( eyeDir, normal );gl_Position = uModelViewProjectionMatrix * aVertex;}in vec3 vReflectVector;in vec3 vRefractVector;out vec4 fFragColor;uniform float uMix;uniform samplerCube uReflectUnit;uniform samplerCube uRefractUnit;const vec4 WHITE = vec4( 1.,1.,1.,1. );void main( ){vec4 refractcolor = textureCube( uRefractUnit, vRefractVector );vec4 reflectcolor = textureCube( uReflectUnit, vReflectVector );refractcolor = mix( refractcolor, WHITE, .3 );fFragColor = mix( refractcolor, reflectcolor, uMix );}mjb – January 22, 2013Oregon State UniversityComputer Graphicsmjb – January 22, 2013Oregon State UniversityComputer Graphicsmjb – January 22, 2013Oregon State UniversityComputer


View Full Document

OSU CS 519 - Cube Mapping

Download Cube Mapping
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Cube Mapping and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Cube Mapping 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?