OpenGL Fragment Operations

Slides:



Advertisements
Similar presentations
Presented by: Stacy C. Lovell. How do we perceive color? Our eyes contain only 3 types of photosentitive cells tuned to three frequencies Red, Green,
Advertisements

Lecture 8 Transparency, Mirroring
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
The Buffers and Operations
OpenGL Buffers and Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday, February 8, 2002.
Introduction to OpenGL (Part 4)
Framebuffer in OpenGL MAE152 Computer Graphics for Scientists and Engineers Fall 03.
More HSR, OpenGL Buffers & Tests Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 2, 2004.
Graphics Pipeline.
1 Buffers and Processing Fragments 2011 Autumn Animação e Visualização Tridimensional 2011/2012.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
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.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Chapter 6. More on Color and Material Presented by Garrett Yeh.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
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.
Computer Graphics Mirror and Shadows
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
CS 638, Fall 2001 Today Light Mapping (Continued) Bump Mapping with Multi-Texturing Multi-Pass Rendering.
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
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.
Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.
1 10/24/ :01 UML Graphics II Shadows Session 4.
Multi-pass Rendering. © 2002 James K. Hahn, N.H. Baek2 Multi-pass Rendering Repeat: image  Rendering pass  result imageRepeat: image  Rendering pass.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
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.
UniS CS297 Graphics with Java and OpenGL Blending.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Visible Surface Detection
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.
Accumulation-Based Effects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, February 4, 2004.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
The Framebuffer Hyun-Chul Cho. HyunChul Cho - KUCG -2 Buffer Goal of a graphics program Draw pictures on the screen Screen Rectangular array.
Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
Chapter 6. Blending, Antialiasing, Fog, and Polygon Offset Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Stenciling Effects Glenn G. Chappell
Week 7 - Monday CS361.
Draw a Simple Object.
Introduction to Computer Graphics with WebGL
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
OpenGL Buffers and Tests
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Making the Applications Interesting
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Geb Thomas Adapted from the OpenGL Programming Guide
Computer Graphics Buffers
Blending CSCI 440 textbook section 7.10
Computer Graphics Practical Lesson 7
Chapter X Output Merger.
Ref: OpenGL Programming Guide (The Red Book)
Stencil Buffer & Decals
Presentation transcript:

OpenGL Fragment Operations Rasterization Scissor Test Fragment Data (Position, Color, Depth) Alpha Test Frame Buffer Texture Mapping Stencil Test Color Buffer Fog Depth Test Depth Buffer Antialiasing Blending Stencil Buffer Dithering Logical Operations Buffer Masking

Scissor Test Alpha Test void glScissor(GLint x, GLint y, GLsizei width, GLsizei height) Define a scissor rectangle (scissor box) in window coordinates. Fragment that lies inside the scissor rectangle passes the scissor test. x, y: Lower left corner of the scissor rectangle width, height: Width and height of the scissor rectangle Use glEnable(GL_SCISSOR_TEST) to enable scissor test. Use glDisable(GL_SCISSOR_TEST) to disable scissor test. Alpha Test void glAlphaFunc(GLenum func, GLclampf ref) Define alpha test function func (default is GL_ALWAYS) and reference value ref (default is 0.0).

func Meaning GL_NEVER Always fail GL_ALWAYS Always pass GL_LESS Pass if fragment alpha < ref GL_LEQUAL Pass if fragment alpha  ref GL_EQUAL Pass if fragment alpha = ref GL_GEQUAL Pass if fragment alpha  ref GL_GREATER Pass if fragment alpha > ref GL_NOTEQUAL Pass if fragment alpha  ref Use glEnable(GL_ALPHA_TEST) to enable alpha test. Use glDisable(GL_ALPHA_TEST) to disable alpha test.

Stencil Test void glStencilFunc(GLenum func, GLint ref, GLuint mask) Define stencil test function func (default is GL_ALWAYS), reference value ref (default is 0) and a mask value mask (default is all 1s). func: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL Stencil test procedure: Retrieve stencil value s from stencil buffer at fragment position. Mask reference value and stencil value using bitwise AND operation: ref0 = ref & mask; s0 = s & mask; Compare ref0 and s0, if they satisfy the inequality defined by func, then the fragment passes the stencil test, otherwise it fails. Use glEnable(GL_STENCIL_TEST) to enable stencil test. Use glDisable(GL_STENCIL_TEST) to disable stencil test.

