Ray Tracing TP OpenGL
description
Transcript of Ray Tracing TP OpenGL
Ray TracingRay TracingTP OpenGLTP OpenGL
PHAM Trong TônPHAM Trong Tôn
WANG YuanhangWANG Yuanhang
Scene management and displayScene management and display
> Scene display workflow
.call Scene::draw() in viewer
.Scene::draw() scans through QPtrList<Object> listObj_
.for each Object* obj in listObj_
.call obj->draw(), which is a virtual function
.draw() of derived class of Object override obj->draw()
> Scene loading workflow
.load scene file by Scene::loadFromFile
.call initFromDOMElement of respective Object
.parse xml, set parameter value
Ray Ray castingcasting>ray sphere intersection, algebraic approach
.if there is intersection
t, the closest positive solution of quadratic function.
Rd Ro
.otherwise
return background
Store Pt, t, normal, material and calculated texture mapping in parameter hit
P = Ro + t*Rd
(P- Po )∙(P- Po )-r^2=0
Pt
.Po
Call void Viewer::select(int x, int y)
Lighting & ShadowLighting & Shadow
I = Ia ka
Light source
Direct reflection
View point
Ambient Color
Diffuse Color
Specular Color
+ Ipkdcosθ + Ipks (cosα)n
TextureTexture mapping mapping & & Anti-Anti-aliasingaliasing
(x,y,z) (u,v)(0,0) 1
1mapping
u = 1.0 – θ/2π θ = atan2(x,y)
v = 0.5 – α/π α = atan(z/sqrt(x2+y2))
11 11
11 11*Sampling window
(n=2)