Download presentation
Presentation is loading. Please wait.
1
Reflection and Transmission Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico
2
2 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Introduction Interactions between light and materials Phong model Absorbtion Diffuse and specular reflections Puerely local Reflection: Translucent surfaces Refraction Frensel effect Chromatic dispersion
3
3 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Global vs Local Most of these effects can only be computed in a global renderer such as a ray tracer
4
4 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Ray Tracing Ray tracers can make use of all these effects in a global calculation by tracing rays R N -N L T
5
5 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Environmental Map Can use all these effects Implement in Cg with vertex and fragment programs
6
6 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Refraction With pure refraction, all the light is transmitted but the angle of refraction is determined by Snell’s law ή l sin θ l = ή t sin θ t where ή l and ή t are the speed of light relative to the speed of light in a vacuum Let ή = ή l / ή t
7
7 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computing T ή 2 sin 2 θ l = ή 2 (1- cos 2 θ l )= sin 2 θ t = 1-cos 2 θ t Solving for cos θ t Assuming normalized vectors cos θ t = T·N = (1- ή 2 (1-cos 2 θ l )) 1/2 where cos θ l = T·N T, N, and L must be coplanar T = L + N and T·T = 1 Solving T = -1/ ή L – (cos θ t - 1/ ή cos θ l ) N
8
8 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Notes Critical angle: total internal reflection 1= ή 2 (1-cos 2 θ l ) Snell’s law is a statement that light takes the shortest path (in time) Can apply to reflection maps (see Cg Tutorial) via vertex program
9
9 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fresnel Effect Some light is reflected and some transmitted at surface between two materials Amount of light reflected is greatest at shallow angle Approximation: use affine combination of refracted and reflected colors where = max (0, min(1, bias + scale (1 + L·N) power ))
10
10 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chromatic Dispersion The refraction coefficient is actually a function of wavelength N -N L TbTb TgTg TrTr
11
11 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chromatic Dispersion with Cg Easy to do with reflection maps Use three values of Make use of vector operations
12
12 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fragment Program void C7E5v_dispersion(float4 position : POSITION, float3 normal : NORMAL, out float4 oPosition : POSITION, out float reflectionFactor : COLOR, out float3 R : TEXCOORD0, out float3 TRed : TEXCOORD1, out float3 TGreen : TEXCOORD2, out float3 TBlue : TEXCOORD3, uniform float fresnelBias, uniform float fresnelScale, uniform float fresnelPower, uniform float3 etaRatio, uniform float3 eyePositionW, uniform float4x4 modelViewProj, uniform float4x4 modelToWorld) {
13
13 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fragment Program oPosition = mul(modelViewProj, position); // Compute position and normal in world space float3 positionW = mul(modelToWorld, position).xyz; float3 N = mul((float3x3)modelToWorld, normal); N = normalize(N); // Compute the incident, reflected, and refracted vectors float3 I = positionW - eyePositionW; R = reflect(I, N); I = normalize(I); TRed = refract(I, N, etaRatio.x); TGreen = refract(I, N, etaRatio.y); TBlue = refract(I, N, etaRatio.z); // Compute the reflection factor reflectionFactor = fresnelBias + fresnelScale * pow(1 + dot(I, N), fresnelPower ); }
14
14 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fragment Program void C7E6f_dispersion(float reflectionFactor : COLOR, float3 R : TEXCOORD0, float3 TRed : TEXCOORD1, float3 TGreen : TEXCOORD2, float3 TBlue : TEXCOORD3, out float4 color : COLOR, uniform samplerCUBE environmentMap0, uniform samplerCUBE environmentMap1, uniform samplerCUBE environmentMap2, uniform samplerCUBE environmentMap3) {
15
15 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Fragment Program // Fetch the reflected environment color float4 reflectedColor = texCUBE(environmentMap0, R); // Compute the refracted environment color float4 refractedColor; refractedColor.x = texCUBE(environmentMap1, TRed).x; refractedColor.y = texCUBE(environmentMap2, TGreen).y; refractedColor.z = texCUBE(environmentMap3, TBlue).z; refractedColor.w = 1; // Compute the final color color = lerp(refractedColor, reflectedColor, reflectionFactor); }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.