Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.

Similar presentations


Presentation on theme: "CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering."— Presentation transcript:

1 CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering

2 CS 638, Fall 2001 Light Maps Aim: Speed up lighting calculations by pre- computing lighting and storing it in maps –Allows complex illumination models to be used in generating the map (eg shadows, radiosity) –Used in complex rendering algorithms to catch radiance (Radiance) Issues: –How is the mapping determined? –How are the maps generated? –How are they applied at run-time?

3 CS 638, Fall 2001 Choosing a Mapping Problem: In a preprocessing phase, points on polygons must be associated with points in maps One solution: –Find groups of polygons that are “near” co-planar and do not overlap when projected onto a plane Result is a mapping from polygons to planes –Combine sections of the chosen planes into larger maps –Store texture coordinates at polygon vertices Lighting tends to change quite slowly (except at hard shadows), so the map resolution can be poor

4 CS 638, Fall 2001 Generating the Map Problem: What value should go in each pixel of the light map? Solution: –Map texture pixels back into world space (using the inverse of the texture mapping) –Take the illumination of the polygon and put it in the pixel Advantages of this approach: –Choosing “good” planes means that texture pixels map to roughly square pieces of polygon - good sampling –Not too many maps are required, and not much memory is wasted

5 CS 638, Fall 2001 Example

6 CS 638, Fall 2001 Example

7 CS 638, Fall 2001 Applying Light Maps Use multi-texturing hardware –First stage: Apply color texture map –Second stage: Modulate with light map Pre-lighting textures: –Apply the light map to the texture maps as a pre-process –When is this less appealing? Multi-stage rendering: –Same effect as multi-texturing, but modulating in the frame buffer

8 CS 638, Fall 2001 Dynamic Light Maps Light maps are a preprocessing step, so they can only capture static lighting What is required to compute a light map at run-time? How might we make this tractable? –Spatial subdivision algorithms allow us to identify nearby objects, which helps with this process Compute a separate, dynamic light map at runtime using same mapping as static light map Add additional texture pass to apply the dynamic map

9 CS 638, Fall 2001 Fog Maps Dynamic modification of light-maps Put fog objects into the scene Compute where they intersect with geometry and paint the fog density into a dynamic light map –Use same mapping as static light map uses Apply the fog map as with a light map –Extra texture stage

10 CS 638, Fall 2001 Fog Map Example

11 CS 638, Fall 2001 Bump Mapping Bump mapping modifies the surface normal vector according to information in the map View dependent: the effect of the bumps depends on which direction the surface is viewed from Bump mapping can be implemented with multi- texturing or multi-pass rendering

12 CS 638, Fall 2001 Storing the Bump Map Several options for what to store in the map –The normal vector to use –An offset to the default normal vector –Data derived from the normal vector –Illumination changes for a fixed view Multi-texturing map: –Store four maps (or more) showing the illumination effects of the bumps from four (or more) view directions –Key point: Bump maps on diffuse surfaces just make them lighter or darker - don’t change the color

13 CS 638, Fall 2001 Multi-Texture Bump Maps At run time: –Compute the dot product of the view direction with the ideal view direction for each bump map Bump maps that were computed with views near the current one will have big dot products –Use the computed dot product as a blend factor when applying each bump map –Must be able to specify the blend function to the texture unit OpenGL allows this Textbook has details for more accurate bump-mapping –Note that computing a dot product between the light and the bump map value can be done with current hardware

14 CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass techniques render the scene, or parts of the scene, multiple times –Makes use of auxiliary buffers to hold information –Make use of tests and logical operations on values in the buffers –Really, a set of functionality that can be used to achieve a wide range of effects Mirrors, shadows, bump-maps, anti-aliasing, compositing, …

15 CS 638, Fall 2001 Buffers Color buffers: Store RGBA color information for each pixel –OpenGL actually defines four or more color buffers: front/back, left/right and auxiliary color buffers Depth buffer: Stores depth information for each pixel Stencil buffer: Stores some number of bits for each pixel Accumulation buffer: Like a color buffer, but with higher resolution and different operations Buffers are defined by: –The type of values they store –The logical operations that they influence –The way they are written and read

16 CS 638, Fall 2001 Fragment Tests A fragment is a pixel-sized piece of shaded polygon, with color and depth information The tests and operations performed with the fragment on its way to the color buffer are essential to understanding multi- pass techniques Most important are, in order: –Alpha test –Stencil test –Depth test –Blending As the fragment passes through, some of the buffers may also have values stored into them

17 CS 638, Fall 2001 Alpha Test The alpha test either allows a fragment to pass, or stops it, depending on the outcome of a test: Here,  fragment is the fragment’s alpha value, and  reference is a reference alpha value that you specify op is one of: –, >= There are also the special tests: Always and Never –Always let the fragment through or never let it through What is a sensible default? if (  fragment op  reference ) pass fragment on

18 CS 638, Fall 2001 Billboards Billboards are polygons with an image textured onto them, typically used for things like trees –More precisely, and image-based rendering method where complex geometry (the tree) is replaced with an image placed in the scene (the textured polygon) The texture normally has alpha values associated with it: 1 where the tree is, and 0 where it isn’t –So you can see through the polygon in places where the tree isn’t

