computer graphics & visualization reflections. computer graphics & visualization image...

38
computer graphics & visualization Image Synthesis Reflections

Upload: ashlynn-king

Post on 23-Dec-2015

251 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis

Reflections

Page 2: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Reflect the scene about a planar mirror

– Environment maps won‘t work in general

• Two basic algorithms– 1) flip scene through the mirror and re-render– 2) flip point of view through the mirror and re-render

Page 3: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Reflect scene through the mirror plane

– Need to find reflection matrix

• Re-render reflected scene– Restrict drawing to the mirrors visible part

Mirror

Reflected scene

Wall

Page 4: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• The reflection matrix

– p[3]: point on plane– n[3]: plane normal– d: n·p

1000

]2[2]2[]2[21]1[]2[2]0[]2[2

]1[2]2[]1[2]1[]1[21]0[]1[2

]0[2]2[]0[2]1[]0[2]0[]0[21

ndnnnnnn

ndnnnnnn

ndnnnnnn

Page 5: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Algorithm

A) Initialize ModelView matrixB) Multiply ModelView matrix with reflection matrix

- Flips the scene

C) Render scene !!!D) Render mirror plane

• Sets depth values correctly• Don‘t draw color buffer

E) Pull ModelView matrixF) Render unreflected scene

Page 6: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Problems

– Mirror is not infinite– Reflected scene should not be seen through walls

• Solution– Use stencil buffer to restrict drawing of reflected

scene– Render mirror polygons and set stencil bit– Restrict drawing of restricted scene to stenciled

pixels

Page 7: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Algorithm

A) Draw scene without mirrors • glEnable(GL_DEPTH_BUFFER_BIT)

B)Draw mirror• glColorMask(0,0,0,0)• glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)• glStencilFunc(GL_ALWAYS, 1, ~0)

C)Draw mirror again to reset depth in mirror projection- glDepthRange(1,1)- glDepthFunc(GL_ALWAYS)- glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)- glStencilFunc(GL_EQUAL, 1, ~0)

Page 8: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflectionsAlgorithm cont.

D) Draw reflected scene (clip everything in front of the mirror using glClipPlane(…) )

• glDepthRange(0,1)• glDepthFunc(GL_LESS)• glColorMask(1,1,1,1)

E)Draw mirror again to reset stencil and depth values- glColorMask(0,0,0,0)- glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO)- glDepthFunc(GL_ALWAYS)

Repeat for all other mirrors

Page 9: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflectionsRecursive reflections

– Reflect scene recursively through reflected mirrors• Generate reflection matrix for reflected mirrors

– Successively increment stencil bit in recursive reflections

• Masking within previous masks

Page 10: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections• Reflections using texture mapping

– Stores image of reflected environment– Generated by flipping scene or view point through

mirror • Image is mapped onto the reflector

• Rendering from reflected view point

• E‘ = E+2d(-N)

• R‘ = 2(NE)N-EE: view point

N: normal of mirror plane

d: dist of E to mirror plane

Page 11: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Non-Planar Reflections

Page 12: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps• Used to simulate reflections of the surrounding

scene in an object• Easily realized in software by tracing ´secondary

rays´• Alternative approach:

– Image of the 3D reflected scene is stored in a 2D environment (texture) map

– Secondary rays are looked up in the environment map during rendering

Page 13: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps

Page 14: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps• Cube maps

– Capture reflected scene in 6 projected faces

Page 15: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps• Cube maps

– General layout

– Generated by rendering the scene as seen from the objects center through each face

XNeg ZPos

YPos

YNeg

XPos ZNeg

Page 16: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps• Cube map example

Page 17: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps• Cube maps

– Introduce anisotropic sampling• Larger solid angles are subtended near the edges

– View independent• Update only when surrounding scene changes

– Texture coordinate calculation easy to do• Access via 3D texture coordinates, i.e. the reflection vector• Select largest component of reflection vector

– Selects cube face

• Divide other components through– Selects 2D texture coordinate

Page 18: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps / fixed function• Cube maps hardware support

– OpenGL support for cube maps• glTexImage2D(GL_CUBE_MAP_ENUM, ......)• GL_CUBE_MAP_ENUM one of GL_TEXTURE_CUBE_MAP_POSITIVE(NEGATIVE)_X(Y,Z)• glEnable(GL_TEXTURE_CUBE_MAP)

– Hardware suported calculation of the reflection vector

• reflection_vector

– New automatic texture coordinate generation function

• GL_REFLECTION_MAP• GL_NORMAL_MAP

– Often used to re-normalize directions

Page 19: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps / fixed functionglActiveTextureARB(GL_TEXTURE0_ARB);glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);glBindTexture(GL_TEXTURE_2D,g_uiCheesBoardTexture);glEnable(GL_TEXTURE_2D);

