1Cube MappingMike BaileyOregon State Universitymjb – October 23, 2008Oregon State UniversityComputer GraphicsCube Map Texture Lookup• 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)+Y• The texture coordinates in that texture are the remaining two texture coordinates divided by L: (a/L,b/L)-Z-Y-X+Xmjb – October 23, 2008Oregon State UniversityComputer Graphicsvec3 ReflectVector = reflect( vec3 eyeDir, vec3 normal );vec3 RefractVector = refract( vec3 eyeDir, vec3 normal, float Eta );Y2Cube Map of the World-Y+Z+Y-X +Xmjb – October 23, 2008Oregon State UniversityComputer Graphics-ZCreating a Globe from the World Cubemap(some shapes map better than others…)mjb – October 23, 2008Oregon State UniversityComputer Graphics3varying vec3 nnormal;void main( ){nnormal = normalize( gl_Normal );Creating a Globe from the World Cubemapgl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;}uniform samplerCube TexUnit;varying vec3 nnormal;mjb – October 23, 2008Oregon State UniversityComputer Graphicsyg ;void main( ){vec4 newcolor = textureCube( TexUnit, normalize(nnormal) );gl_FragColor = newcolor;}Cube Map of Nvidia’s Lobbymjb – October 23, 2008Oregon State UniversityComputer Graphicshttp://www.codemonsters.de/html/textures_cubemaps.html4Showing the Cube and its Seamsmjb – October 23, 2008Oregon State UniversityComputer GraphicsUsing the Cube Map for Reflectionmjb – October 23, 2008Oregon State UniversityComputer Graphics5Using the Cube Map for Reflectionvarying vec3 ReflectVector;void main( ){vec3 ECposition = vec3( gl_ModelViewMatrix * gl_Vertex );vec3 eyeDir = ECposition–vec3(0 0 0 );// vector from eye to ptvec3 eyeDir = ECposition –vec3(0.,0.,0.);// vector from eye to ptvec3 normal = normalize( gl_NormalMatrix * gl_Normal );ReflectVector = reflect( eyeDir, normal );gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;}varying vec3 ReflectVector;uniform samplerCube ReflectUnit;mjb – October 23, 2008Oregon State UniversityComputer Graphicsvoid main( ){vec4 newcolor = textureCube( ReflectUnit, ReflectVector );gl_FragColor = newcolor;}Using the Cube Map for Refractionmjb – October 23, 2008Oregon State UniversityComputer Graphics6Using the Cube Map for Refractionvarying vec3 RefractVector;varying vec3 ReflectVector;uniform float Eta;void main( ){vec3 ECposition = vec3( gl_ModelViewMatrix * gl_Vertex );3Di li(ECiti)3(0 0 0 )// t f t tvec3 eyeDir = normalize( ECposition ) –vec3(0.,0.,0.);// vector from eye to ptvec3 normal = normalize( gl_NormalMatrix * gl_Normal );RefractVector = refract( eyeDir, normal, Eta );ReflectVector = reflect( eyeDir, normal );gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;}varying vec3 ReflectVector;varying vec3 RefractVector;uniform float Mix;uniform samplerCube ReflectUnit;mjb – October 23, 2008Oregon State UniversityComputer Graphicsp;uniform samplerCube RefractUnit;void main( ){vec4 WHITE = vec4( 1.,1.,1.,1. );vec4 refractcolor = textureCube( RefractUnit, RefractVector );vec4 reflectcolor = textureCube( ReflectUnit, ReflectVector );refractcolor = mix( refractcolor, WHITE, .3 );gl_FragColor = mix( refractcolor, reflectcolor, Mix );}mjb – October 23, 2008Oregon State UniversityComputer Graphics7mjb – October 23, 2008Oregon State UniversityComputer
View Full Document