Ray Tracing TP OpenGL PHAM Trong Tôn WANG Yuanhang
Scene management and display > Scene display workflow.call Scene::draw() in viewer.Scene::draw() scans through QPtrList 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 casting >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 & Shadow I = I a k a Light source Direct reflection View point Ambient Color Diffuse Color Specular Color + I p k d cosθ+ I p k s (cosα) n
Texture mapping & Anti-aliasing (x,y,z) (u,v) (0,0)1 1 mapping u = 1.0 – θ/2π θ = atan2(x,y) v = 0.5 – α/π α = atan(z/sqrt(x 2 +y 2 ))1111 * Sampling window (n=2)