Presentation is loading. Please wait.

Presentation is loading. Please wait.

Texture Mapping CAP4730: Computational Structures in Computer Graphics.

Similar presentations


Presentation on theme: "Texture Mapping CAP4730: Computational Structures in Computer Graphics."— Presentation transcript:

1 Texture Mapping CAP4730: Computational Structures in Computer Graphics

2 Outline n What is texture mapping? n Math behind texture mapping n OpenGL texture mapping n Advanced Topics in texture mapping

3 Marching towards Visual Realism http://www.3drender.com/jbirn/productions.html

4 How do we do this?

5 Another Example

6 Using only Triangles n Using only triangles to model everything is hard n Think about a label on a soup can n Instead of interpolating colors, map a pattern n Run Demo n How do you create a pattern?

7 Texture n A color array that holds an image n Similar to a framebuffer n gluint buffer[x*y*3] n 255 0 255

8 Procedural Texture n Calculate pixel values via functions

9 Image Textures Load pixel values from a file

10 Let’s look at some games

11 Texture Space n How would you store this in your program? n How much memory? s t s = [0…1] t = [0…1]

12 Object Space s t (u 0,v 0 ) (u 1,v 1 ) (u 2,v 2 ) (u 3,v 3 ) Texture -> Object Transformation s = [0…1] t = [0…1] u = [0…1] v = [0…1]

13 Going from pixels to textures Object -> Texture Transformation Image -> Object Transformation (s,t)(s,t) (u,v) (x,y)(x,y)

14 What is the question? n A pixel (x,y) corresponds to what texture element (s,t)? n Q: How do we convert (s,t) into texture element coordinates? n TEXture Elements (TEXELS) n A: Linearly Interpolate texture coordinates! n http://graphics.lcs.mit.edu/ classes/6.837/F98/Lecture2 1/Slide05.html

15 Tiling n Let’s look at the texture coordinates s t (u 0,v 0 ) (u 1,v 1 ) (u 2,v 2 ) (u 3,v 3 )

16 Textures built to Tile n Think Windows Background n Why would you want this? Discuss the Pros and Cons of tiling. n Look at code 0,0 1,1 0,1 1,0 0,0 2,2 0,2 2,0

17 Filtering n Why does this happen? (u 0,v 0 ) (u 1,v 1 ) (u 2,v 2 )

18 Filtering n Why does this happen? n What are some alternatives? (u j,v j ) (u i,v i )

19 Combining Lighting + Texturing n If you notice there is no lighting involved with texture mapping! n They are independent operations, which MAY (you decide) be combined n It all depends on how you “apply” the texture to the underlying triangle

20 Combining Lighting + Texturing n C T = Texture Color n C C = Base Triangle n Replace, C F = C T n Blend, C F = C T * C C n OpenGL: –glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); –http://trant.sgi.com/opengl/docs/man_pag es/hardcopy/GL/html/gl/texenv.html

21 Screen space vs. world space P 0 (x,y,z) P 1 (x,y,z) V 0 (x,y) V 1 (x,y)

22 Interpolation in Screen Space P 0 (x,y,z) P 1 (x,y,z) V 0 (x’,y’) V 1 (x’,y’) z’=1

23 Interpolation in World Space P 0 (x,y,z) P 1 (x,y,z) V 0 (x’,y’) V 1 (x’,y’) z’=1

24 Comparing the two n What do we need to interpolate in screen space now? n What happens if we don’t have Z? What have we discussed that doesn’ n What happens if we don’t have Z? What have we discussed that doesn’t have Z? n n Perspectively Correct Z n http://graphics.lcs.mit.edu/class es/6.837/F98/Lecture21/Slide14. html

25 Other solutions n Cost of screen space interpolation now? n Increase # of triangles

26 Linear Interpolation is wrong? n Gouraud is wrong, but why does it look okay? n Q: Why does Texture mapping not look right even though we are doing the same thing? n A: All about the slope of the interpolation and the “gradualness” or “abruptness” of the change

27 Transparencies n We will revisit this later, but we can use the alpha channel to stencil out textures. n Thus per pixel, set alpha = 1 or alpha = 0. Where alpha = 0,

28 Let’s Look at some games n Pick a favorite game from the class


Download ppt "Texture Mapping CAP4730: Computational Structures in Computer Graphics."

Similar presentations


Ads by Google