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
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 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… 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 Similar to shadow mapping 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 "frontmost" surface behind the refractor
Code snippets DrawCausticsSceneWithLightSpaceGatheredPhotons { if ( needToRerenderCaustics )   RenderCaustics // create the buffers needed for refraction from the "eye's" 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

Interactive Refractions And Caustics Using Image Space Techniques

  • 1.
    Interactive Refractions andCaustics Using Image-Space Techniques Shader Study (http://cafe.naver.com/shader.cafe) Codevania (http://codevania.blogspot.com)
  • 2.
  • 3.
  • 4.
  • 5.
    Table of ContentsApproximate, 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
  • 6.
    Approximate, Image-Space RefractionAim to solve problem of previous GPU-based refraction technique The limitation to refract through only a single interface -_-!? ^-^♬
  • 7.
    Approximate, Image-Space RefractionThe observation underlying our approach Find the location of the initial intersection Shader can compute a refraction direction Using an image & approximates the location
  • 8.
    Approximate, Image-Space RefractionThe 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
  • 9.
    Approximate, Image-Space RefractionThe observation underlying our approach Find the location of the initial intersection Shader can compute a refraction direction Using an image & approximates the location
  • 10.
    Refraction Algorithm Thesteps 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
  • 11.
    Approximate Distance d1 Identify d1 Determine dv Using Depth-Peeling If, nt > ni T1 bends toward –N1
  • 12.
    Approximating Surface NormalN 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
  • 13.
    Graphical Overview ofRendering Image-Space Refraction Using V, N 1  T 1
  • 14.
    Graphical Overview ofRendering Image-Space Refraction Using d V , d N  ~d 1
  • 15.
    Graphical Overview ofRendering Image-Space Refraction P 1 + ( ~d 1 * T 1 ) = P 2
  • 16.
    Graphical Overview ofRendering Image-Space Refraction Using P 2, N BACK  N 2
  • 17.
    Graphical Overview ofRendering Image-Space Refraction Using T 1, N 2  T 2 Using all of them  Final Scene
  • 18.
    Fixing Problem CasesFew problems and limitations How to deal with Total Internal Reflection (TIR) Nonconvex refractors Inaccurate ~d1
  • 19.
    Fixing Problem CasesTotal Internal Reflection (TIR)
  • 20.
    Fixing Problem CasesNonconvex refractors
  • 21.
    Fixing Problem CasesInaccurate ~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) .
  • 22.
  • 23.
    Approximate, Image-Space CausticsTraditional 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
  • 24.
    Caustics Algorithm Borrowsfrom 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
  • 25.
    Caustics Algorithm Proposeadding a 3 rd render pass Renders photons into a caustic map Caustic map counts photons
  • 26.
    Rendering From theLight Photon Shooting Use any existing reflection or refraction technique Similar to shadow mapping Depth Map Final Photon Locations Standard Rendering From Light’s View Incident Photon Direction
  • 27.
    Rendering Caustic MapUse photon data in vertex shader, render points at photon locations Light Space Eye Space
  • 28.
    Applying the CausticMap 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
  • 29.
    Putting it TogetherUpdate 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
  • 30.
  • 31.
    Conclusion 2 Image-Spacetechniques 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
  • 32.
    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 "frontmost" surface behind the refractor
  • 33.
    Code snippets DrawCausticsSceneWithLightSpaceGatheredPhotons{ if ( needToRerenderCaustics ) RenderCaustics // create the buffers needed for refraction from the "eye's" 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 }
  • 34.
    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)
  • 35.
    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  ( 각종 광학 관련 사진들 )
  • 36.