View
219
Download
0
Tags:
Embed Size (px)
Citation preview
Illumination and Shading
Rendering
• Simulation of physical interaction of light and matter.
• Physically correct shading is too complex– Material layers– Inter-object relations
• Good approximations are possible– Physical models when CPU available– Heuristics that look good
Light Sources
• Point source (A)– Light originates from a point– The point may be at infinity– Approximation for light sources whose
dimensions are small relative to objects
AB
C
Light Sources
• Parallel source– Light rays are parallel – Can be modeled as a light source in infinity– Approximation for far sources
AB
C
Light Sources
• Light originates at a finite area– Windows– Fluorescent
• Sometimes called distributed source
AB
C
Light Sources Example
Parallel light source
Point light source
Illumination models
• Material has following properties– Ambient– Diffuse– Specular
Illumination models
• Material has following properties– Ambient
• Compensates for global interactions• Assumes non directional light in the environment• The shading equation:
I = IAKA, IA – ambient light, KA – surface parameter
– Diffuse– Specular
Illumination models
• Material has following properties– Ambient– Diffuse
• Represents matt (non shining) surfaces • Known as Lambert model• Reflects lights in all directions• Reflected light is proportional to <N,L>
• I = IDKD<N,L>
– Specular L
N
Illumination models
• Material has following properties– Ambient– Diffuse– Specular
• Shiny (metallic) surfaces reflect light in preferred direction
• Ideal shiny surface reflects only in one direction R• Phong specularity exponent (no physical basis)
nL R
V
cos cos8 cos128
Illumination models
• Material has following properties– Ambient– Diffuse– Specular
• Computing R
N
L
R
N L N L
LNLNLLNLNR
,2),(2
Illumination Equation• Definitions
– N – point normal
– V – viewing direction
– L – lighting direction
– R – reflection direction
– D – diffuse, A – ambient, S – specular
– I – intensity
– K – surface coefficient,
– θ – angle between V and L
– α – angle between V and R
nL R
V
1
1
( ( ) ( ) )
( cos( ) cos( ) )
i
i
mn
a a d d i s ii
mn
a a d d i s ii
I I k I k N L k R V
I k I k k
Illumination comparison
Ambient
Diffuse
Specular, n = 100
Specular, n = 8
Shading
• Constant
• Gouraud
• Phong
Shading
• Constant– Color each polygon according to its normal
• Gouraud
• Phong
Shading
• Constant
• Gouraud– Compute exact colors for vertexes– Interpolate colors for interior pixels of polygon– We can miss specular highlights
• Phong
Shading
• Constant
• Gouraud
• Phong (default Inventor model)– Compute normals for vertexes– Interpolate normals for interior pixels– Compute color according to pixel normal
Shading Example
Interpolation
c1
c2 c3
scanline
c c c4 1 1 1 21 ( ) c c c5 2 1 2 31 ( )
c( , ) ( )x y c c 3 4 3 51
( , )x y
Lights in Inventor
• Light node in Inventor determines– What the light illuminates (following nodes)– Where it is located (affected by current
transformation)
• Light sources are cumulative
• SoTransformSeparator– Light should not be under standard separator– You can separate only light transformation– Only the light position can be changed
Light Nodes
• SoLight fields– On (SoSFBool)
• If the source is turned on / off
– Intensity (SOSFFloat)• 0 – minimum• 1 – maximum
– color (SOSFColor)• Color of the light
Light Nodes
• SoPointLight (Point Source)– location (SoSFVec3f)
• 3D location of a point light source • affected by current geometric transformation
Light Nodes
• SoDirectionalLight (Parallel source)– direction (SOSFVec3f)
• Direction of rays• Affected by current transformation
Light Nodes• SoSpotLight
– A point light restricted to a cone– location (SoSFVec3f)
• 3D location of a point light source • affected by current geometric transformation
– direction (SoSFVec3f)• primary direction of illumination
– dropOffRate (SoSFFloat)• rate at which the light intensity drops off from the primary
direction.• 0.0 = constant intensity• 1.0 = sharpest drop-off
Light Nodes• cutOffAngle (SoSFFloat)
– angle, in radians, where the intensity is 0.0– measured from one cone edge to the other
Light Nodes
• Directional lights are the fastest
• Spotlights are the slowest
• To increase speed use fewer lights
Multiple Lights Example
• The example contains:– A red stationary directional light– A green light moved back and forth by SoShuttle
Example// Add a directional light SoDirectionalLight *myDirLight = new SoDirectionalLight; myDirLight->direction.setValue(0, -1, -1); myDirLight->color.setValue(1, 0, 0); // red root->addChild(myDirLight);
// Add shuttle and point light SoShuttle *myShuttle = new SoShuttle; myTransformSeparator->addChild(myShuttle); myShuttle->translation0.setValue(-2, -1, 3); myShuttle->translation1.setValue( 1, 2, -3); SoPointLight *myPointLight = new SoPointLight; myTransformSeparator->addChild(myPointLight); myPointLight->color.setValue(0, 1, 0); // green
Surface Material
• Opaque surface– Light is reflected and absorbed
• Transparent surface– Light is reflected and transmitted
• SoMaterial contains– transparrency (SoMFFloat)
• 0.0 for opaque• 1.0 for transparent
Surface material• The amount reflected depends on material
– Shiny reflect more• Intensive brightness in one direction
– Rough reflect less• Equally bright from all directions
• SoMaterial contains– shininess (SoMFFloat)
• 0.0 for diffuse• 1.0 for metallic
– diffuseColor (SoMFColor) KD
– specularColor (SoMFColor) KS
Ambient light• Models inter-object relations• The object is illuminated with the same light
everywhere• One equation for each channel R,G,B.• SoEnvironment contains
– ambientIntensity ( SoSFFloat) IA
– ambientColor (SoSFColor) KAE (environment)
• SoMaterial contains– ambientColor (SoSFColor) KAM (material)
KA = KAE*KAM
Ray Tracing
Ray Tracing
Radiosity
Direct Illumination Global Illumination
Radiosity
Radiosity
Radiosity
Radiosity