CS代考计算机代写 algorithm Computer Graphics CSI4130 – Winter 2019

Computer Graphics CSI4130 – Winter 2019
Jochen Lang
EECS, University of Ottawa Canada

This Lecture
• Hidden Surface Removal – Z-buffer
– Perspectivecorrecttexturemapping
• Graphics Pipeline
– Graphicspipeline – Clipping
CSI4130 Computer Graphics

Z-Buffer Algorithm
– Image plane solution • Key observation:
– Only need to decide what object to draw for every pixel in the final image – global depth order is not needed.
void setPixel( int i, int j, int rgb, float z)
{
if z is rasterized in screen space with but texture is in world space
– Need 􏰝 􏰝 for texture interpolation
• The following gives the correct result along each edge
– and is therefore correct everywhere
CSI4130 Computer Graphics

A Hardware Approach
• The previous approach works but is expensive to calculate
– There is a much simpler approach
– Consider a sloped triangle after projection and map the z- coordinate after projection
– Observation: The projected depth is what we need
34…
CSI4130 Computer Graphics

Hardware Approach
• Send texture coordinates through the rasterizer – just as vertex coordinates
– For vertex coordinates, we have – For texture coordinates, we have
are world space 2D texture coordinates
are image space 2D texture coordinate • the “homogeneous” coordinate is
– To get the world space textures
interpolation
This is the default “smooth” interpolation
CSI4130 Computer Graphics
• we need to calculate
• Rasterizer must simply do the same perspective correct
𝒔􏰞 𝒕􏰞
𝒉􏰟 𝒉􏰟

Explicit Perspective Correct Texturing: Vertex Shader
• Vertex shader
– use one extra dimension in the texture coordinate – project the texture coordinate (just like positions)
#version 330 core
in vec2 texCoord;
in vec4 position;
noperspective out vec3 texCoordFrag;
uniform mat4 MVP;
…void main() {
gl_Position = MVP * position;
texCoordFrag = vec3(texCoord,gl_Position.w ); …}
CSI4130 Computer Graphics

Explicit Perspective Correct Texturing: Fragment Shader
– Use the homogeneous component – Special sampler exists
#version 330 core
noperspective in vec3 texCoordFrag;
uniform sampler2D tex;
out vec4 color;
…void main() {
color = textureProj(tex, texCoordFrag);
// Same as:
// vec2 uv = texCoordFrag.st/textCoordFrag.p;
// color = texture(tex,uv);
…}
CSI4130 Computer Graphics

Old-Style OpenGL 1.1 Fixed Pipeline
Geometry
Geometry Processing (Per-vertex operation)
Lighting
Per-fragment operation
Texturing Depth Test Blending
Modelview Transformation
Perspective Transformation
Scan Conversion
Rasterization
Frame- buffer
Textures
CSI4130 Computer Graphics
Clipping and Viewport Transformation

Overview of Modern OpenGL
Geometry Vertex Shader
Geometry Processing (Per-vertex operation)
Geometry Shader Clipping
Rasterization
Tesselllation Control and Evaluation Shader
Scan Conversion
Fragment Shader
Fragment test, framebuffer blending and logic, write masking
Per-fragment operation
Textures
CSI4130 Computer Graphics
Frame- buffer

Full OpenGL 4.5 Pipeline
CSI4130 Computer Graphics
© Khronos Group

Vertex Shader Output to Rasterization
© Khronos Group
CSI4130 Computer Graphics

Misc. Graphics Pipeline Topics
• Culling
– Geometric primitives completely outside of the viewing
volume are not rasterized • Back-face elimination
– The back of polygons in models which are closed are never visible, i.e., they need not be drawn.
• Tessellation
– Breaking up higher order primitives into triangles, lines etc.
• Building triangle strips and fans
– Reduce the number of vertices required to define a mesh
CSI4130 Computer Graphics

Triangle Clipping
– Some triangles will pierce the bounding planes of the viewing frustum
• Scenario: t
l
f
right plane r
{vA,v1,vB}; {v0,vB,v2}; {v0,vA,vB}
T
n
T
b
CSI4130 Computer Graphics

Finding the new Vertices on the Line of Intersection
• Implicit plane equation:
• Find plane equation (T1) based on vertices
• Parametric line equation (edge ):
􏰠 can be found similarly.

Clipping Implementation
• Efficient hardware implementation
– avoids float division or multiplication
• Characterization
– 2D vs. 3D clipping
– line segements vs. polygons – Algorithm
• Line clipping
– Cohen-Sutherland [1963] – Liang-Barsky [1984]
• Polygon clipping
– Sutherland-Hodgman [1974]
http://www.siggraph.org/education/materials/HyperGraph/scanline/clipping/lbth.htm CSI4130 Computer Graphics

Next Lecture
• Introduction to Splines – Introduction
– Bézier curves
• Subdivision
• Bernstein-Bézier formula
• De Casteljau algorithm – Splines
• Canonical form, constraint and basis matrix • Catmull-Rom splines
CSI4130 Computer Graphics

Leave a Reply

Your email address will not be published. Required fields are marked *