CPSC 591/691 Lab Assignment: Attribute-Based Texture Mapping Based on the paper: X-Toon: An extended toon shader Barla et al, NPAR ‘06 PDF + video here: plus lectures on view-dependent mapping
Mapping a Texture Based on parametric texture coordinates glTexCoord*() specified at each vertex s t 1, 1 0, 1 0, 01, 0 (s, t) = (0.2, 0.8) (0.4, 0.2) (0.8, 0.4) A BC a b c Texture SpaceObject Space
s t 1, ( s A, t A ) = ? A B C a Texture Space N. L Object Space Lambertian (diffuse) shading (view-independent) Attribute-based Texture Mapping ( s C, t C ) = ? ( s B, t B ) = ? D Tone detail (view-dependent)
s t 1, s A = N A. L A B C a Texture Space N. L Object Space The horizontal axis (0 <= s <= 1) corresponds to tone – the texture coordinate along that axis is derived from a standard Lambertian shading computation: N. L, where N is the unit surface normal and L is the unit light direction. s B = N B. L s C = N C. L (s-axis) Lambertian (Diffuse) Shading (view-independent)
s t 1, t A = D (z A, N A, …) A B C a Texture Space D Object Space The vertical axis (0 <= t <= 1) corresponds to tone detail: each value t along this axis (labelled D for detail) corresponds to a view-dependent attribute. t C = D (z C, N C, …) t B = D (z B, N B, …) (t-axis) Tone Detail (view-dependent)
s t 1, t A = D (N A, V, r) A B C a D t C = D (N C, V, r) t B = D (N B, V, r) Orientation-based attribute mapping n and v are the unit normal and view vector, respectively, and r >= 0 is a user-defined parameter that controls the magnitude of the effect. (t-axis) Tone Detail (view-dependent)
Orientation-based attribute mapping Near-silhouette abstraction and backlighting
Orientation-based attribute mapping Plastic and metal highlights
s t 1, t A = D (z A, z min, r) A B C a D Depth-based attribute mapping z is the computed depth of a vertex relative to the eye; Two user-specified parameters: zmin, the distance at which the detail starts decreasing, and r >1, the scale factor that defines the coarsest detail (greatest abstraction) at distance zmax = rzmin. t C = D (z C, z min, r) t B = D (z B, z min, r) (t-axis) Tone Detail (view-dependent)
Depth-based attribute mapping Toon shading
Depth-based attribute mapping Aerial Perspective
User Interface Load 3D models Load textures Move camera and light source Tone detail effects: – Select particular effect (use correct textures and tone detail D function) 1.Orientation-based: Near-silhouette abstraction and backlighting 2.Orientation-based: Plastic and metal highlights 3.Depth-based: Toon shading 4.Depth-based: Aerial Perspective – Control specific parameters (tone detail D function): Orientation-based: user control of parameter r Depth-based: user control of parameters zmin and r
Textures (1): Orientation-based Effects Near-silhouette abstraction and backlighting (fig. 10) Plastic and metal highlights (fig. 11)
Textures (2) : Depth-based Effects Toon (quantized) shading (fig. 7) Aerial perspective (fig. 9)
Models Sphere (great for testing/validating all mapping effects) Bodies, Mechanical Parts Heads Terrains
Loading Bitmap Texture extern int LoadBitmap(char *filename); texture.h/cpp at texture_load_exec.zip from Then you can load the texture bytes to texture memory by: my_model.id_texture=LoadBitmap("texture-name.bmp"); tutorial3.cpp at texture_load_exec.zip See example at
Loading Bitmap Texture GLubyte *teximage; int teximageWidth, teximageHeight; void Init(){... teximage = TextureLoadBitmap(“test.bmp”, &teximageWidth, &teximageHeight); } void display() {... glEnable(GL_TEXTURE); glTexImage2D(GL_TEXTURE_2D, 0, 3, teximageWidth, teximageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, teximage); /* assign texture to object */ glDisable(GL_TEXTURE); }
Steps in Texture Mapping glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); teximage = TextureLoadBitmap(“test.bmp”, &teximageWidth, &teximageHeight); Init() Step 1: Indicate how the texture is applied Step 2: Load bitmap texture
Steps in Texture Mapping Step 3: Enable texture mapping glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, 3, teximageWidth, teximageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, teximage); glBegin(GL_POLYGON); glTexCoord2f(sA, tA); glVertex3fv(vexA); glTexCoord2f(sB, tB); glVertex3fv(vexB); glTexCoord2f(sC, tC); glVertex3fv(vexC); glEnd(); glDisable(GL_TEXTURE_2D); Step 5: Draw the scene, supply texture & geometric coordinates Display() Step 4: Specify the texture