Presentation is loading. Please wait.

Presentation is loading. Please wait.

Madhulika (18010), Assistant Professor, LPU.

Similar presentations


Presentation on theme: "Madhulika (18010), Assistant Professor, LPU."— Presentation transcript:

1 Madhulika (18010), Assistant Professor, LPU.
Computer Graphics Texture Mapping Madhulika (18010), Assistant Professor, LPU.

2 Madhulika (18010), Assistant Professor, LPU.
Objectives Introduce Mapping Methods Texture Mapping Madhulika (18010), Assistant Professor, LPU.

3 Madhulika (18010), Assistant Professor, LPU.
Texture can either be two-dimensional or three-dimensional and is distinguished by visual and physical textures. Physical Texture: Physical texture is known as actual texture or tactile texture. It depicts the variations on a particular surface. Physical texture can be felt by touch. Fur, wood, grains, statues, sand, glass, and so on can be included in this type of texture. 2. Visual Texture: Visual texture is the perception of having a physical texture. Every material has its own visual texture which needs to be considered before creating a composition. Textures are created by repetitive use of shapes and lines. Madhulika (18010), Assistant Professor, LPU.

4 Madhulika (18010), Assistant Professor, LPU.
Texture Mapping: Texture mapping makes use of photographical or procedural generated textures. These procedural generated patterns are made to appear very natural by subjecting them to noise or random variation. The texture mapping method involves scanning or digitizing the picture into another space, 2-D texture space. Madhulika (18010), Assistant Professor, LPU.

5 The Limits of Geometric Modeling
Although graphics cards can render over 10 million polygons per second, that number is insufficient for many phenomena Clouds Grass Terrain Skin Madhulika (18010), Assistant Professor, LPU.

6 Madhulika (18010), Assistant Professor, LPU.
Modeling an Orange Consider the problem of modeling an orange (the fruit) Start with an orange-colored sphere Too simple Replace sphere with a more complex shape Does not capture surface characteristics (small dimples) Takes too many polygons to model all the dimples Madhulika (18010), Assistant Professor, LPU.

7 Madhulika (18010), Assistant Professor, LPU.
Modeling an Orange (2) Take a picture of a real orange, scan it, and “paste” onto simple geometric model This process is known as texture mapping Still might not be sufficient because resulting surface will be smooth Need to change local shape Bump mapping Madhulika (18010), Assistant Professor, LPU.

8 Madhulika (18010), Assistant Professor, LPU.
Three Types of Mapping Texture Mapping Uses images to fill inside of polygons Environment (reflection mapping) Uses a picture of the environment for texture maps Allows simulation of highly specular surfaces Bump mapping Emulates altering normal vectors during the rendering process Madhulika (18010), Assistant Professor, LPU.

9 Texture Surface Patterns
Texture mapping Consists in mapping patterns onto the geometric description of an object. Texture Pattern to be mapped either an array of color values or as a procedure that modifies existing color or as an image from an image file Madhulika (18010), Assistant Professor, LPU.

10 Madhulika (18010), Assistant Professor, LPU.
Texture Mapping geometric model texture mapped Madhulika (18010), Assistant Professor, LPU.

11 Madhulika (18010), Assistant Professor, LPU.
Environment Mapping Madhulika (18010), Assistant Professor, LPU.

12 Madhulika (18010), Assistant Professor, LPU.
Bump Mapping Madhulika (18010), Assistant Professor, LPU.

13 Where does mapping take place?
Mapping techniques are implemented at the end of the rendering pipeline Very efficient because few polygons make it past the clipper Madhulika (18010), Assistant Professor, LPU.

14 Madhulika (18010), Assistant Professor, LPU.
Is it simple? Although the idea is simple---map an image to a surface---there are 3 or 4 coordinate systems involved 2D image 3D surface Madhulika (18010), Assistant Professor, LPU.

15 Madhulika (18010), Assistant Professor, LPU.
Coordinate Systems Parametric coordinates May be used to model curves and surfaces Texture coordinates Used to identify points in the image to be mapped Object or World Coordinates Conceptually, where the mapping takes place Window Coordinates Where the final image is really produced Madhulika (18010), Assistant Professor, LPU.

16 Madhulika (18010), Assistant Professor, LPU.
Texture Mapping parametric coordinates texture coordinates window coordinates world coordinates Madhulika (18010), Assistant Professor, LPU.

17 Madhulika (18010), Assistant Professor, LPU.
Mapping Functions Basic problem is how to find the maps Consider mapping from texture coordinates to a point a surface Appear to need three functions x = x(s,t) y = y(s,t) z = z(s,t) But we really want to go the other way (x,y,z) t s Madhulika (18010), Assistant Professor, LPU.

18 OpenGL Texture Mapping

19 Madhulika (18010), Assistant Professor, LPU.
Objectives Introduce the OpenGL texture functions and options Madhulika (18010), Assistant Professor, LPU.

