interactive refractions and caustics using image space techniques

36
Interactive Refractions and Caustics Using Image-Space Techniques Shader Study (http://cafe.naver.com/shader.cafe) Codevania (http://codevania.blogspot.com)

Upload: taewoo-kim

Post on 13-Jul-2015

1.789 views

Category:

Technology


3 download

TRANSCRIPT

Interactive Refractions and Caustics

Using Image-Space Techniques

Shader Study (http://cafe.naver.com/shader.cafe)

Codevania (http://codevania.blogspot.com)

Reflection… Refraction… Caustic…

Goal is…

Table of Contents

• Approximate, Image-Space Refraction– Refraction Algorithm– Approximating Distance– Approximating Surface Normal– Fixing Problem Cases– Putting it Together

• Approximate, Image-Space Caustics– Caustics Altorithm– Rendering From the Light– Rendering the Caustic Map– Applying the Caustic Map– Putting it Together

• Samples and Discussion• Conclusion

1d2N

Approximate, Image-Space Refraction

• Aim to solve problem of previous GPU-based refraction technique– The limitation to refract

through only a single interface

-_-!?

^-^♬

Approximate, Image-Space Refraction

• The observation underlying our approach

– Find the location of the initial intersection

– Shader can compute a refraction direction

– Using an image & approximates the location

Approximate, Image-Space Refraction

• The observation underlying our approach– Find the location of the initial intersection

• With scene geometry

– Shader can compute a refraction direction• Once the refracted direction is known

– Problem is reduced– Finding the 2nd refraction -> question of distance

» Namely, how far the 2nd surface is located» Along what? The refracted ray!

– Using an image & approximates the location• Approximates the location of the second refraction

– By using distances » Distances are easily computed on the GPU

Approximate, Image-Space Refraction

• The observation underlying our approach– Find the location of the initial intersection– Shader can compute a refraction direction– Using an image & approximates the location

Refraction Algorithm

• The steps in Computhing a pixels color– Find P1

– Find N1 at P1

– Refract to compute T1

– Intersect the RAY( ) to find P2

– Find N2 at P2

– Refract to compute T2

– Intersect the RAY( ) to find P3

– Compute shading at point P3

Approximate Distance d1

• Identify d1– Determine dv

• Using Depth-Peeling

– If, nt > ni • T1 bends toward –N1

Approximating Surface Normal N2

• =• Exactly determining N2 proves difficult– ∵normals are associated with vertices– ∵P2 is not exactly on the refractor’s surface

• Resolve by Cheap multipass approach– 1st pass: Render back-facing surface normals

• To texture map

– Apply projection matrix to P2

• To determine texture coords

– Index into the texture map• To find the normal N2

Graphical Overview of RenderingImage-Space Refraction

• Using V, N1 T1

Graphical Overview of RenderingImage-Space Refraction

• Using dV, dN ~d1

Graphical Overview of RenderingImage-Space Refraction

• P1 + ( ~d1 * T1 ) = P2

Graphical Overview of RenderingImage-Space Refraction

• Using P2, NBACK N2

Graphical Overview of RenderingImage-Space Refraction

• Using T1, N2 T2

• Using all of them Final Scene

Fixing Problem Cases

• Few problems and limitations– How to deal with

• Total Internal Reflection (TIR)• Nonconvex refractors• Inaccurate ~d1

Fixing Problem Cases

• Total Internal Reflection (TIR)

Fixing Problem Cases

• Nonconvex refractors

Fixing Problem Cases

• Inaccurate ~d1–When ~d1 overestimates p1–May not project onto a texel(contain srf Nrm)– But, occurs realatively rarely–Many occurrences fall in regions of TIR

• Rays Refractor’s side of(Surface Nrm⊥ViewDir)• Construct Surface Nrm N1(⊥V)• .

Putting it Together

Approximate, Image-Space Caustics

• Traditional Technique– Focusing of light from a specular obj– Can be interactively rendered– However, limit light to a single bounce

• Key Idea of Our Approach– Light travels multiple path in space to reach a

focal region– It’s visibility problem

• How many times a point is visible from the light

– Shadow mapping?• No, It determines a binary visibility

Caustics Algorithm

• Borrows from the 2pass approach of photon mapping

• Idea is…– 1st

• Render the scene once from the light• Storing where photons land

– 2nd

• Render a second time gathering nearby photons to determine a final color

• Difficulties exist so far– Efficiently storing and gathering the photons

Caustics Algorithm

• Propose adding a 3rd render pass– Renders photons into a caustic map– Caustic map counts photons

Rendering From the Light

• Photon Shooting– Use any existing reflection or refraction

technique– Similar to shadow mapping

Depth Map Final PhotonLocations

Standard RenderingFrom Light’s View

Incident PhotonDirection

Rendering Caustic Map

Use photon data in vertexshader, render pointsat photon locations

Light Space

Eye Space

Applying the Caustic Map

• Once the caustic map has been computedrendering the scene is straightforward– Render the scene normally

• Using your favorite technique for shdows, reflections and refraction

–When rendering diffuse surfaces• Add the caustic contribution

to the result of each pixel– How to add caustic contribution?

» Modulated by the material properties

Putting it Together

• Update Caustic map– After changes

• the light • scene geometry

• Approach must quick enough – to run twice per frame– Cause, 1st pass and Last Pass use this routine

Examples and Discussion

Conclusion

• 2 Image-Space techniques– Interactive refraction through complex object– Interactive caustics rendering

• Rely on the use of images– To store intermediate values

• Exist typical Img-spce aliasing problem– But…– Not expensive to determine intersection– Provide a viable quality-performance

spectrum

RenderCaustics{ // create the buffers needed for refraction from light (for caustics) createRefractionBuffers // create all the necessary buffers (normal, bg geom, depth, etc) from a particular POV

// draw the normals for the back sidecreateBackSideMaps// Draw just the background geometrycreateOtherObjectEyeTexture

// draw the caustics positions & directions info to the framebuffer DrawSceneCausticsToBuffer // Draw refractive geometry from a particular POV // store positions of final hitpoints into a secondary buffer

set the eye's lookat Draw the environment mapDraw the refractorDraw the non refractive objects in the scene

PerformLightSpaceGather// find caustic contribution using an image-space gather using a image from the light's POV draw photons splats using point sprites

}// Now we've got our caustic map. However, simply projecting this onto the// scene means any surface will get a caustic, whether shadowed (from the refractor) or not!// By copying the depth buffer from the background image we used above,// we can sort this out to only cast caustics onto the "frontmost" surface behind the refractor

Code snippets

DrawCausticsSceneWithLightSpaceGatheredPhotons{

if ( needToRerenderCaustics )

RenderCaustics

// create the buffers needed for refraction from the "eye's" point of viewCreateRefractionBuffersForLightSpacePhotonGather // create all the necessary buffers (normal, bg geom, depth, etc) from a particular POV// Draw just the background geometry (MacBeth, Dragon, etc) DrawShadowedBackgroundWithLightSpaceCaustics

DrawEnvironmentMapcompute the shadow map matrixindex into 'light-space caustic map'displayBackGroundGeometry

// draw the normals for the back side createBackSideMaps

// draw the scene, with caustics on the background geometry, refracted thru the refractorFinalDrawWithAlreadyComputedLightSpaceGather// takes the background geometry textures// (which includes one with accumulated photon contributions) set the eye's lookat //Draw the (background) non refractive objects in the scene displayLargeTextureWithDepth // Go ahead and actually draw the refractive object glCallList

}

Code snippets

Graphical Overview

(1) Eye-space background image without refractor(2) Eye-space background surface depth map(3) Light-space background surface depth map(4) Eye-space view of refractor's backfacing surface normals(5) Eye-space view of refractor's backfacing surface depth(6) Four frame caustic map (one frame's intensity per channel)(7) Current frame's photon buffer (i.e., the photon positions)(8) Surface normal at final photon positions (light-space)(9) Light-space depth map (a.k.a. the shadow map)

References

• http://www.cs.uiowa.edu/~cwyman/ ( 저자홈피 )• http://en.wikipedia.org/wiki/Caustic_(optics)• http://en.wikipedia.org/wiki/Caustic_(mathematics)• Refraction of Light ( 굴절 설명과 시뮬레이터 )• Atmospheric Optics ( 각종 광학 관련 사진들 )

Appendix

• Total Internal Refraction