CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.

Slides:



Advertisements
Similar presentations
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
Advertisements

8.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 8 Polygon Rendering.
COMPUTER GRAPHICS SOFTWARE.
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
O a polygon is a plane figure specified by a set of three or more coordinate positions, called vertices, that are connected in sequence by straight-Line.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
OpenGL Fragment Operations
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
University of Sulaimani - School of Science - Computer Dept.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
CAP4730: Computational Structures in Computer Graphics Visible Surface Determination.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
CS 4731: Computer Graphics Lecture 18: Hidden Surface Removal Emmanuel Agu.
CGDD 4003 THE MASSIVE FIELD OF COMPUTER GRAPHICS.
1 Lecture 5 Rendering 3D graphical primitives. 2 3D Rendering Example:
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
CSE 381 – Advanced Game Programming Basic 3D Graphics
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Hidden Surface Removal 1.  Suppose that we have the polyhedron which has 3 totally visible surfaces, 4 totally invisible/hidden surfaces, and 1 partially.
1Computer Graphics Implementation II Lecture 16 John Shearer Culture Lab – space 2
Binary Space Partitioning Trees Ray Casting Depth Buffering
Implementation II.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Computer Graphics Blending CO2409 Computer Graphics Week 14.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Computer Graphics I, Fall 2010 Implementation II.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
The Graphics Pipeline Revisited Real Time Rendering Instructor: David Luebke.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Introduction to Computer Graphics
CS 4722 Made by Dr. Jeffrey Chastine Modified by Dr. Chao Mei
Visible Surface Detection
- Introduction - Graphics Pipeline
Computer Graphics Implementation II
Week 7 - Monday CS361.
Draw a Simple Object.
Week 2 - Friday CS361.
The Graphic PipeLine
Deferred Lighting.
The Graphics Rendering Pipeline
Day 05 Shader Basics.
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
UMBC Graphics for Games
Lecture 13 Clipping & Scan Conversion
Visibility (hidden surface removal)
Chapter X Output Merger.
Introduction to OpenGL
Frame Buffer Applications
Presentation transcript:

CS 4363/6353 BASIC RENDERING

THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive Assembly Assemble sets of vertices into lines and polygons Clipping volume culls out geometry outside, and clips geo that straddles Rasterization Determine which pixels are inside each polygon (primitive) The output is a set of fragments for each primitive Fragment Processing Fills in the pixels in the frame buffer (what you’re seeing right now!)

SHADERS (FROM 100,000 FEET. WELL, MAYBE 10,000 FEET) Shaders: Expose the programmable pipeline ! Allow us to manipulate vertices and pixel colors Look very similar to C void main() Must be compiled and linked from source Generally have two shaders: Vertex shader (to handle vertex transformations and lighting) Fragment shaders (to handle per-pixel operations like lighting to determine color) Hundreds (or thousands) of GPUs are available

SHADERS AND PASSING DATA Must feed shaders some data! Three ways to pass. Attributes (vertex shaders only): data that changes per vertex A four component vector (regardless if you use it or not) Copied from your OpenGL program into a buffer Uniforms (vertex/fragment shaders): A single value that is shared for all attributes Common for transformation matrices (vertex shader) Texture (mostly fragment shaders): Used for texture data

SIMPLE VERTEX EXAMPLE #version 150 in vec4 vPosition; // This data is from your OpenGL code void main () { gl_Position = vPosition; }

SIMPLE FRAGMENT SHADER #version 150 out vec4 fColor; void main () { fColor = vec4(1.0, 0.0, 0.0, 1.0); } // Hard-coded red!

SHADERS AND PASSING DATA outs/ins Used for passing data between shaders Client (OpenGL code) has no access to these variables Vertex shader’s out variable corresponds to the fragment shader’s in variable.

RENDERING OPTIONS We typically create a single batch of vertices to draw We generally set up all “features” before drawing anything State machine mentality We always have vertices, but we can render them in 7 different ways GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES** GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

RENDERING OPTIONS ( GL_POINTS ) Can change the point sizes, but not important right now Points are always square unless anti-aliased

RENDERING OPTIONS ( GL_LINES ) Connects in pairs (line segments), so should have an even number of points Change line width with glLineWidth (GLfloat width);

RENDERING OPTIONS ( GL_LINE_STRIP ) In a connect-the-dots fashion, draw from one vertex to another How would you do this with GL_LINES ?

RENDERING OPTIONS ( GL_LINE_LOOP ) Closes the loop Is typically what you would use for outlines/tracing

RENDERING OPTIONS ( OTHERS ) Some of these are allowed…

RENDERING OPTIONS ( OTHERS ) Some of these aren’t… NO QUADS! Triangles only…

TRIANGLE WINDING Simply means the order of the vertices you specify Clockwise Counter-Clockwise Why is this important? Clockwise is back facing Counter-clockwise is front facing Long story short: If you specify in reverse order, sometimes you won’t see anything or it will be reversed Can reverse using glFrontFace (GL_CW); V0V0 V1V1 V2V2 V0V0 V2V2 V1V1

TRIANGLE STRIPS Specify the first triangle (V 0, V 1, V 2 ) V0V0 V1V1 V2V2

TRIANGLE STRIPS Specify the first triangle (V 0, V 1, V 2 ) The next vertex (V 3 ) creates a new triangle (V 1, V 2, V 3 ) V0V0 V1V1 V2V2 V3V3

