1 / 38

Image Synthesis

Image Synthesis. Reflections. 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. Planar reflections.

sadah
Download Presentation

Image Synthesis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Image Synthesis Reflections

  2. 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

  3. 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

  4. Planar reflections • The reflection matrix • p[3]: point on plane • n[3]: plane normal • d: n·p

  5. Planar reflections • Algorithm A) Initialize ModelView matrix B) 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 matrix F) Render unreflected scene

  6. 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

  7. 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)

  8. Planar reflections Algorithm 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

  9. Planar reflections Recursive reflections • Reflect scene recursively through reflected mirrors • Generate reflection matrix for reflected mirrors • Successively increment stencil bit in recursive reflections • Masking within previous masks

  10. 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(NE)N-E E: view point N: normal of mirror plane d: dist of E to mirror plane

  11. Non-Planar Reflections

  12. 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

  13. Environment maps

  14. Environment maps • Cube maps • Capture reflected scene in 6 projected faces

  15. Environment maps • Cube maps • General layout • Generated by rendering the scene as seen from the objects center through each face YPos ZPos XPos ZNeg XNeg YNeg

  16. Environment maps • Cube map example

  17. 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

  18. 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

  19. Environment maps / fixed function glActiveTextureARB(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 Mapping glActiveTextureARB(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-space FLOATMATRIX4 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);

  20. Environment maps / D3D10 HLSL TextureCube 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 ); [...] }

  21. Planar reflections + Env Maps Combination 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

  22. 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

  23. Fresnel effects Transparency with Fresnel term

  24. Fresnel effects • The Fresnel equation (simplified) • F = 2 2 n cosi - t cosi – n t + 0.5 cosi +n t n cosi +t i: angle of incidence relative to N n: index of refraction t: n2+cosi-1 / n

  25. 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

  26. Bump Mapping

  27. 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

  28. Bump mapping • Normal pertubation • Displacement values perturb the surface normal • The lighting at each pixel on the surface is changed accordingly

  29. Bump mapping Surface 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)

  30. Normal mapping

  31. Normal Mapping

  32. Normal Mapping • Similar idea to bump mapping • Store normals instead of displacements • Avoid difference computation • Requires Tangent Space transformation

  33. 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

  34. Parallax mapping

  35. Normal vs. Parallax Mapping

  36. Steep Parallax Mapping

  37. Steep Parallax Mapping // tsE = tangent space eye vector float4 PS(VERTEX2PIXEL input) { const intnumSteps = 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 [...] }

  38. Combination of Techniques

More Related