computer graphics environment mapping mirroring.ppt

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

Upload: hmsohag

Post on 03-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 1/33

Computer  Graphics Inf4/MSc

Computer Graphics

Lecture 8

Transparency, Mirroring

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 2/33

Computer  Graphics Inf4/MSc

2

Today

• Environment Mapping

• Mirroring

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 3/33

Computer  Graphics Inf4/MSc

Environment Maps

• Simple yet powerful method to generate reflections

• Simulate reflections by using the reflection vector to indexa spherical texture map at "infinity".

• Assumes that all reflected rays begin from the same point.

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 4/33

Computer  Graphics Inf4/MSc

Environment Mapping Example

Terminator II

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 5/33

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  

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 6/33

Computer  Graphics Inf4/MSc

Examples

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 7/33

Computer  Graphics Inf4/MSc

Calculating the reflection vector 

•  Normal vector of the surface : N

• Incident Ray : I

• Reflection Ray: R 

•  N,I,R all normalizedR = I -2 N ( N . I ) 

• The texture coordinate is basedon the reflection vector 

• Assuming the origin of thevector is always in the center of the cube environment map

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 8/33

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 +zdirection

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 9/33

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) 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 10/33

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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 11/33

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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 12/33

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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 13/33

Computer  Graphics Inf4/MSc

Indexing Sphere Maps• Given the reflection vector R (Rx,Ry,Rz)

( Rx,Ry,Rz )

 

• (u,v) on the spherical map

1,0 vu

2221

2

v,

2

1

2

 z   y x

  y x

 R R Rmm

 R

m

 Ru

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 14/33

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, itsx,y coordinates are also location on the

sphere map

Finally converting them to make their range

[0,1]

 

 

 

 

m

 R

m

 R

m

 R

 R R Rm

 z  y x

 z  y x

1,,

1222

n

1,,(  z   y x R R RN

2221

1

2v,

2

1

2

 z   y x

  y x

 R R Rm

m

 R

m

 Ru

 

  

 

m

 R

m

 R

m

 R

 R R Rm

 z  y x

 z  y x

1,,

1222

n

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 15/33

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

Correct Linear 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 16/33

Computer  Graphics Inf4/MSc

Refractive Environment Mapping

• When simulating effects

mapping the refracted

environment ontotranslucent materials such

as ice or glass, we must use

Refractive Environment

Mapping

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 17/33

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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 18/33

Computer  Graphics Inf4/MSc

Snell’s Law 

• i: incoming vector 

• t: refraction vector 

))((1

,)(

where)(

2

1

r wr wk 

r w

n

nr 

k wr 

ni

nit

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 19/33

Computer  Graphics Inf4/MSc

19

Today

• Environment Mapping

• Mirroring

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 20/33

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 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 21/33

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 beobtained by scaling matrix

S(1,-1,1)

Mirror Wall

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 22/33

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

Mirror Wall Mirror 

 p

)()()1,1,1()()( 1pnnp

T  RS  RT 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 23/33

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’ssurface• Third Pass:

 –  Enable the color buffer again –  Render the original scene, without the mirror  –  Depth buffer stops from writing over things in mirror 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 24/33

Computer  Graphics Inf4/MSc

Reflection Example

The color buffer after the final pass

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 25/33

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) 

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 26/33

Computer  Graphics Inf4/MSc

We need to use the “Stencil Buffer” 

• The stencil buffer acts like a paint stencil - it lets somefragments through but notothers

• 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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 27/33

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

!=, >, >=

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 28/33

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)

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 29/33

Computer  Graphics Inf4/MSc

mirror 

Reflection Example

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 30/33

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 thecolour buffer, render the mirror, settingthe 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 thestencil test. Only things seen in the mirror will be drawn

• Combine it with the scene made during thefirst pass

The stencil buffer after the second pass

Rendering the mirrored scene into the stencil

active area

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 31/33

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

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 32/33

Computer  Graphics Inf4/MSc

Another approach

• You can reflect the viewpoint aboutthe mirror to see what is seen in themirror 

• Add a clipping plane at the plane of 

the mirror, remove everything that isrendered on the same side of theviewer 

• Render the reflected scene and add itto the original scene

Mirror Wall

7/29/2019 Computer Graphics environment mapping mirroring.ppt

http://slidepdf.com/reader/full/computer-graphics-environment-mapping-mirroringppt 33/33

Computer  Graphics Inf4/MSc

Readings

• Foley 16.5-6• Real-time Rendering 2, Chapter 5.7, 6.10