Download BSP Trees & Rendering: Back-to-Front & Barycentric Techniques - Prof. Juraj Obert and more Exams Computer Graphics in PDF only on Docsity!
Juraj Obert
http://graphics.cs.ucf.edu/cap4720/fall2008/
BSP trees revisited
BSP – Binary Space Partitioning
A
B C
BSP construction
p
p
p
p
p
p4 p
p
BSP construction cont.
BuildTree(tree, polygonList)
if (polygonList.count <= 1)
tree.polygons = polygonList[0];
return tree;
tree.splitter = chooseSplitter(polygonList);
foreach polygon P1 in polygonList do classifyPolygon(P1, splitter)
case FRONT: frontList.add(P1);
case BACK: backList.add(P1);
case COINCIDENT: tree.polygons.add(P1);
case SPANNING: splitPolygons(P1, splitter, P1front, P1back);
frontList.add(P1front);
backList.add(P1back);
BuildTree(tree.front, frontList);
BuildTree(tree.back, backList);
Painter’s algorithm
Painter’s Algorithm cont.
How to sort polygons back-to-front?
Easy in 2D space
Easy in 3D space if polygons are coplanar
Not easy if polygons aren’t coplanar
Difficult if their planes interest
BSP trees can help us
BSP rendering
p
p
p
p
p
p
BSP rendering algorithm
DrawTree(tree, eye) classifyPosition(tree.splitter, eye); case FRONT: DrawTree(tree.back); DrawPolygon(tree.polygons); DrawTree(tree.front); case BACK: DrawTree(tree.front); DrawPolygon(tree.polygons); DrawTree(tree.back); case COINCIDENT: DrawTree(tree.front); DrawTree(tree.back);
Z/Depth buffer revisited
Same resolution as color buffer
z values from [ 0.0f, 1.0f ]
z-test
Compare z-value of a pixel already on the screen (zold) and
z-value of a fragment just computed in a fragment shader
(znew)
Pass (znew < zold): new fragment overwrites old pixel
Fail (znew > zold): new fragment is rejected
In OpenGL:
glEnable
glDepthFunc
Example
Z-buffer for a simple scene
Shaders
Short programs executed on processing units
inside a GPU
Vertex/pixel shader units (e.g. 4/16 for GeForce 6800)
Unified design (e.g. 128 for GeForce 8800 Ultra)
Variety of shading languages
GLSL (OpenGL Shading Language)
HLSL (High Level Shading Language)
Cg (C for Graphics)
Focus now on fragment shaders
Applications of fragment shaders
Graphics:
Lighting computations
Texturing
Shadows
Color correction
Tone mapping
Image processing
GPGPU:
Wavelet transformations
Matrix multiplication
Compression
Vertex shader to fragment shader
“varying” variable type
varying vec4 tri_col;
void main()
tri_col = vec4(…);
Declare and set in vertex shader: (^) Declare and use in frag shader:
varying vec4 tri_col;
void main()
Vertex shader to fragment shader
How does the GPU compute value of tri_color for fragment P?
vertex B
tri_color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
fragment P
vertex C
tri_color = vec4(0.0f, 0.0f, 1.0f, 1.0f);
vertex A
tri_color = vec4(0.0f, 1.0f, 0.0f, 1.0f);
Barycentric coordinates
Given point P, what masses would you assign to
triangle vertices to make P the geometric
centroid of the triangle?
fragment P
vertex A barycentric coordinate u
vertex C barycentric coordinate w
vertex B barycentric coordinate v
Barycentric coordinates cont.
u = Area(PCB) / Area(ACB) v = Area(PAC) / Area(ACB) w = 1 – u – v
Computing area of a triangle:
v 1 = C - P v 2 = B - P
Area(PCB) = 0.5 * || v 1 x v 2 ||
P
vertex A barycentric coordinate u
vertex C barycentric coordinate w
vertex B barycentric coordinate v
Normalized barycentric coordinates: u + v + w = 1.
v 2 v 1
Next class
Lighting