Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Inf4/MSc Computer Graphics Lecture 8 Transparency, Mirroring.

Similar presentations


Presentation on theme: "Computer Graphics Inf4/MSc Computer Graphics Lecture 8 Transparency, Mirroring."— Presentation transcript:

1 Computer Graphics Inf4/MSc Computer Graphics Lecture 8 Transparency, Mirroring

2 Computer Graphics Inf4/MSc 2 Today Environment Mapping Mirroring

3 Computer Graphics Inf4/MSc Environment Maps Simple yet powerful method to generate reflections Simulate reflections by using the reflection vector to index a spherical texture map at "infinity". Assumes that all reflected rays begin from the same point.

4 Computer Graphics Inf4/MSc Environment Mapping Example Terminator II

5 Computer Graphics Inf4/MSc Cubic Mapping The most popular method The map resides on the surfaces of a cube around the object –align the faces of the cube with the coordinate axes To generate the map: Using methods such as ray tracing –Or, take 6 photos of a real environment with a camera in the object’s position : much easier

6 Computer Graphics Inf4/MSc Examples

7 Computer Graphics Inf4/MSc Calculating the reflection vector Normal vector of the surface : N Incident Ray : I Reflection Ray: R N,I,R all normalized R = I -2 N ( N. I )‏ The texture coordinate is based on the reflection vector Assuming the origin of the vector is always in the center of the cube environment map

8 Computer Graphics Inf4/MSc Indexing Cubic Maps Assume you have R and the cube’s faces are aligned with the coordinate axes, and have texture coordinates in [0,1]x[0,1] –How do you decide which face to use? The reflection vector coordinate with the largest magnitude (0.3, 0.2, 0.8)  face in +z direction

9 Computer Graphics Inf4/MSc Indexing Cubic Maps –How do you decide which texture coordinates to use? Divide by the coordinate with the largest magnitude Now ranging [-1,1] Remapped to a value between 0 and 1. (0.3,0.2,0.8)  ((0.3/0.8 +1)*0.5, ((0.2/0.8 +1)*0.5) = (0.6875, 0.625)‏

10 Computer Graphics Inf4/MSc A Sphere Map A mapping between the reflection vector and a circular texture Prepare an image/texture in which the environment is mapped onto a sphere

11 Computer Graphics Inf4/MSc Sphere Mapping To generate the map: –Take a photograph of a shiny sphere –Mapping a cubic environment map onto a sphere –For synthetic scenes, you can use ray tracing

12 Computer Graphics Inf4/MSc Sphere Map Compute the reflection vector at the surface of the object Find the corresponding texture on the sphere map Use the texture to color the surface of the object

13 Computer Graphics Inf4/MSc Indexing Sphere Maps Given the reflection vector R (Rx,Ry,Rz)‏ (Rx,Ry,Rz)‏ (u,v) on the spherical map

14 Computer Graphics Inf4/MSc Indexing Sphere Maps The normal vector is the sum of the reflection vector and the eye vector Normalization of the vector gives If the normal is on a sphere of radius 1, its x,y coordinates are also location on the sphere map Finally converting them to make their range [0,1]

15 Computer Graphics Inf4/MSc Non-linear Mapping Problems: –Highly non-uniform sampling –Highly non-linear mapping Linear interpolation of texture coordinates picks up the wrong texture pixels –Do per-pixel sampling or use high resolution polygons Can only view from one direction CorrectLinear

16 Computer Graphics Inf4/MSc Refractive Environment Mapping When simulating effects mapping the refracted environment onto translucent materials such as ice or glass, we must use Refractive Environment Mapping

17 Computer Graphics Inf4/MSc Snell’s Law When light passes through a boundary between two materials of different density (air and water, for example), the light’s direction changes. The direction follows Snell’s Law We can do environment mapping using the refracted vector t

18 Computer Graphics Inf4/MSc Snell’s Law i: incoming vector t: refraction vector

19 Computer Graphics Inf4/MSc 19 Today Environment Mapping Mirroring

20 Computer Graphics Inf4/MSc Planar Reflections (Flat Mirrors)‏ Basic idea: Drawing a scene with mirrors! –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

21 Computer Graphics Inf4/MSc Reflecting Objects If the mirror passes through the origin, and is aligned with a coordinate axis, then just negate appropriate coordinate For example, if a reflection plane has a normal n=(0,1,0) and passes the origin, the reflected vertices can be obtained by scaling matrix S(1,-1,1)‏ MirrorWall

22 Computer Graphics Inf4/MSc Reflecting Objects If the reflection plane passes a point p and has a normal vector n, you translate and rotate the coordinate system, negate, and move back to the original coordinate system MirrorWallMirror p

23 Computer Graphics Inf4/MSc Rendering Reflected First (Using the depth buffer(Z-buffer)) First pass: –Render the reflected scene without mirror, depth test on Second pass: –Disable the color buffer, and render the mirror polygon –Now the depth buffer of the mirror region is set to the mirror’s surface Third Pass: –Enable the color buffer again –Render the original scene, without the mirror –Depth buffer stops from writing over things in mirror

24 Computer Graphics Inf4/MSc Reflection Example The color buffer after the final pass

25 Computer Graphics Inf4/MSc Reflected Scene First (issues)‏ Objects behind the mirror cause problems: –The reflected area outside the mirror region is just overwritten by the objects in the front –unless there is a wall, they will remain visible Doesn’t do: –Reflections of mirrors in mirrors (recursive reflections)‏ –Multiple mirrors in one scene (that aren’t seen in each other)‏

26 Computer Graphics Inf4/MSc We need to use the “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

27 Computer Graphics Inf4/MSc 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:, >=

28 Computer Graphics Inf4/MSc 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)‏

29 Computer Graphics Inf4/MSc mirror Reflection Example

30 Computer Graphics Inf4/MSc Normal first, reflected area next First pass: –Render the scene without the mirror For each mirror –Second pass: Clear the stencil, disable the write to the colour buffer, render the mirror, setting the stencil to 1 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 Combine it with the scene made during the first pass The stencil buffer after the second pass Rendering the mirrored scene into the stencil active area

31 Computer Graphics Inf4/MSc Multiple mirrors Can manage multiple mirrors –Render normal view, then do other passes for each mirror A recursive formulation exists for mirrors that see other mirrors –After rendering the reflected area inside the mirror surface, render the mirrors inside the mirror surface, and so on

32 Computer Graphics Inf4/MSc Another approach You can reflect the viewpoint about the mirror to see what is seen in the mirror Add a clipping plane at the plane of the mirror, remove everything that is rendered on the same side of the viewer Render the reflected scene and add it to the original scene MirrorWall

33 Computer Graphics Inf4/MSc Readings Foley 16.5-6 Real-time Rendering 2, Chapter 5.7, 6.10


Download ppt "Computer Graphics Inf4/MSc Computer Graphics Lecture 8 Transparency, Mirroring."

Similar presentations


Ads by Google