TRIANGLE STRIPS Specify the first triangle (V 0, V 1, V 2 ) The next vertex (V 3 ) creates a new triangle (V 1, V 2, V 3 ) The next vertex (V 4 ) creates a new triangle (V 2, V 3, V 4 ) V0V0 V1V1 V2V2 V3V3 V4V4

EXAMPLE From Wikipedia…

TRIANGLE FANS Can create a fan where V 0 is the central vertex Specify first triangle, then each new vertex is a wedge of the fan V0V0 V1V1 V2V2

TRIANGLE FANS Can create a fan where V 0 is the central vertex Specify first triangle, then each new vertex is a wedge of the fan Still uses V 0 V0V0 V1V1 V2V2 V3V3

TRIANGLE FANS Can create a fan where V 0 is the central vertex Specify first triangle, then each new vertex is a wedge of the fan Still uses V 0 V0V0 V1V1 V2V2 V3V3 V4V4

EXAMPLE OF TRIANGLE FAN

CULLING AND DEPTH TESTING You’re going to be drawing a lot of triangles What happens if you draw one triangle on top of another? What if the second triangle is far away? Sort triangles of an object (painter’s algorithm)? What about several objects on the screen? Also, should you be able to see the inside of geometry? Basically, there are two problems: Unseen triangles are unlit The depth of the triangles is important

HOUSTON, WE HAVE A PROBLEM (IMAGE FROM OPENGL SUPERBIBLE) Sometimes rendering the far-side triangles (which are unlit)

BACKFACE CULLING Simply means “Don’t draw triangles that don’t face the camera” Two steps in OpenGL glEnable (GL_CULL_FACE); glCullFace (GL_BACK); glCullFace could also use: GL_FRONT GL_FRONT_AND_BACK

CULLING THE BACKFACE(S) Problem solved?

BUT WAIT! (IMAGES FROM OPENGL SUPERBIBLE)

DEPTH TESTING Just because we culled the back-facing triangles doesn’t mean they’re sorted! Depth testing: Removes hidden surfaces Each pixel has a depth (z-value) Higher values mean closer to the camera This value is stored in the depth buffer glEnable (GL_DEPTH_TEST); Is this starting to make sense? glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);

POLYGON RENDERING MODES Polygons do not have to be filled We have 3 modes to draw polygons: GL_FILL – what we’ve been using GL_LINE – 3D wireframe GL_POINT – just the vertices Call glPolygonMode() to change rendering value: // renders front and back facing polys in wireframe glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);

GL_LINE Backface culling and depth testing are turned on

A NOTE ABOUT POLYGON OFFSET You can skip it Sometimes draw two triangle very close to the same depth (called decaling) This creates “z-fighting” Part of the further polygon shows Before rendering closer triangle: glEnable (GL_POLYGON_OFFSET_LINE); glPolygonOffset(-1.0f, -1.0f);

SCISSOR TEST We won’t be using this in our code, but: Used to increase performance Updates only the portion within a defined area (i.e. doesn’t update anything outside of that area) By default, scissor test is the size of the window Use glScissor (int x, int y, int width, int height) : glEnable (GL_SCISSOR_TEST); glScissor (100, 100, 600, 400); // only render in that area

BLENDING Without depth testing, color values overwrite one another With depth testing, new fragments may replace old ones Discards further fragments This no longer happens with OpenGL blending: glEnable (GL_BLENDING); Remember, each color has a red, green, blue and alpha!

SPECIFYING HOW TO BLEND We must specify how the blending occurs Destination color is the color already in the color buffer Source color is the one we’re about to write into the color buffer C f = (C s * S) + (C d * D) Where: C f is the final color, C s is the source color and C d is the destination color S is the source blending factor D is the destination blending factor

MOST COMMON METHOD glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Take source and multiply rgb (colors) by its alpha value Take destination and multiply rgb by (1-source alpha) Example: C d = (1.0f, 0.0f, 0.0f, 1.0f) //Red C s = (0.0f, 0.0f, 1.0f, 0.6f) // Blue, with source alpha 0.6 D = 1.0f – 0.6 == 0.4f C f = (Blue*0.6) + (Red*0.4)

EXAMPLE

ONE FINAL NOTE We can change the underlying equation as well using glBlendEquation(): GL_FUNC_ADD C f = (C s *S)+(C d *D) GL_FUNC_SUBTRACT C f = (C s *S)-(C d *D) GL_FUNC_REVERSE_SUBTRACT C f = (C d *D) - (C s *S) GL_MIN C f = min(C s,C d ) GL_MAX C f = max(C s,C d )

ANTIALIASING We have square pixels, which make the image look computer-generated The visual aspect of this is called “the jaggies” To eliminate, OpenGL uses blending of source with surrounding destination pixels So: glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Then: glEnable (GL_POINT_SMOOTH); // and/or glEnable (GL_LINE_SMOOTH); // and/or glEnable (GL_POYGON_SMOOTH);// ** // ** outdated or not supported at all!

EXAMPLE

MULTISAMPLING Helps to smooth out polygons Creates another buffer (color, depth and stencil) All primitives are sampled multiple times, then “averaged” You take a performance hit here, but looks good! Point/Line antialiasing is disable when multisampling is enabled First: glutInitDisplayMode (GLUT_DOUBLE| GLUT_RGB| GLUT_DEPTH| GLUT_MULTISAMPLE); Then: glEnable (GL_MULTISAMPLE);