20 Madhulika (18010), Assistant Professor, LPU.
Basic Strategy Three steps to applying a texture specify the texture read or generate image assign to texture enable texturing assign texture coordinates to vertices Proper mapping function is left to application specify texture parameters filtering Madhulika (18010), Assistant Professor, LPU.

21 Madhulika (18010), Assistant Professor, LPU.
Texture Mapping x y z geometry display s t image Madhulika (18010), Assistant Professor, LPU.

22 Madhulika (18010), Assistant Professor, LPU.
Texture Example The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective Madhulika (18010), Assistant Professor, LPU.

23 Texture Mapping and the OpenGL Pipeline
Images and geometry flow through separate pipelines that join during fragment processing “complex” textures do not affect geometric complexity geometry pipeline vertices pixel pipeline image fragmentprocessor Madhulika (18010), Assistant Professor, LPU.

24 Specifying a Texture Image
Define a texture image from an array of texels (texture elements) in CPU memory Glubyte my_texels[512][512]; Define as any other pixel map Scanned image Generate by application code Enable texture mapping glEnable(GL_TEXTURE_2D) OpenGL supports 1-4 dimensional texture maps Madhulika (18010), Assistant Professor, LPU.

25 Define Image as a Texture
glTexImage2D( target, level, components, w, h, border, format, type, texels ); target: type of texture, e.g. GL_TEXTURE_2D level: used for mipmapping components: number of color components w, h: width and height of texels in pixels border: used for smoothing format and type: describe texels texels: pointer to texel array glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); Madhulika (18010), Assistant Professor, LPU.

26 Madhulika (18010), Assistant Professor, LPU.
Mapping a Texture Based on parametric texture coordinates glTexCoord*() specified at each vertex Texture Space Object Space t 1, 1 (s, t) = (0.2, 0.8) 0, 1 A a c (0.4, 0.2) b B C s (0.8, 0.4) 0, 0 1, 0 Madhulika (18010), Assistant Professor, LPU.

27 Madhulika (18010), Assistant Professor, LPU.
Typical Code glBegin(GL_POLYGON); glColor3f(r0, g0, b0); //if no shading used glNormal3f(u0, v0, w0); // if shading used glTexCoord2f(s0, t0); glVertex3f(x0, y0, z0); glColor3f(r1, g1, b1); glNormal3f(u1, v1, w1); glTexCoord2f(s1, t1); glVertex3f(x1, y1, z1); . glEnd(); Note that we can use vertex arrays to increase efficiency Madhulika (18010), Assistant Professor, LPU.

28 Madhulika (18010), Assistant Professor, LPU.
Interpolation OpenGL uses interpolation to find proper texels from specified texture coordinates Can be distortions texture stretched over trapezoid showing effects of bilinear interpolation good selection of tex coordinates poor selection of tex coordinates Madhulika (18010), Assistant Professor, LPU.

29 Magnification and Minification
More than one texel can cover a pixel (minification) or more than one pixel can cover a texel (magnification) Can use point sampling (nearest texel) or linear filtering ( 2 x 2 filter) to obtain texture values Texture Polygon Magnification Minification Madhulika (18010), Assistant Professor, LPU.

30 Madhulika (18010), Assistant Professor, LPU.
Filter Modes Modes determined by glTexParameteri( target, type, mode ) glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER, GL_NEAREST); Note that linear filtering requires a border of an extra texel for filtering at edges (border = 1) Madhulika (18010), Assistant Professor, LPU.

31 Madhulika (18010), Assistant Professor, LPU.
Applying Textures II specify textures in texture objects set texture filter set texture function enable texturing supply texture coordinates for vertex coordinates can also be generated Madhulika (18010), Assistant Professor, LPU.

32 Madhulika (18010), Assistant Professor, LPU.
#include<GL/glut.h> #define red {0xff,0x00,0x00} #define blue {0x00,0x00,0xff} GLubyte texture[][3]={ red,blue, blue,red, }; void reshape(int width, int height){ glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(80,GLfloat(width)/height,1,40); glMatrixMode(GL_MODELVIEW); gluLookAt(2,-1,5,0,0,0,0,1,0); glEnable(GL_TEXTURE_2D); glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D(GL_TEXTURE_2D, 0, 3, 2,2, 0, GL_RGB, GL_UNSIGNED_BYTE,texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); } Madhulika (18010), Assistant Professor, LPU.

33 Madhulika (18010), Assistant Professor, LPU.
void display(void) { glClearColor(1.0,1.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glTexCoord2f(4, 8); glVertex2f(3, 3); glTexCoord2f(0.0, 0.0); glVertex2f(0, 0); glTexCoord2f(8, 0.0); glVertex2f(3, 0); glEnd(); glFlush(); } int main(int argc,char** argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(600,600); glutInitWindowPosition(100,100); glutCreateWindow("Texture"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); } Madhulika (18010), Assistant Professor, LPU.

34 Madhulika (18010), Assistant Professor, LPU.
Thank You Madhulika (18010), Assistant Professor, LPU.


Download ppt "Madhulika (18010), Assistant Professor, LPU."

Similar presentations


Ads by Google