// Texture unit #1 contains the cubic environment map with Reflection MappingglActiveTextureARB(GL_TEXTURE1_ARB);glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,g_uiCubemap);glEnable(GL_TEXTURE_CUBE_MAP_ARB);glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP_ARB);glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP_ARB);glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_MAP_ARB);glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R);

// Setup texture matrix to transform world-space reflections back to object-spaceFLOATMATRIX4 invM;invM.getModelview();invM = invM.inverse();invM[12]=0; invM[13]=0; invM[14]=0; glMatrixMode(GL_TEXTURE);glLoadMatrixf(invM.array);glMatrixMode(GL_MODELVIEW);

glCallList(g_iBigSphere);

Page 20: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Environment maps / D3D10 HLSLTextureCube g_txEnvMap;

SamplerState g_samCube{ Filter = ANISOTROPIC; AddressU = Clamp; AddressV = Clamp;};

[..]

float4 PS_EnvMappedScene( VS_OUTPUT_SCENEENV vin ) : SV_Target{ wN = ( mul( vin.Normal, (float3x3)mWorld ) );ac float3 I = vin.wPos.xyz - vEye; float3 wR = I - 2.0f * dot( I, wN ) * wN; float4 CubeSample = lightMul*g_txEnvMap.Sample( g_samCube, wR );

[...]}

Page 21: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Planar reflections + Env MapsCombination of planar mirror reflections and environment maps

– Loop across all reflective objects– Render reflected scene as is– Store result as environment map or planar

reflection map– Repeat loop

Page 22: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Fresnel effects• The Fresnel term defines the ratio of incident

light to reflected light– F = f(,i,material properties)– It specifies the attenuation of light– For some materials like glass or plastic the

attenuation is independent of • Little reflected light at normal angles• Most light is reflected at glancing angles

– For metallic surfaces (high refraction index) the Fresnel term is close to 1

Page 23: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Fresnel effects Transparency with Fresnel term

Page 24: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Fresnel effects• The Fresnel equation (simplified)

– F =

n cosi - t n cosi +t

cosi – n t cosi +n t

+0.5

i: angle of incidence relative to N

n: index of refraction

t: n2+cosi-1 / n

2 2

Page 25: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Fresnel effects• Environment maps with fresnel term

Additive blend of diffuse and Fresnel

weighted mirror term

refraction indices: 1.5, 200

-blending of diffuse and Fresnel

weighted mirror term

refraction indices:1.5, 200

Page 26: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Bump Mapping

Page 27: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Bump mapping• Bumps could be simulated by geometric displacement

– They are detected by relative darkness or lightness of surface features

• Displacement can be avoided by computing the light distribution and by mapping these values onto the surface– Surface details (texture) are interpreted as a heightfield

and its interaction with light is simulated– Bumpmap defines the displacement of details from the

base surface

Page 28: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Bump mapping• Normal pertubation

– Displacement values perturb the surface normal– The lighting at each pixel on the surface is changed

accordingly

Page 29: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Bump mappingSurface displacement

– p´(u,v) = p(u,v) + f(u,v) • N(u,v)

Now the perturbed normal is needed for shading– N´= (Tu x Tv) / |Tu x Tv|

– Tu and Tv are the tangents to the perturbed surface points

– Tu = (px´/u, py

´/u, pz´/u)

– Tv = (px´/v, py

´/v, pz´/v)

Page 30: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Normal mapping

Page 31: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Normal Mapping

Page 32: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Normal Mapping• Similar idea to bump mapping

– Store normals instead of displacements– Avoid difference computation– Requires Tangent Space transformation

Page 33: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Tangent Space• Normals are stored as if the face lies in the x/z

plane and the normal points toward (0,0,1)• During runtime the faces are most likely

oriented differently tangent space transformation

Page 34: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Parallax mapping

Page 35: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Normal vs. Parallax Mapping

Page 36: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Steep Parallax Mapping

Page 37: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Steep Parallax Mapping// tsE = tangent space eye vector

float4 PS(VERTEX2PIXEL input) { const int numSteps = 30; float height = 1.0, step = 1.0 / numSteps;

float2 offset = input.texCoord.xy; float4 NormalBump = txNB.Sample(smLinear, offset); float2 delta = float2(-tsE.x, tsE.y) / (tsE.z * numSteps);

while (NormalBump.a < height) { height -= step; offset += delta; NormalBump = txNB.Sample(smLinear, offset); }

float4 color = txColor.Sample(smLinear, offset); float3 normal = NB.xyz * 2 - 1;

// same for light ray [...]}

Page 38: Computer graphics & visualization Reflections. computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization

computer graphics & visualization

Image Synthesis – WS 07/08Dr. Jens Krüger – Computer Graphics and Visualization Group

Combination of Techniques