void glStencilOp(GLenum fail, GLenum zfail, GLenum zpass) Define actions to take on stencil buffer values. fail: Action to take when the fragment fails stencil test. zfail: Action to take when the fragment passes stencil test but fails depth test. zpass: Action to take when the fragment passes stencil test and also passes depth test. fail, zfail, zpass value Meaning GL_KEEP Keep current value. GL_ZERO Replace with zero. GL_REPLACE Replace with reference value defined by glStencilFunc(). GL_INCR Increment by one. Clamp to maximum value. GL_DECR Decrement by one. Clamp to 0. GL_INVERT Bitwise invert.

Depth Test void glDepthFunc(GLenum func) Define depth test function func (default is GL_LESS). func: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL Compare fragment depth value with the depth value stored in the depth buffer. If they satisfy the inequality defined by func, then the fragment passes the depth test, otherwise it fails. Use glEnable(GL_DEPTH_TEST) to enable depth test. Use glDisable(GL_DEPTH_TEST) to disable depth test.

OpenGL Blending Operations Blending combines the color value of the incoming fragment with the color value of the corresponding pixel already stored in the frame buffer. Color with Alpha Value (R, G, B, A) R: Red component G: Green component B: Blue component A: Alpha component (transparency) Each component value is between 0.0 and 1.0

Source and Destination Blending Factors Source: Incoming fragment Destination: Pixel already stored in the color buffer Source color: (Rs, Gs, Bs, As) Source blending factor: (Sr, Sg, Sb, Sa) Destination color: (Rd, Gd, Bd, Ad) Destination blending factor: (Dr, Dg, Db, Da) The final blended color is: (RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa) Each component is clamped to [0.0, 1.0] void glBlendFunc(GLenum srcfactor, GLenum dstfactor) Define source and destination blending factors srcfactor: Define source blending factor dstfactor: Define destination blending factor

srcfactor, dstfactor RGB blending factors Alpha blending factor GL_ZERO (0, 0, 0) GL_ONE (1, 1, 1) 1 GL_SRC_COLOR (Rs, Gs, Bs) As GL_ONE_MINUS_SRC_COLOR (1Rs, 1Gs, 1Bs) 1As GL_DST_COLOR (Rd, Gd, Bd) Ad GL_ONE_MINUS_DST_COLOR (1Rd, 1Gd, 1Bd) 1Ad GL_SRC_ALPHA (As, As, As) GL_ONE_MINUS_SRC_ALPHA (1As, 1As, 1As) GL_DST_ALPHA (Ad, Ad, Ad) GL_ONE_MINUS_DST_ALPHA (1Ad, 1Ad, 1Ad) GL_SRC_ALPHA_SATURATE (f, f, f) f = min (As, 1Ad). GL_SRC_ALPHA_SATURATE can only used as source blending factor.

Use glEnable(GL_BLEND) to enable blending. Use glDisable(GL_BLEND) to disable blending. To create color buffer with alpha channel, use: glutInitDisplayMode (GLUT_RGB | GLUT_ALPHA ……); Draw Multiple Transparent and Opaque Objects glDepthMask(GL_TRUE); glDisable(GL_BLEND); Draw all opaque objects; glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Sort transparent objects from back to front; Draw transparent objects in back to front order;

OpenGL Antialiasing Operations Super Sample Antialiasing Multi Sample Antialiasing

Steps to Use Antialiasing in OpenGL When performing antialiasing, OpenGL calculates a coverage value for each fragment. The coverage value is the percentage of a fragment’s area that overlaps with the primitive being drawn. The fragment’s alpha value is then multiplied by its coverage value. Steps to Use Antialiasing in OpenGL Enable antialiasing. Give hint on antialiasing quality. Enable blending and choose appropriate blending factors. Draw primitives.

Enable Antialasing Enable antialiasing for points: glEnable(GL_POINT_SMOOTH) Enable antialiasing for lines: glEnable(GL_LINE_SMOOTH) Enable antialiasing for polygons: glEnable(GL_POLYGON_SMOOTH)

