Reflection and Transmission Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico
Introduction Interactions between light and materials Phong model - Absorbtion - Diffuse and specular reflections - Puerely local Reflection: Translucent surfaces - Refraction - Frensel effect - Chromatic dispersion 2
Global vs Local Most of these effects can only be computed in a global renderer such as a ray tracer 3
Ray Tracing Ray tracers can make use of all these effects in a global calculation by tracing rays R N L T -N 4
Environmental Map Can use all these effects Implement in Cg with vertex and fragment programs 5
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 6
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 7
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 8
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 )) 9
Chromatic Dispersion The refraction coefficient is actually a function of wavelength N L T r -N T g T b 10
Chromatic Dispersion with Cg Easy to do with reflection maps Use three values of Make use of vector operations 11
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) 12
Fragment Program oposition = mul(modelviewproj, position); // Compute position and normal in world space float3 positionw = mul(modeltoworld, position).xyz; float3 N = mul((float3x3)modeltoworld, 13
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) 14
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); } 15