Texture Mapping CS418 Computer Graphics John C. Hart
Interpolation • Rasterization will interpolate any vertex 9 attribute across a polygon’s fragments 8 • Interpolating color 7 yields Gouraud smooth 6 shading 5 • Can also define texture 4 coordinates (u,v) at vertices that, when 3 interpolated, map an 2 image onto a meshed 1 surface 0 0 1 2 3 4 5 6 7 8 9
Texture Mapping 1 v 0 0 u 1
Texture Mapping 1 .7 .6 v (.1,.7) (.2,.6) 0 0 u 1 .1 .2
Perspective z y top z front z half z back Correction v half v back v front • In this example: v d – y = -1, d = 1 and v = -z y canvas = y /(- z / d ) = y / w – v back maps to y top = -1/- z back – v half maps to y half = -1/- z half – v front maps to y bottom = -1/-z front • So need to interpolate inverse u = x v = z • clip verts + attrs: ( x , y , z , w , u , v , 1 ) • canvas vertices and attributes: (-2,-1,0) (2,-1,0) ( x / w , y / w , z / w , 1/ w , u / w , v / w ) • interpolate: ( u / w , v / w , 1/ w ) • divide per-pixel by 1/ w to get interpolated (u,v)
Example y canvas = y /(- z / d ) = y / w u/w = 1/9 -9 u = 1.0 1/w = 1/9 -5 -3 u/w = .5/9 u = 0.1 1/w = 5/9 -1 u/w = 0 u = 0.0 1/w = 1 (0,0,0) 1 3 5 7 9 z = -1 -3 -5 -7 -9 y = -1 -1 -1 -1 -1 w = 1 3 5 7 9 u = 0 .25 .5 .75 1
Magnification Aliasing • “Jaggies” – lines have a staircased edge appearance • Occur when a single texture sample (texels) projects to multiple screen pixels • (Also occurs when rasterizing lines or polygon edges)
Bilinear Filtering • “Jaggies” – lines have a staircased edge appearance • Occur when a single texture sample (texels) projects to multiple screen pixels • (Also occurs when rasterizing lines or polygon edges) • Fixed by averaging neighboring samples to find the value between samples
Minification Aliasing • Many texture pixels (texels) map into a single screen pixel • Cannot simply add them up because some pixels would take longer than others to add
MIP Mapping • Many texture pixels (texels) map into a single screen pixel • Cannot simply add them up because some pixels would take longer than others to add • Create an image pyramid from the initial texture • Each level of the pyramid half the resolution of the one below it • Choose the texture resolution whose projected texel size most closely matches pixel size
Recommend
More recommend