Give Hint on Antialiasing Quality void glHint(GLenum target, GLenum hint) target Meaning GL_POINT_SMOOTH_HINT Hint for point antialiasing GL_LINE_SMOOTH_HINT Hint for line antialiasing GL_POLYGON_SMOOTH_HINT Hint for polygon antialiasing hint Meaning GL_FASTEST Most efficient implementation GL_NICEST Highest image quality GL_DONT_CARE No preference

Set Blending Factors To antialiasing points and lines, use glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Then render points or lines in arbitrary order. To antialiasing polygons, use glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE) ; Then render the polygons in front to back order.

OpenGL Fog Effect void glFog{if}(GLenum pname, TYPE param) void glFog{if}v(GLenum pname, TYPE *param) Set fog mode and parameters. pname param Meaning GL_FOG_MODE GL_EXP (default) GL_EXP2 GL_LINEAR Fog mode GL_FOG_COLOR Cf = (Rf, Gf, Bf, Af) Fog color GL_FOG_DENSITY  Fog density GL_FOG_START zmin Fog start distance GL_FOG_END zmax Fog end distance

Fog Factor GL_EXP GL_EXP2 GL_LINEAR z is the eye-coordinate distance between view point and the fragment to be fogged. Final Fogged Color C = f Ci + (1 – f) Cf Ci: Incoming fragment color Cf: Fog color

Fog Hint void glHint(GLenum target, GLenum hint) target: GL_FOG_HINT hint: GL_NICEST Per-pixel fog calculation GL_FASTEST Per-vertex fog calculation GL_DONT_CARE No preference Use glEnable(GL_FOG) to enable fog. Use glDisable(GL_FOG) to disable fog.

Dithering Dithering operation is hardware-dependent. All OpenGL allows you to do is to turn it on and off. Use glEnable(GL_DITHER) to enable dithering. Use glDisable(GL_DITHER) to disable dithering.

Logical Operations void glLogicOp(GLenum opcode) Result GL_CLEAR GL_XOR s ^ d GL_SET 1 GL_EQUIV ~(s ^ d) GL_COPY s GL_COPY_INVERTED ~s GL_NOOP d GL_INVERT ~d GL_AND s & d GL_AND_REVERSE s & (~d) GL_NAND ~(s & d) GL_OR_REVERSE s | (~d) GL_OR s | d GL_AND_INVERTED (~s) & d GL_NOR ~(s | d) GL_OR_INVERTED (~s) | d s: Incoming fragment value (Source) d: Value of the pixel in the color buffer (Destination) &: Bitwise AND |: Bitwise OR ^: Bitwise XOR ~: Bitwise NOT

In RGBA color mode Use glEnable(GL_COLOR_LOGIC_OP) to enable logical operations. Use glDisable(GL_COLOR_LOGIC_OP) to disable logical operations. In color index mode Use glEnable(GL_INDEX_LOGIC_OP) to enable logical operations. Use glDisable(GL_INDEX_LOGIC_OP) to disable logical operations.

Frame Buffer Clearing and Masking void glClear (GLbitfield mask) Clear the frame buffer. mask: GL_COLOR_BUFFER_BIT color buffer GL_DEPTH_BUFFER_BIT depth buffer GL_STENCIL_BUFFER_BIT stencil buffer void glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) Set clear value for color buffer void glClearDepth( GLclampd depth ) Set clear value for depth buffer void glClearStencil( GLint s ) Set clear value for stencil buffer

void glColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) Set writing masks for color buffer. r, g, b, a: Writing masks for red, green, blue and alpha channel. GL_TRUE: channel can be written (default value). GL_FALSE: channel can not be written. void glDepthMask(GLboolean flag) Set writing mask for depth buffer. flag: GL_TRUE: Depth buffer can be written (default value). GL_FALSE: Depth buffer can not be written. (But can still be read.) void glStencilMask(GLuint mask) Set writing mask for stencil buffer. mask: Binary writing mask. “1” indicates the corresponding bit in stencil buffer can be written, “0” indicates the bit can not be written.