Upcoming SlideShare
×

Like this presentation? Why not share!

# Interactive Refractions And Caustics Using Image Space Techniques

## on Jul 28, 2009

• 2,542 views

Material for studying 6.3 section of ShaderX5

Material for studying 6.3 section of ShaderX5

### Views

Total Views
2,542
Views on SlideShare
2,528
Embed Views
14

Likes
0
10
0

### 3 Embeds14

 http://codevania.blogspot.com 7 http://www.slideshare.net 6 http://www.apurva.com 1

### Report content

• Comment goes here.
Are you sure you want to

## Interactive Refractions And Caustics Using Image Space TechniquesPresentation 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…
• 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
• 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 2 nd refraction -> question of distance
• Namely, how far the 2 nd 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 P 1
• Find N 1 at P 1
• Refract to compute T 1
• Intersect the RAY( ) to find P 2
• Find N 2 at P 2
• Refract to compute T 2
• Intersect the RAY( ) to find P 3
• Compute shading at point P 3
• Approximate Distance d 1
• Identify d1
• Determine dv
• Using Depth-Peeling
• If, nt > ni
• T1 bends toward –N1
• Approximating Surface Normal N 2
• =
• Exactly determining N 2 proves difficult
• ∵ normals are associated with vertices
• ∵ P 2 is not exactly on the refractor’s surface
• Resolve by Cheap multipass approach
• 1 st pass: Render back-facing surface normals
• To texture map
• Apply projection matrix to P 2
• To determine texture coords
• Index into the texture map
• To find the normal N 2
• Graphical Overview of Rendering Image-Space Refraction
• Using V, N 1  T 1
• Graphical Overview of Rendering Image-Space Refraction
• Using d V , d N  ~d 1
• Graphical Overview of Rendering Image-Space Refraction
• P 1 + ( ~d 1 * T 1 ) = P 2
• Graphical Overview of Rendering Image-Space Refraction
• Using P 2, N BACK  N 2
• Graphical Overview of Rendering Image-Space Refraction
• Using T 1, N 2  T 2
• 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
• 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
• No, It determines a binary visibility
• Caustics Algorithm
• Borrows from the 2pass approach of photon mapping
• Idea is…
• 1 st
• Render the scene once from the light
• Storing where photons land
• 2 nd
• 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 3 rd 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
Depth Map Final Photon Locations Standard Rendering From Light’s View Incident Photon Direction
• Rendering Caustic Map Use photon data in vertex shader, render points at photon locations Light Space Eye Space
• Applying the Caustic Map
• Once the caustic map has been computed rendering 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, 1 st 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
• Code snippets 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 side createBackSideMaps // Draw just the background geometry createOtherObjectEyeTexture // 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 map Draw the refractor Draw 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 &quot;frontmost&quot; surface behind the refractor
• Code snippets DrawCausticsSceneWithLightSpaceGatheredPhotons { if ( needToRerenderCaustics ) RenderCaustics // create the buffers needed for refraction from the &quot;eye's&quot; point of view CreateRefractionBuffersForLightSpacePhotonGather // create all the necessary buffers (normal, bg geom, depth, etc) from a particular POV // Draw just the background geometry (MacBeth, Dragon, etc) DrawShadowedBackgroundWithLightSpaceCaustics DrawEnvironmentMap compute the shadow map matrix index 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 refractor FinalDrawWithAlreadyComputedLightSpaceGather // 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 }
• 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