Sunteți pe pagina 1din 33

Computer Graphics Inf4/MSc

Computer Graphics
Lecture 8
Transparency, Mirroring
Computer Graphics Inf4/MSc
2
Today

Environment Mapping
Mirroring
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.

Computer Graphics Inf4/MSc
Environment Mapping Example
Terminator II
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
objects position : much easier
Computer Graphics Inf4/MSc
Examples
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
Computer Graphics Inf4/MSc
Indexing Cubic Maps
Assume you have R and the cubes
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
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)

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
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
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
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 s s v u
( )
2
2 2
1
2
1
2
v ,
2
1
2
+ + + =
+ = + =
z y x
y
x
R R R m
m
R
m
R
u
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]
( )
|
|
.
|

\
| +
=
+ + + =
m
R
m
R
m
R
R R R m
z
y
x
z y x
1
, ,
1
2 2 2
n
) 1 , , ( + =
z y x
R R R N
( )
2
2 2
1
2
1
2
v ,
2
1
2
+ + + =
+ = + =
z y x
y
x
R R R m
m
R
m
R
u
( )
|
|
.
|

\
| +
=
+ + + =
m
R
m
R
m
R
R R R m
z
y
x
z y x
1
, ,
1
2
2 2
n
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
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

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

Computer Graphics Inf4/MSc
Snells Law
i: incoming vector
t: refraction vector



) )( ( 1
, ) (
where
) (
2
1
r w r w k
r w
n
n
r
k w r
+ + =
- =
=
+ =
n i
n i t
Computer Graphics Inf4/MSc
19
Today

Environment Mapping
Mirroring
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

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)
Mirror Wall
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 ( ) ( ) (
1
p n n p

T R S R T
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 mirrors
surface
Third Pass:
Enable the color buffer again
Render the original scene, without the mirror
Depth buffer stops from writing over things in mirror

Computer Graphics Inf4/MSc
Reflection Example
The color buffer after
the final pass
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
Doesnt do:
Reflections of mirrors in
mirrors (recursive reflections)
Multiple mirrors in one scene
(that arent seen in each other)

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
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: <, <=, =,
!=, >, >=
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)
Computer Graphics Inf4/MSc
mirror
Reflection Example
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
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
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
Mirror Wall
Computer Graphics Inf4/MSc
Readings
Foley 16.5-6
Real-time Rendering 2, Chapter 5.7, 6.10

S-ar putea să vă placă și