ShadingShading: determining light reflection from objects at each pixel.
Basic Reflection Model:
Phong Reflection Model (most commonly used)
I= kaIa + kd Id (l · n) + ksIs(v · r ) α
I : reflected-light intensity
Ambient Reflection:
Direction independent
ka Ia
Ia : incident ambient-light intensity
ka : object ambient-reflection coefficient
part of the object material properties
Lambertian / Diffusive Reflection:
Lighting-direction dependent
Id kd(ln) = Id kdcos()
Id : incident difussive-light intensity
kd : object diffusive-reflection coefficient
: angle between light direction (l) and surface normal (n). Both l and n are unit vectors.
Specular Reflection:
Viewing-direction dependent
Is ks(vr)α = Is ks cos α (Ф).
Is : incident specular-light intensity
ks : object specular-reflection coefficient
Ф : angle between reflection direction (r) and viewing
direction (v).
: specular-reflection exponent, shaniness coefficient.
1/: roughness.
The effects of ambient, diffusive and specular reflection. (http://en.wikipedia.org/wiki/Utah_teapot)
Teapots shaded with different parameters.
Attenuation:
Distance dependent, no impact on ambient light
fatt = 1/(a + bd + cd2)
d : distance from the light to the surface point.
a,b,c: constant, linear, quadratic attenuation coefficients.
I = kaIa + fatt kd Id (l · n) + fatt ksIs(v · r ) α
I = kaIa + Id kdcos() / (a + bd + cd2)
+ Is ks cos α (Ф) / (a + bd + cd2)
Summary:
I = kaIa + fatt kd Id (l · n) + fatt ksIs(v · r ) α
I = kaIa +
Id kdcos() / (a + bd + cd2) +
Is ks cos α (Ф) / (a + bd + cd2)
Colored Lights and Surfaces :I = (Ir, Ig, Ib) = { I, = r, g, b}
: color channel
->Colored lights:
Ia, Id, Is,
->Colored objects:
ka, kd, ks,
I = Ia ka + fatt Id kd(ln) + fatt Is ks(vr) α
with = r, g, b.
Ir = Iar kar + fatt Idr kdr(ln) + fatt Isr ksr(vr) α
Ig = Iag kag + fatt Idg kdg(ln) + fatt Isg ksg(vr) α
Ib = Iab kab + fatt Idb kdb(ln) + fatt Isb ksb(vr) α
Multiple Lights:
I = Ia ka + fatti [Idi kd(l i n) + Isi ks(vr i) α]
with = r, g, b.
m: number of lights.
OpenGL support ambient component for individual light.
I = [ Iai ka + fatti [Idi kd(l i n) + Isi ks(vr i) α]]
0
m
i
0
m
i
Many more things consider:
Shadow, Reflection, Transparency, Refraction, …
http://www.codeproject.com/KB/graphics/RayTracerNet.aspx Figure 2. Shading effects: a) Ambient, b) Diffuse, c) Highlights, d) Shadows
and e) Reflection (notice the reflection on the floor also)
How to get to each pixel?
Two approaches: object order and image order
Frame Buffer: a buffer of memory to store the colors of
the screen, one memory cell per pixel. http://www.webopedia.com/TERM/F/frame_buffer.htmlhttp://en.wikipedia.org/wiki/Framebufferhttp://en.wikipedia.org/wiki/Linux_framebuffer
Simple Ray Tracing: for (each scan line in image ) {
for (each pixel in scan line ) {determine ray from eye through pixel;for(each object in scene) {
if(object is intersected and is closest considered thus far)record intersection point and object id.
}set pixel’s color to that at closest object
intersection point(using the REGULAR I formula.)
}}
Recursive Ray Tracing:
Set pixel’s color to that at closest object intersection point using the I formular given below.
I= (1- kr - kt )Iregular+ kr Ir+ kt It
Iregular: regular reflection of lights from light source.
Computed by the formula above.
kr : reflection coefficient.
Ir: illumination from other objects (to be reflected).
kt : transmission coefficient.
It: illumination from other objects (to be transmitted).
Recursive Ray Tracing: for (each scan line in image ) {
for (each pixel in scan line ) {determine ray from eye through pixel;for(each object in scene) {
if(object is intersected and is closest considered thus far)record intersection point and object id.
}set pixel’s color to that at closest object
intersection point(using the RECURSIVE I formula.)
}}
Programming Image-order Shading
Ray Tracing using Povray
(Image created by Russell Yuncker) (Image created by Jian He)
http://www.iss.rwth-aachen.de/Projekte/grace/raytracing.html
Figure: mirror + shadowFree ray tracing software: POV-Ray (http://www.povray.org/) Start->Program Files->Pov Ray for Windows Run the examples in the “scenes” directory: C:\Program Files\Pov Ray for Windows\scenes. The resulting image is stored in the same directory as
the source file.
// Shading Demonstration
// Using POV-Ray's SDL (Scene Description Language)
#include "colors.inc"
#include "stdcam.inc"
sphere {
<-1.5, 0.4, -2.5>, 0.4 // center & radius
pigment { rgb <0.0, 0.5, 0.5> } //color
finish {
ambient .2 // ka
diffuse .6 // kd
specular .75 // ks
roughness .01 // 1/ } }
text {
ttf "cyrvetic.ttf" // font type
"Color Sphere", 0.1, 0 // string, thickness, gap
scale <1.25, 1.25, 4>
translate <-3.75, 0, 0>
pigment { rgb <1, 0.5, 0.2>
} }
Note:Rotation and scaling are about the origin. Need to
move the object to the origin, rotate/scale there and then move it back. (WoodBox example)
#declare Box_Lid = box {<-3.75, 0.0, -2.75> <3.75, 0.25, 2.75>
translate -2.75*z // put "hinge" at origin
rotate x*25 // open the lid
translate 2.75*z // move "hinge" back
translate y*2 // lift to top
texture {T3}
}
By default, POV-Ray has the positive y-axis pointing up, the positive x-axis pointing to the right, and the positive z-axis pointing into the screen. But this will change depending on the camera settings. (Help: camera, placing)
You place the camera in the world coordinate system. But the images are displayed from the camera’s point of view.
More Info on Ray Tracing
Povray Community (Hall of Fame, Contests, …)
http://www.povray.org/community/
UNC Ray Tracing Tutorial
http://www.cs.unc.edu/~rademach/xroads-RT/RTarticle.html
Ray Tracing Contests:
http://www.irtc.org:7777/irtc/irtc
Ray Traced Images and Videos Images for raytracing http://www.google.com/images?hl=en&rlz=&q=Raytracing&u
m=1&ie=UTF-8&source=univ&ei=Z4VxTN6RGIG0lQei3_C0Dw&sa=X&oi=image_result_group&ct=title&resnum=4&ved=0CD4QsAQwAw&biw=1280&bih=621
Videos for raytracing http://www.google.com/search?source=ig&hl=e
n&rlz=&=&q=raytracing&aq=f&aqi=g-s7g1g-s2&aql=&oq=&gs_rfai=Ch7LQko1xTLWPBZG6hATSztjlDwAAAKoEBU_Q5UWV#q=raytracing&hl=en&prmd=ivb&source=univ&tbs=vid:1&tbo=u&ei=ko1xTMeSE4TGlQePy_mhDg&sa=X&oi=video_result_group&ct=title&resnum=8&ved=0CEkQqwQwBw&fp=fff49bcb8f5e5b8c
Hardware Assisted Ray Tracing
Nvidia GF100 Ray-tracing
http://www.youtube.com/watch?v=Cbnv_z6VDj8
Writing a Ray Tracer
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm A raytracer in C++
http://www.codermind.com/articles/Raytracer-in-C++-Introduction-What-is-ray-tracing.html
Povray Source Code
http://www.povray.org/download/
Object Order Shading:
Geometrically approximate objects as patched (triangled) surfaces.Appearance-wise use three shading methods to approximate:
Flat, Gouraud, Phong
Z Buffer (depth buffer): a buffer of memory to store the z values of the screen, one memory cell per pixel.
http://en.wikipedia.org/wiki/Z-buffering
line of sight
Frame buff Z buff
Flat/Constant Shading:http://www.yourdictionary.com/computer/flat-shading
for (each object)
for(each triangle of the object)
compute its reflection
using color and normal of the triangle
for(each pixel in the triangle)
if(closer to the viewer than the
current z buffer value) {
update z buffer with the new z
update pixel color with the triangle reflection
}
Gouraud/Smooth Shading http://en.wikipedia.org/wiki/Gouraud_shading
for (each object)
for(each triangle of the object)
{ for(each vertex of in the triangle)
compute the vertex reflection
using the color and the normal of the vertex
for(each pixel in the triangle)
if(closer to the viewer than the current z buffer value)
{ update z buffer with the new z
interpolate the pixel color
from the vertex reflections.
}
}
Phong Shading:http://www.yourdictionary.com/phong-shading#computer
for (each object)for(each triangle of the object)
for(each pixel in the triangle) if(closer to the viewer than the
current z buffer value) { update z buffer with the new z
interpolate the pixel normal from the vertex normals compute the pixel color/relection using Phong reflection model using pixel normals and the properties of the
object. }
Comparaison of Shading Methods:http://en.wikipedia.org/wiki/Gouraud_shadinghttp://en.wikipedia.org/wiki/Phong_shading
Comparaison of Shading Methods: Gouraud Shadinghttp://en.wikipedia.org/wiki/Gouraud_shadinghttp://en.wikipedia.org/wiki/Phong_shading
Comparaison of Shading Methods: Gouraus vs. Phonghttp://en.wikipedia.org/wiki/Gouraud_shadinghttp://en.wikipedia.org/wiki/Phong_shading
GOURAUD SHADING
Comparaison of Shading Methods: High Resolution Gouraudhttp://en.wikipedia.org/wiki/Gouraud_shadinghttp://en.wikipedia.org/wiki/Phong_shading
Top Related