Surface Mappng One CS7GV3 Real-tme Renderng
Textures Add complexty to scenes wthout addtonal geometry Textures store ths nformaton, can be any dmenson Many dfferent types: Dffuse most common Ambent, specular, gloss maps Bump, normal, dsplacement maps Reflecton, refracton maps
Textures and Renderng Recall the Renderng Equaton: I( x, x') g( x, x')[ e( x, x') ( x, x', x") I( x', x") dx"] I(x, x ) : ntensty of lght passng from x to x g(x, x ) = (geometry factor) e (x, x ) : ntensty of lght emtted by x and passng to x r (x, x, x ) : b-drectonal reflectance scalng factor for lght passng from x to x by reflectng off x Based on last few lectures, lets smplfy ths as: I g e L df df s n.l L h.n s s L a a
Dffuse Map Smplest texturng drectly apples a colour to object In basc llumnaton colour s mostly based on dffuse component I g e L df df n.l L h.n s s L a a
Emsson Map A..a. Glow map Models lght sources on a surface Does not depend on surface normal or lght sources. I g e L df df n.l L h.n s s L a a
Specular Map Specular color : Gloss map Shnness Control the specular exponent n Phong lght model Or roughness n other lght models I g e L df df n.l L h.n s s L a a
Specular Map + Specular Exp. Map Dffuse Color Specular Color Specular Exponent Shny Dull
Normal Map Use texture as a nput to perturb geometrc representaton I g e L df df n.l L h.n s s L a a
Vsblty Mappngs Parallax mappng Shft n texture looup based on vew-ray ntersecton wth heghtfeld Can account for occlusons Alpha Mappng: Transparency mappng across prmtve Shadow mappng I g e L df df n.l L h.n s s L a a
Lght & Envronment Mappng Approxmaton of ncomng radance Lght maps: pre-computed ncdent flux across 2D surfaces Envronment Maps: more complex 3D loo up of ncomng flux n scene Can combne wth other maps Texture d envronment Lght Maps Merged Scene I g e L df df n.l L h.n s s L a a
Texture Mappng For 2D textures, we need a 3D to 2D mappng Sometmes called a projector functon Each vertex n the model wll need a (u,v) co-ordnate Normally defned by the artst and added to the vertex stream
Texture Mappng Components XYZ UV [0,1] U [0-wdth] V [0-heght] RGB K d? N, From: Aenne-Moller, Hanes, Hoffman Real-tme Renderng 3 rd Ed.
UV Mappngs
Example: Cylndrcal
Tlng, Wrappng etc. Can specfy rules for (u, v) behavour outsde [0, 1] Tlng: number of repettons of texture wthn space Tlng Mode: normal, mrror, no-tlng (clamp) The (u, v) co-ordnate can be manpulated by shader Just another nput e.g. could rotate texture co-ordnate
Bump Mappng Add surface geometrc detal wthout addtonal vertces A real bump dstorts the drectons of the normals (ths effects calculatons of lght reflectance) Fae bumps created by dstortng the normals although the model geometry s stll flat. e.g. A bump-map texture appled to a flat polygon.
Bump Mappng Use a texture map to perturb the normal to the surface Tradtonally represent ths as ether: d stored n 2 separate scalar textures (for d u and d v ) store a heghtfeld and compute or approxmate d from the surface dfferentals
Bump/Normal Mappng Gve the lluson of geometrc detal Shape percepton depends on lghtng cues Wthout normal mappng Wth bump mappng
Normal Mappng A more commonly used method s normal mappng Also nown as dot3 bump mappng Image taen from Wpeda avalable at http://en.wpeda.org/w/normal_mappng
Object Space Normal Mappng Basc Idea: Store the actual surface normal n the texture (RGB = nx, ny, nz) At each pxel, loo up the normal map, and use ths nstead of the nterpolated normal Tool support requred f generatng normals from hgh-res surfaces
Per-vertex Lghtng Only Normal Maps e.g. Combne wth Mesh Smplfcaton Cohen, Olano, Manocha, Appearance-preservng smplfcaton, SIGGRAPH, 1998. http://gamma.cs.unc.edu/aps/aps.pdf
Object Space Normal Mappng Object space has some problems: Not very flexble Strongly ted to specfc object Can t tle map or use symmetry Don t wor so well wth MIP maps or sharp edges Image from http://www.3dngdoms.com/tutoral.htm
Tangent Space Normal Mappng Normal s stored relatve to the tangent space of the object Sort of le a local normal Defne a local co-ordnate frame Form a co-ordnate system from normal n and tangent t and bnormal b Then defne dsplaced normal n n ths space n t b z y x z y x z y x T n n n b b b t t t n b t M t n n' b
Shader Setup Applcaton must send normal and tangent vector to the shader The normal s straghtforward avalable as bult n attrbute The tangent s slghtly trcy (for polygonal objects) Pass ths down as a custom attrbute B-tangent can be calculated n the shader Must be consstent wth the tangent vector to avod nterpolaton problems
Lghtng wth the bump map Transform lght and vew vectors nto tangent space (per vertex) Vertex Shader: varyng vec3 v; varyng vec3 l; unform vec4 L; //drectonal lght n eye space attrbute vec3 rm_tangent; attrbute vec3 rm_btangent; //here we get the btangent from applcaton //but we could calculate ths n the shader vod man(vod) { gl_poston = ftransform(); gl_texcoord[0] = gl_texturematrx[0]*gl_multtexcoord0; vec4 camera = gl_modelvewmatrxinverse*vec4(0.0, 0.0, 0.0, 1.0); vec3 vew = normalze(camera.xyz-gl_vertex.xyz); //object space vew and lght vector vec3 lght = normalze(gl_modelvewmatrxtranspose*l).xyz; } //TBNnv transforms vectors from object space to tangent space mat3 TBNnv(rm_Tangent, rm_btangent, gl_normal); l = TBNnv*lght; v = TBNnv*vew;
Lghtng wth the bump map Fragment Shader unform vec4 ambentcolor; unform vec4 dffusecolor; unform vec4 specularcolor; unform sampler2d dffusetex; unform sampler2d normaltex; unform float shnness; varyng vec3 v; varyng vec3 l; vod man(vod) { l = normalze(l); v = normalze(v); } vec3 n = 2.0*texture2D( normaltex, gl_texcoord[0].st ).xyz - 1.0; //tangent-space normal vec4 dffuseterm = texture2d( dffusetex, gl_texcoord[0].st)* dffusecolor *(max( 0.0, dot(n, l))); vec3 r = reflect(-l, n); //tangent-space reflecton vector vec4 specularterm = specularcolor*pow(max(0.0, dot(r, v)), shnness); gl_fragcolor = ambentcolor + dffuseterm + specularterm;
Tangent Space Normal Mappng
Tangent Space Normal Mappng Predomnantly blue: Why? No dsplacement means normal = n n tangent space n = [0 0 1] whch maps to RGB blue Dsplaced normals are relatvely close to ths Storage: Record 255*(n +1)/2 n normal map (to map to [0,255] range)