19 CS 638, Fall 2001 Alpha Test and Billboards You can use texture blending to make the polygon see through, but there is a big problem –What happens if you draw the billboard and then draw something behind it? –Hint: Think about the depth buffer values –This is one reason why transparent objects must be rendered back to front The best way to draw billboards is with an alpha test: Do not let alpha < 0.5 pass through –Depth buffer is never set for fragments that are see through –Doesn’t work for transparent polygons - more later

20 CS 638, Fall 2001 Stencil Buffer The stencil buffer acts like a paint stencil - it lets some fragments through but not others It stores multi-bit values You specify two things: –The test that controls which fragments get through –The operations to perform on the buffer when the test passes or fails –All tests/operation look at the value in the stencil that corresponds to the pixel location of the fragment Typical usage: One rendering pass sets values in the stencil, which control how various parts of the screen are drawn in the second pass

21 CS 638, Fall 2001 Stencil Tests You give an operation, a reference value, and a mask Operations: –Always let the fragment through –Never let the fragment through –Logical operations between the reference value and the value in the buffer:, >= The mask is used to select particular bit-planes for the operation –(reference & mask ) op ( buffer & mask )

22 CS 638, Fall 2001 Stencil Operations Specify three different operations –If the stencil test fails –If the stencil passes but the depth test fails –If the stencil passes and the depth test passes Operations are: –Keep the current stencil value –Zero the stencil –Replace the stencil with the reference value –Increment the stencil –Decrement the stencil –Invert the stencil (bitwise)

23 CS 638, Fall 2001 Depth Test and Operation Depth test compares the depth of the fragment and the depth in the buffer –Depth increase with greater distance from viewer Tests are: Always, Never,, >= Depth operation is to write the fragments depth to the buffer, or to leave the buffer unchanged –Why do the test but leave the buffer unchanged? Each buffer stores different information about the pixel, so a test on one buffer may be useful in managing another

24 CS 638, Fall 2001 Multi-Pass Algorithms Designing a multi-pass algorithm is a non-trivial task –At least one person I know of has received a PhD for developing such algorithms References for multi-pass algorithms: –The OpenGL Programming guide discusses many multi-pass techniques in a reasonably understandable manner –Game Programming Gems has some –Watt and Policarpo has others –Several have been published as academic papers –As always, the web is your friend

25 CS 638, Fall 2001 Planar Reflections (Flat Mirrors) Use the stencil buffer, color buffer and depth buffer Basic idea: –We need to draw all the stuff around the mirror –We need to draw the stuff in the mirror, reflected, without drawing over the things around the mirror Key point: You can reflect the viewpoint about the mirror to see what is seen in the mirror, or you can reflect the world about the mirror

26 CS 638, Fall 2001 Reflecting Objects If the mirror passes through the origin, and is aligned with a coordinate axis, then just negate appropriate coordinate Otherwise, transform into mirror space, reflect, transform back MirrorWall

27 CS 638, Fall 2001 Small Problem Reflecting changes the apparent vertex order as seen by the viewer –Impacts back-face culling, so turn it off or change interpretation of vertex ordering Reflecting the view has the same effect, but this time it also shift the left-right sense in the frame buffer –Works, just harder to understand what’s happening

28 CS 638, Fall 2001 Rendering Reflected First First pass: –Render the reflected scene without mirror, depth test on Second pass: –Disable the color buffer, Enable the stencil buffer to always pass but set the buffer, Render the mirror polygon –Now, set the stencil test to only pass points outside the mirror –Clear the color buffer - does not clear points inside mirror area Third Pass: –Enable the color buffer again, Disable the stencil buffer –Render the original scene, without the mirror –Depth buffer stops from writing over things in mirror

29 CS 638, Fall 2001 Reflection Example The stencil buffer after the second pass The color buffer after the second pass – the reflected scene cleared outside the stencil

30 CS 638, Fall 2001 Reflection Example The color buffer after the final pass

31 CS 638, Fall 2001 Reflected Scene First (issues) If the mirror is infinite, there is no need for the second pass –But might want to apply a texture to roughen the reflection If the mirror plane is covered in something (a wall) then no need to use the stencil or clear the color buffer in pass 2 Objects behind the mirror cause problems: –Will appear in reflected view in front of mirror –Solution is to use clipping plane to cut away things on wrong side of mirror Curved mirrors by reflecting vertices differently Doesn’t do: –Reflections of mirrors in mirrors (recursive reflections) –Multiple mirrors in one scene (that aren’t seen in each other)

32 CS 638, Fall 2001 Rendering Normal First First pass: –Render the scene without the mirror Second pass: –Clear the stencil, Render the mirror, setting the stencil if the depth test passes Third pass: –Clear the depth buffer with the stencil active, passing things inside the mirror only –Reflect the world and draw using the stencil test. Only things seen in the mirror will be drawn

33 CS 638, Fall 2001 Normal First Addendum Same problem with objects behind mirror –Same solution Can manage multiple mirrors –Render normal view, then do other passes for each mirror –Only works for non-overlapping mirrors (in view) –But, could be extended with more tests and passes A recursive formulation exists for mirrors that see other mirrors


Download ppt "CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering."

Similar presentations


Ads by Google