1 / 43

Texture and lighting

Texture and lighting. Mark Nelson mjas@itu.dk. Purpose of today ’ s lecture. Introduction to the main conceptual elements of T&L Theoretical basis Practical approximations. Types of rendering. Photorealistic Ultimate goal is an accurate simulation of light physics/optics

kaia
Télécharger la présentation

Texture and lighting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Texture and lighting • Mark Nelson • mjas@itu.dk Fall 2013 www.itu.dk

  2. Purpose of today’s lecture Introduction to the mainconceptual elements of T&L Theoretical basis Practical approximations

  3. Types of rendering Photorealistic Ultimate goal is an accurate simulation of light physics/optics Realistic goal is a visually acceptable approximation Non-photorealistic In principle can be anything Render in an interesting way, not necessarily physically accurate Most common example is cel-shading (”cartoon-style”) Will focus on photorealistic

  4. Two basic elements Light and light propagation Surfaces with properties (And howthoseinteract)

  5. Light interacting with surfaces Fourbasicthings it can do Absorption Reflection Transmission (possibly with refraction) Diffraction (Diffraction is almostalwaysignored.)

  6. Absorption, reflection, and color Light striking a surface can be absorbed (not reflected) If uniformly, surface looks dimmer/lighter If some colors more than others, gives surface its color Reflection direction/scattering can vary Surfaces have a BDRF – bidirectional reflectance distribution function BDRF is relative to a surface normal

  7. Global illumination Assume we have light sources and BDRFs for all surfaces Can theoretically compute L(x,ω) for every surface point Luminence from that point in each direction

  8. Rendering equation L(x,ω) equals: Light emitted directly (e.g. glowing), plus For each incoming direction ω’ (integrate), The amount of incoming light from that direction, times The proportion reflected towards direction ω (given by the BDRF), times (-ω · n), which attenuates light based on incident angle

  9. Global illumination problems Impossible to actually compute! Can approximate in some ways High-quality but slow: raytracing Trace many incident rays, see where they go, add up the results

  10. More global illumination problems Doesn’t fit the pipelined rasterization model Want to texture & light locally, not globally

  11. Approximation 1: Normal-based local lighting Vertex is lit based on its distance and angle to a light source Angle effects: Flat-on vertices are fully lit Tilted vertices are less lit Perpendicular or facing-the-wrong way vertices not lit Vertex lighting is sum of contribution from each light

  12. Approximation 1 assumptions Purely diffuse reflections ”Lambertian surface” Angle dependence is ”Lambert’s cosine law” Independent local lighting

  13. Approximation 1 features Purely diffuse lighting No shiny reflections No ambient light No other fancy features also No shadows No mirror-type reflections Some of these are easier to fix than others

  14. Re-introduce a simplified BRDF No longer a full function giving reflection angles Approximate with two parts Diffuse reflections spread out in all directions Specular reflections bounce in a direction (but are not ”true” reflections; can’t see yourself in the mirror) Surfaces are a mix of Lambertian and reflective

  15. Diffuse and specular reflections

  16. Phong lighting model Diffuseand specularreflections, plus ambient light

  17. The shadow question Convex objects do self-shadowing appropriately Normals on the ”other side” are facing away, so don’t get lit Standard OpenGL-style lighting doesn’t do real shadows Several advanced techniques Shadow mapping Volumetric shadows

  18. Where does this leave us? Decent approximation to real lighting Albeit without shadows Decent approximation to flat surfaces What about more complex surfaces?

  19. Textures Make a flat surface look textured Two main reasons (related): Capture elements of the surface look not captured in the lighting model Simulate 3d elements too complex to spend polygons on (can’t spend polys on every brick in a brick wall)

  20. Textures

  21. Texture space A single texture goes from (0,0) to (1,1) Texture is addressed in texture coordinates This is texture space

  22. Texture mapping A textured triangle is texture-mapped Each vertex is mapped into a point (u,v) in texture space The texture is then drawn on the rasterized triangle’s face

  23. Texture repetition see glTexParameter

  24. Texturing in OpenGL Enable textures Load textures Create a new texture ID Bind texture ID Set up textures Store texture ID When rendering an object Store texture IDs that it uses Bind texture ID

  25. Enable texturing glEnable(GL_TEXTURE_2D) glDisable(GL_TEXTURE_2D)

  26. Create textures void *data = LoadBitmap(textureName); GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); glTextImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); // then set other parameters

  27. Render textures glBindTexture(GL_TEXTURE_2D, textureId); glBegin(GL_TRIANGLES) for( int i=0 ; i < numTriangles ; i++ ) { glTexCoord2f( v0.u(), v0.v() ); glVertex3f( v0.x(), v0.y(), v0.z() ); glTexCoord2f( v1.u(), v1.v() ); glVertex3f( v1.x(), v1.y(), v1.z() ); glTexCoord2f( v2.u(), v2.v() ); glVertex3f( v2.x(), v2.y(), v2.z() ); } glEnd();

  28. Unwraps (UV-mapping) To texture complex meshes, unwrap into texture space 3d editors will typically generate these Paint in the textures on the unwrap Load the (u,v) coordinate map with the mesh

  29. Unwraps (UV-mapping)

  30. Texture-map in model space!

  31. Texture filtering and texel density A texel is a pixel from a texture mapped into the scene Rarely matches 1-to-1 to screen pixels Texture filtering upsamples or downsamples as needed Texel density is the density of texels in the world E.g. texels/meter, if world coordinates are meters

  32. Texel density Typically want approximately constant texel density But, may have higher-resolution texture in certain places Character faces Book sitting on a table (so it can be read)

  33. Texel density mismatches

  34. Texture filtering Nearest Neighbor (GL_NEAREST) (bi)linear (GL_LINEAR) Mipmapping (GL_NEAREST_MIPMAP_*)

  35. Mipmapping Several versions of a texture of reduced size ”Texture pyramid” Efficiency (pre-filtered) Avoids some aliasing problems

  36. Mipmapping

  37. Isotropic filtering Standard texture filtering is ”isotropic” Texture is resized in texture space, like resizing a 2d image in Photoshop Gives poor results at steep viewing angles Very different texel density in width versus height Ends up with blurry textures in the distance

  38. Anisotropic filtering Rip mapping Like mip mapping but in one more dimension Pyramid of textures at different res. and aspect ratios (viewing angles) On modern hardware, ”proper” anisotropic filtering GL_TEXTURE_MAX_ANISOTROPY_EXT

  39. Anisotropic filtering

  40. Pre-baking things into textures Can bake rendered intotextures Light-mapping: pre-lit textures Oftenused to fake non-movingshadows Pre-bakedlightingcanbe made exclusivew/ GL_REPLACE (instead of the default GL_MODULATE) Reflectionmapping: pre-rendered distant reflections

  41. Reflection mapping

  42. “3d” texturing This lecture was essentially about ”2d” texturing Can also use textures to fake 3d effects Rough surfaces, bricks with some depth, etc. Bump mapping Parallax mapping

  43. Recap Should understand: Global illumination theory Phong approximation Texture mapping Texture filtering

More Related