Visual AppearanceVisual AppearanceChapter 4Chapter 4
Tomas Akenine-Möller
Department of Computer Engineering
Chalmers University of Technology
Tomas Akenine-Mőller © 2002
Overview of today’s lectureOverview of today’s lecture
Refresher on simple lighting models– Plus some new stuff
FogGamma correctionTransparency and alpha
Tomas Akenine-Mőller © 2002
Compute lighting at vertices,Compute lighting at vertices,then interpolate over trianglethen interpolate over triangle
How compute lighting? We could set colors per vertex manually For a little more realism, compute lighting from
– Light sources– Material properties– Geometrical relationships
light
Geometry
blue
red green
Rasterizer
Tomas Akenine-Mőller © 2002
Refresher on lightingRefresher on lightingDiffuse component : Diffuse component : iidiffdiff i=iamb+idiff+ispec
Diffuse is Lambert’s law: cos lndiffi
Photons are scattered equally in all directions
diffdiffdiff smlni )(
Tomas Akenine-Mőller © 2002
LightingLightingSpecular component : Specular component : iispecspec
Diffuse is dull (left)Specular: simulates a highlight
Tomas Akenine-Mőller © 2002
Specular component: PhongSpecular component: PhongPhong specular highlight modelReflect l around n:
l)n2(nlr
n
lr
-lnln )(
lnshishi mm
speci )(cos)( vr
specspecm
specshi smvri ))(,0max(
Read about Blinns highlight formula: (n.h)m
Tomas Akenine-Mőller © 2002
Ambient component: Ambient component: iiambamb
Ad-hoc – tries to account for light coming from other surfaces
Just add a constant color:
ambambamb smi
Tomas Akenine-Mőller © 2002
LightingLightingi=ii=iambamb+i+idiffdiff+i+ispecspec
This is just a hack!Has little to do with how reality works!
++
=
DEMO
Tomas Akenine-Mőller © 2002
Additions to the lighting equationAdditions to the lighting equationDepends on distance: 1/(a+bt+ct )Can have more lights: just sum their
respective contributionsDifferent light types:
2
Tomas Akenine-Mőller © 2002
What’s lighting andWhat’s lighting andwhat’s shading?what’s shading?Lighting: the interaction between light
and matterShading: do lighting (at vertices) and
determine pixel’s colors from theseThree types of shading:
– Flat, Goraud, and Phong
Tomas Akenine-Mőller © 2002
FogFog
Simple atmospheric effect– A little better realism – Help in determining distances
Color of fog: color of surface: fc sc
]1,0[ )1( fff ssp ccc How to compute f ? 3 ways: linear, exponential, exponential-squared Linear:
startend
pend
zz
zzf
Tomas Akenine-Mőller © 2002
Fog exampleFog example
Often just a matter of – Choosing fog color– Choosing fog model– Turning it on
Tomas Akenine-Mőller © 2002
Gamma correctionGamma correction
If input to gun is 0.5, then you don’t get 0.5 as output in intensity
Instead, gamma correct that signal: gives linear relationship
Tomas Akenine-Mőller © 2002
Gamma correctionGamma correction
I=intensity on screenV=input voltage (electron gun)a,and are constants for each systemCommon gamma values: 2.3-2.6Assuming =0, gamma correction is:
)( VaI
)/1( icc
Tomas Akenine-Mőller © 2002
Why is it important to care about Why is it important to care about gamma correction?gamma correction?
Portability across platforms Image quality
– Texturing– Interpolation
One solution is to put gamma correction in hardware…
Tomas Akenine-Mőller © 2002
Transparency and alphaTransparency and alpha
Transparency– Very simple in real-time contexts
The tool: alpha blending (mix two colors)Alpha () is another component in the
frame buffer, or on triangle– Represents the opacity – 1.0 is totally opaque– 0.0 is totally transparent
The over operator: dso ccc )1( Rendered object
Tomas Akenine-Mőller © 2002
TransparencyTransparency
Need to sort the transparent objects– Render back to front
Lots of different other blending modes
Can store RGB in textures as wellTwo ways:
– Unmultiplied– Premultiplied