CS代考计算机代写 Graphics for Games CPI 411
Graphics for Games CPI 411
2/18/2021
Today’s Contents
• Solution of Lab#5 (Demo)
• Reflection & Refraction
• Quiz#5 (15 min) on Chapter 7
2/18/2021
• •
Review: Skybox
Skybox is a Cube Mapping, which is one of environment maps.
Vertex Shader: Calculate the incident vector as the texture coordinate.
output.TextureCoordinate = VertexPosition.xyz – CameraPosition;
Pixel Shader: Use the texCUBE function. – SkyBoxSamplerisasamplerCUBE
texCUBE(SkyBoxSampler, normalize(input.TextureCoordinate));
•
2/18/2021
Overview
• Reflection & Refraction – BasicReflection
– BasicRefraction
– Dispersion
– Fesnel
Peter Wonka
4
2/18/2021
REFLECTION
Reflection.fx
• I : incident vector (negative view vector)
• R: Reflection vector of I ; R = reflect (I, N)
• Pixel Shader:
– SetthetexturecoordinateasR(insteadofI)
– Lerpthecolorsofreflection(texCUBE)andmodel’stexture(tex2D) N
2/18/2021
I
R
Sample Movie
2/18/2021
2/18/2021
REFRACTION
Refract.fx
• I : incident vector (negative view vector)
• R: Refract vector of I with refraction factor; R = refract (I, N, etaRatio)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb509640(v=vs.85).aspx
• Pixel Shader:
– SetthetexturecoordinateasR(insteadofI)
– Lerptherefraction(texCUBE)andmodel’stexture(tex2D)
Snells Law: 1 sin 1 = 2 sin T
2/18/2021
Definition of refract • Parameter = ratio of indices of refraction
float3 refract(float3 I, float3 N, float etaRatio)
{
float cosI = dot(-I, N);
float cosT2 = 1.0f – etaRatio * etaRatio * (1.0f – cosI * cosI);
float3 T = etaRatio * I +
((etaRatio * cosI – sqrt(abs(cosT2))) * N); return T * (float3)(cosT2 > 0);
}
10
Sample Movie
2/18/2021
2/18/2021
FRESNEL EFFECT
Fresnel Effect
• E.g. water surface
– ifyoulookstraightdown→youcanseeafish
– ifyoulookfromsteeperangle→youseereflectionofsky
• Simplified Version:
reflectionCoefficient = rC =
max(0, min(1, bias + pow(1 + dot(I, N))power ))
– IandNcoincident→rCshouldbe~0
– IandNclosetoboundaryangle→rCshouldbe~1
• Cfinal = rC * Creflected + (1-rC) * Crefracted
13
Sample Movie
2/18/2021
2/18/2021
CHROMATIC DISPERSION
Chromatic Dispersion
• Refraction Index Depends on Wavelength
• Lookup Red, Green and Blue values at different locations in the reflective environment map
16
Sample Movie
2/18/2021
Dispersion v2
2/18/2021
Fresnel & Dispersion FX
• Variables: (controlled by user keyboard input in test program)
– float3 etaRatio: Ratio of indices of refraction for red, green, and blue light (packed into one float3)
– float fresnelPower: Fresnel power – float fresnelScale: Fresnel scale – float fresnelBias: Fresnel bias
2/18/2021
Fresnel & Dispersion
• Vertex Shader
…
TRed = refract(I, N, etaRatio.x); TGreen = refract(I, N, etaRatio.y); TBlue = refract(I, N, etaRatio.z);
reflectionFactor =
fresnelBias + fresnelScale * pow(1 + dot(I, N), fresnelPower);
• Pixel Shader:
float4 refractedColor;
refractedColor.r = texCUBE(environmentMap, TRed).r; refractedColor.g = texCUBE(environmentMap, TGreen).g; refractedColor.b = texCUBE(environmentMap, TBlue).b; refractedColor.a = 1;
color = lerp(refractedColor, reflectedColor, reflectionFactor); 2/18/2021
Next
• Reading Homework
– CgTutorialChapter8(BumpMap) http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter08.html
• Lab #6 (Reflection)
• Quiz#5 (Skybox)
2/18/2021