Upload
jelani-sharp
View
29
Download
0
Embed Size (px)
DESCRIPTION
CSL 859: Advanced Computer Graphics. Dept of Computer Sc. & Engg. IIT Delhi. Lighting in OpenGL. Per-vertex per-pixel with Cg Light and Material Properties glLightfv: RGBA Color of light – RGBA in [0:255] glMaterialfv: RGBA Color of material – RGBA in [0:255] glColor3f: RGBA - PowerPoint PPT Presentation
Citation preview
CSL 859: CSL 859: Advanced Advanced Computer Computer GraphicsGraphicsDept of Computer Sc. & Engg.Dept of Computer Sc. & Engg.
IIT DelhiIIT Delhi
Lighting in OpenGLLighting in OpenGL
Per-vertexPer-vertex per-pixel with Cgper-pixel with Cg
Light and Material PropertiesLight and Material Properties glLightfv: RGBAglLightfv: RGBA
Color of light – RGBA in [0:255]Color of light – RGBA in [0:255] glMaterialfv: RGBAglMaterialfv: RGBA
Color of material – RGBA in [0:255]Color of material – RGBA in [0:255]
glColor3f: RGBAglColor3f: RGBA Uses glColorMaterialUses glColorMaterial
Color PerceptionColor Perception
Energy?Energy? Q = h/Q = h/λλ Some colors are perceived brighterSome colors are perceived brighter
λ
Intensity
DefinitionsDefinitions
Energy per unit wavelength?Energy per unit wavelength? Spectral Energy: (Q in an interval Spectral Energy: (Q in an interval ∆∆λλ)/)/∆∆λλ
→→ dQ/d dQ/dλλ IrradianceIrradiance, H , H
Spectral Power reaching surface per unit Spectral Power reaching surface per unit areaarea
RadianceRadiance ∆∆H/H/∆∆σσ, , per unit solid angleper unit solid angle
Surface RadianceSurface Radiance
dA
dA cosθ
θ θ
Surface Radiance L Surface Radiance L ==
tAQH
coscos
nn
ll
BRDFBRDF
Bi-directional Reflectance FunctionBi-directional Reflectance Function ρρioio = = LLo o / H/ Hlightlight
-io
Types of BRDFsTypes of BRDFs
IsotropicIsotropic Reflectance independent of rotation Reflectance independent of rotation
about a given surface normalabout a given surface normal Smooth plasticsSmooth plastics
AnisotropicAnisotropic Reflectance changes with rotation Reflectance changes with rotation
around a given surface normalaround a given surface normal Brushed metal, satin, hairBrushed metal, satin, hair
Luminous EfficiencyLuminous Efficiency
Lumens per watt Lumens per watt (lm/W)(lm/W)
Photopic Photopic efficiencyefficiency < < 683 lm/W683 lm/W @ Monochromatic light @ Monochromatic light
with with λλ = 555 nm = 555 nm (green).(green).
Scotopic Scotopic efficiencyefficiency < < 1700 lm/W1700 lm/W @ @ λλ = 507 nm = 507 nm
Tri-Stimulus TheoryTri-Stimulus Theory
Metamers appear the sameMetamers appear the same Eyes have sensors:Eyes have sensors:
Rods (low resolution, Peripheral, Many)Rods (low resolution, Peripheral, Many) Cones (High res, in fovea, few, 3 types) Cones (High res, in fovea, few, 3 types)
Maximum response at 420 nm (blue),Maximum response at 420 nm (blue), Maximum response at 534 nm (Bluish-Green), Maximum response at 534 nm (Bluish-Green), Maximum response at 564 nm (Yellowish-Maximum response at 564 nm (Yellowish-
Green).Green). Integrating (Filtering) SensorsIntegrating (Filtering) Sensors
CIE Color StandardCIE Color Standard
Three componentsThree components X Y ZX Y Z
Y has luminance (perceived brightness)Y has luminance (perceived brightness) X and Z have brightnessX and Z have brightness
C = X + Y + ZC = X + Y + Z Represented asRepresented as
x = X/(X+Y+Z), y = Y/(X+Y+Z), Yx = X/(X+Y+Z), y = Y/(X+Y+Z), Y x and y have chromaticity, Y has luminance x and y have chromaticity, Y has luminance
Color SpacesColor Spaces
HSVHSV RGBRGB
CMYKCMYK HDRHDR
Tone MappingTone Mapping
Z
Y
X
B
G
R
1810.12562.00752.0
0437.09778.10215.1
3962.01661.15623.2
Color in HardwareColor in Hardware RED is not the same on every monitorRED is not the same on every monitor
Not even the same everytime on the same Not even the same everytime on the same HWHW
User knobs, Ambient lightingUser knobs, Ambient lighting 0:1, in a normalized space0:1, in a normalized space
No limit in realityNo limit in reality 1 => Maximum screen brightness1 => Maximum screen brightness 0 => Minimum screen brightness0 => Minimum screen brightness
Why R, G, B?Why R, G, B? Engineering convenienceEngineering convenience
Gamma correctionGamma correction Gamma can be commonly set by the userGamma can be commonly set by the user
Hardware Color MappingHardware Color Mapping
Normalize each component to [0:1]Normalize each component to [0:1] Fixed number of stepsFixed number of steps
Monitor dependentMonitor dependent Typically 255Typically 255
Values 0..255 -> v -> intensityValues 0..255 -> v -> intensity Displayed I Displayed I αα (Maximum I) v (Maximum I) vyy
Geometry of Local Geometry of Local LightingLighting
Vertex normals make it “smooth”Vertex normals make it “smooth” Lights in Camera spaceLights in Camera space
Already specified so in OpenGLAlready specified so in OpenGLL
nn
vv
ll
Diffuse ReflectionDiffuse Reflection Reflection uniformly in all directionsReflection uniformly in all directions
Matte (Non-shiny) appearanceMatte (Non-shiny) appearance Eg, chalkEg, chalk
Most materials are not Most materials are not ideallyideally diffuse diffuse
Specular ReflectionSpecular Reflection
Light reflects in a single directionLight reflects in a single direction ShinyShiny Eg, silvered mirrorEg, silvered mirror
Most materials are not Most materials are not ideallyideally specular specular
Diffuse/Specular Diffuse/Specular ReflectionReflection
Most materials are a combination of diffuse and Most materials are a combination of diffuse and specularspecular
Reflection distribution functionReflection distribution function Need not be in a planeNeed not be in a plane Need not be isotropicNeed not be isotropic
Diffuse ReflectionDiffuse Reflection
n
Lambert’s law Lambert’s law ““Amount” of incident light per unit area is proportional Amount” of incident light per unit area is proportional
to the cosine of the angle between the normal and the to the cosine of the angle between the normal and the light rayslight rays
surface
l1
l2
l3
Diffuse ReflectionDiffuse Reflection
Unit vector Unit vector ll points points toto the light the light sourcesource
nl
lncc ldiffp f
cl
fdiff
Directional LightDirectional Light
Distant light sourceDistant light source A unit length direction vector A unit length direction vector dd and a and a
color color cc l l = -= -dd Color shining on the surface Color shining on the surface ccl l = = cc
Point LightsPoint Lights Radiates light equally in all directionsRadiates light equally in all directions Intensity from a point light source drops off proportionally Intensity from a point light source drops off proportionally
to the inverse square of the distance from the lightto the inverse square of the distance from the light
nl
2vp
cc
vpvp
l
pntlcl
fdiff v
pcpnt
AttenuationAttenuation
Sometimes, inverse square falloff behavior Sometimes, inverse square falloff behavior is hacked approximatedis hacked approximated
A common damping of “A common damping of “distance distance attenuationattenuation” is:” is:
vp
cc
dwhere
dkdkk qlc
pntl
2
Multiple LightsMultiple Lights
AdditiveAdditive Interference does happenInterference does happen
E.g., soap bubblesE.g., soap bubbles
iildifff lncc
Ambient LightAmbient Light Poor man’s “global illumination”Poor man’s “global illumination” Same amount everywhereSame amount everywhere Often, Often, ffambamb is set to equal is set to equal ffdifdif
iildiffambamb ff lnccc
Blinn’s ModelBlinn’s Model
Smooth => well defined small highlights,Smooth => well defined small highlights, Rough => Blurred, largerRough => Blurred, larger Surface roughness modeled by microfacetsSurface roughness modeled by microfacets
Distribution of microfacet normalsDistribution of microfacet normals
Polished:Polished:
Smooth:Smooth:
Rough:Rough:
Rougher:Rougher:
Specular HighlightsSpecular Highlights
n
lcl
fspec
eh
To compute the highlight intensity, we start by To compute the highlight intensity, we start by finding the unit length ‘halfway’ vector finding the unit length ‘halfway’ vector hh, which is , which is halfway between the vector halfway between the vector ll pointing to the light pointing to the light and the vector and the vector ee pointing to the eye (camera) pointing to the eye (camera)
le
leh
Specular HighlightsSpecular Highlights
The halfway vector h represents the The halfway vector h represents the direction that a mirror-like microfacet direction that a mirror-like microfacet would have to be aligned in order to would have to be aligned in order to cause the maximum highlight cause the maximum highlight intensityintensity
n
lcl
fspec
eh
Specular HighlightsSpecular Highlights
The microfacet normals generally The microfacet normals generally point in the direction of the macro point in the direction of the macro surface normalsurface normal The further The further hh is from is from nn, fewer facets are , fewer facets are
likely to align with likely to align with hh The Blinn lighting model:The Blinn lighting model:
ss is is shininessshininess or or specular exponentspecular exponent
shi nh
Specular HighlightsSpecular Highlights
Higher exponent more narrow the highlightHigher exponent more narrow the highlight
sf nh
Specular HighlightsSpecular Highlights
To account for highlights, we simply To account for highlights, we simply add an additional contribution to our add an additional contribution to our total lighting equationtotal lighting equation
Blinn lighting modelBlinn lighting model. .
siilspeciildiffambamb fff hnclnccc
Classic Lighting ModelsClassic Lighting Models LambertLambert BlinnBlinn PhongPhong
Considers angle between normal and viewerConsiders angle between normal and viewer Cook-TorranceCook-Torrance
n
lcl
fspec
eh
n
lcl
fspec
e
Blinn Phong
Cook & TorranceCook & Torrance Contributors:Contributors:
Torrance & Sparrow (1967)Torrance & Sparrow (1967) Blinn (1977)Blinn (1977)
Models of Light Reflection for Computer Synthesized Models of Light Reflection for Computer Synthesized Pictures, SIGGRAPH’77Pictures, SIGGRAPH’77
Cook & Torrance (1982)Cook & Torrance (1982) A Reflectance Model for Computer Graphics, ACM A Reflectance Model for Computer Graphics, ACM
TOG 1(1)TOG 1(1)
Thermodynamics and geometric opticsThermodynamics and geometric optics Explains off-cpecular peaksExplains off-cpecular peaks No electromagneticsNo electromagnetics
Fails for very smooth surfacesFails for very smooth surfaces
Cook & TorranceCook & Torrance
EEii = I = Iii (N.L) d (N.L) dii
R = IR = Irr/E/Eii
IIrr = R I = R Iii (N.L) d (N.L) dii
R = sRR = sRss + dR + dRdd, s + d = 1., s + d = 1.
IIrrAA = R= RAA I IiiAA ff f f = 1/= 1/ ∫ (N.L) d ∫ (N.L) dii
Shortcut, Shortcut, ff = 1 = 1
Intensity of Reflected Intensity of Reflected LightLight
IIRR = I = IiAiARRAA + + ll (I (Iilil (N (N•L•Lll) ∆) ∆ilil(sR(sRss + dR + dRDD))))
l: Individual lightsIil: Average intensity of the incident light
N: Surface unit normalLl: Unit vector in the direction of light l
∆il: solid angle of a beam of incident light
Cook-Torrance ModelCook-Torrance Model
RRss = = F D G___ F D G___
(N(N•L) (N•V)•L) (N•V)
F: Fresnel termD: Facet slope distribution: Fraction of facets oriented along H (Roughness)G: Geometrical attenuation factor (occlusion)V: Unit vector in the direction of the viewer
RoughnessRoughness
Blinn:Blinn:D = ceD = ce-(-(/m)/m)22
: angle between H and N: angle between H and N
(H: angular bisector of V and L)(H: angular bisector of V and L)
m: root mean square (rms) slope of the facetsm: root mean square (rms) slope of the facets
Beckmann:Beckmann:D = 1/(mD = 1/(m22coscos44) e) e-(tan-(tan22/m/m22))
Geometric AttenuationGeometric Attenuation
0 <= G <= 10 <= G <= 1 No occlusion to full occlusionNo occlusion to full occlusion
Geometric AttenuationGeometric Attenuation
shadowmasking
shadow
masking
facet
blocked
GGGHV
LNHNG
HVVNHN
G
I
IG
,,1min.
).)(.(2.
).)(.(2
1
Fresnel FactorFresnel Factor
Wavelength dependent. Refractive Index Mirror-like at grazing angles
1
.
1)(
1)(1
)(
)(21
222
2
2
2
2
cng
HVc
cgc
cgc
cg
cgF
Some ExamplesSome Examples
Metal :: refractive index :: absorption Metal :: refractive index :: absorption coeff.coeff.
Silver :: 0.177 :: 3.638Silver :: 0.177 :: 3.638
Copper :: 0.617 :: 2.63Copper :: 0.617 :: 2.63
Steel :: 2.485 :: 3.433 Steel :: 2.485 :: 3.433
Results of Cook-TorranceResults of Cook-Torrance
Copper colored plasticCopper colored plastic Copper vaseCopper vase
ShadingShading
GouraudGouraud Light verticesLight vertices Interpolate colorsInterpolate colors glShadeModel(GL_SMOOTH)glShadeModel(GL_SMOOTH)
PhongPhong Per-pixel (Phong) lightingPer-pixel (Phong) lighting Interpolate normalsInterpolate normals Need pixel-programsNeed pixel-programs
Advanced LightingAdvanced Lighting
ShadowsShadows Accurate reflection modelsAccurate reflection models Procedural shadersProcedural shaders Global IlluminationGlobal Illumination Volumetric effects (fog, Volumetric effects (fog,
translucency…)translucency…) Lens imperfectionsLens imperfections Exposure (& dynamic range)Exposure (& dynamic range)
Shadow MapShadow Map
Find x,y in the Find x,y in the lightlight space space UnprojectUnproject camera, then Project light camera, then Project light But x and y may not be integersBut x and y may not be integers
Find nearest integers?Find nearest integers? Read Depth bufferRead Depth buffer
Compare projected z with stored z.Compare projected z with stored z.