UniS CS297 Graphics with Java and OpenGL Blending.

Slides:



Advertisements
Similar presentations
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Advertisements

Hank Childs, University of Oregon Nov. 25th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 15: animation, transparency.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
OpenGL Fragment Operations
Graphics Pipeline.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
1. 2 Blending: tells you how to specify a blending function that combines color values from a source and a destination. The final effect is that parts.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
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,
Image Compositing Angel 8.11 Angel: Interactive Computer Graphics5E © Addison-Wesley
CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.
Objectives Introduce OpenGL buffers and read/write Introduce OpenGL buffers and read/write Introduce texture mapping Introduce texture mapping Introduce.
University of New Mexico
Computer Graphics - Class 10
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance.
Basic Rendering Techniques V Recognizing basic rendering techniques.
02/14/02(c) University of Wisconsin 2002, CS 559 Last Time Filtering Image size reduction –Take the pixel you need in the output –Map it to the input –Place.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
9/20/2001CS 638, Fall 2001 Today Finishing Up Reflections More Multi-Pass Algorithms Shadows.
V Obtained from a summer workshop in Guildford County July, 2014
Guilford County Sci Vis V204.01
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Modelling and Simulation Types of Texture Mapping.
UniS CS293 Graphics with Java and OpenGL Textures.
UniS CS297 Graphics with Java and OpenGL Introduction.
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.
CS324e - Elements of Graphics and Visualization Compositing.
Vector vs. Bitmap
UniS CS293 Graphics with Java and OpenGL Introduction.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
Filtering and Color To filter a color image, simply filter each of R,G and B separately Re-scaling and truncating are more difficult to implement: –Adjusting.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Game Programming 06 The Rendering Engine
Real-Time rendering Chapter 4.Visual Appearance 4.4. Aliasing and antialiasing 4.5. Transparency,alpha,and compositing 4.6. Fog 4.7. Gamma correction
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CHAPTER 8 Color and Texture Mapping © 2008 Cengage Learning EMEA.
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
Particle Systems (Motion Machines of 2D Objects with Textures) Matthew K. Bowles Advanced Computer Graphics Spring 2004.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Compositing and Blending
Computer Graphics Blending CO2409 Computer Graphics Week 14.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
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.
CISC 110 Day 3 Introduction to Computer Graphics.
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.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Compositing and Blending Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Computer Graphics I, Fall 2008 Compositing and Blending.
Chapter 6. Blending, Antialiasing, Fog, and Polygon Offset Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Week 7 - Monday CS361.
© University of Wisconsin, CS559 Spring 2004
Draw a Simple Object.
Introduction to Computer Graphics with WebGL
Visual Appearance Chapter 4
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
Making the Applications Interesting
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
© University of Wisconsin, CS559 Spring 2004
blending blending textures reflection fog
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Chapter X Output Merger.
CS297 Graphics with Java and OpenGL
blending blending textures reflection fog
Presentation transcript:

UniS CS297 Graphics with Java and OpenGL Blending

UniS 2 The Redbook Material from the Redbook is extensively used throughout these slides. Code has been translated from C++ to JOGL based on example from the book

UniS 3 Overview Blend colours to achieve such effects as making objects appear translucent. Smooth jagged edges of lines and polygons with antialiasing Create scenes with realistic atmospheric effects, fog

UniS 4 Blending Alpha values are specified with glColor*(), when using glClearColor() to specify a clearing colour and when specifying certain lighting parameters such as a material property or light-source intensity. Pixels on screen emit red, green, and blue light, which is controlled by the red, green, and blue colour values. When blending is enabled, the alpha value can be used to combine the colour value of the fragment being processed with that of the pixel already stored in the framebuffer. Blending occurs after scene has been rasterized and converted to fragments, but just before final pixels are drawn in the framebuffer.

UniS 5 Blending Without blending, each new fragment overwrites any existing colour values in the framebuffer, as though the fragment were opaque. With blending, can control how (and how much of) existing colour value should be combined with the new fragment's value. Thus you can use alpha blending to create a translucent fragment that lets some of the previously stored colour value "show through." Colour blending lies at the heart of techniques such as transparency, digital compositing, and painting.

UniS 6 Blending Think of the RGB components of a fragment as representing its colour and the alpha component as representing opacity. Transparent or translucent surfaces have lower opacity than opaque ones and, therefore, lower alpha values. For example, if you're viewing an object through green glass, the colour you see is partly green from the glass and partly the colour of the object. The percentage varies depending on the transmission properties of the glass If the glass transmits 80 percent of the light that strikes it (that is, has an opacity of 20 percent), the colour you see is a combination of 20 percent glass colour and 80 percent of the color of the object behind it.

UniS 7 The Source and Destination Factors During blending, colour values of the incoming fragment (the source) are combined with the colour values of the corresponding currently stored pixel (the destination) in a two-stage process. First you specify how to compute source and destination factors. These factors are RGBA quadruplets that are multiplied by each component of the R, G, B, and A values in the source and destination, respectively. Then the corresponding components in the two sets of RGBA quadruplets are added. Let the source and destination blending factors be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da), respectively, and the RGBA values of the source and destination be indicated with a subscript of s or d. The final, blended RGBA values are given by (Rs.Sr+Rd.Dr, Gs.Sg+Gd.Dg, Bs.Sb+Bd.Db, As.Sa+Ad.Da) Each component of this quadruplet is eventually clamped to [0,1].

UniS 8 The Source and Destination Factors You use glBlendFunc() to supply two constants: –one that specifies how the source factor should be computed –one that indicates how the destination factor should be computed. To have blending take effect, you also need to enable it: gl.glEnable(GL.GL_BLEND); note that gl.glBlendFunc(GL. GL_ONE, GL.GL_ZERO) gives the same results as when blending is disabled;

UniS 9 Source and Destination Factors

UniS 10 Source and Destination Factors

UniS 11 Sample Uses of Blending One way to draw a picture composed half of one image and half of another, equally blended, is to set the source factor to GL_ONE and the destination factor to GL_ZERO, and draw the first image. Then set the source factor to GL_SRC_ALPHA and destination factor to GL_ONE_MINUS_SRC_ALPHA, and draw the second image with alpha equal to 0.5. This pair of factors probably represents the most commonly used blending operation. If the picture is supposed to be blended with 0.75 of the first image and 0.25 of the second, draw the first image as before, and draw the second with an alpha of 0.25.

UniS 12 Sample Uses of Blending set the source factor to GL_ONE, destination factor to GL_ZERO draw the first image(s). source factor to GL_SRC_ALPHA,destination factor to GL_ONE_MINUS_SRC_ALPHA, and draw second image with alpha equal to 0.5.

UniS 13 Sample Uses of Blending set the source factor to GL_ONE, destination factor to GL_ZERO draw the first image(s). source factor to GL_SRC_ALPHA,destination factor to GL_ONE_MINUS_SRC_ALPHA, and draw second image with alpha equal to 0.75.

UniS 14 Sample Uses of Blending set the source factor to GL_ONE, destination factor to GL_ZERO draw the first image(s). source factor to GL_SRC_ALPHA,destination factor to GL_ONE_MINUS_SRC_ALPHA, and draw second image with alpha equal to 0.9.

UniS 15 alpha = 0.5 alpha = 0.75 alpha = 0.9

UniS 16 Sample Uses of Blending Destination factor to GL_ONE and the source factor to GL_SRC_ALPHA. Draw each of the three images with an alpha equal to

UniS 17 Sample Uses of Blending The blending functions that use source factor –GL_DST_COLOR –GL_ONE_MINUS_DST_COLOR destination factor –GL_SRC_COLOR –GL_ONE_MINUS_SRC_COLOR Allow you to modulate each colour component individually. Equivalent to applying a filter For example multiplying –red component by 80 percent, –green component by 40 percent, –blue component by 72 percent would simulate viewing the scene through a photographic filter that blocks 20 percent of red light, 60 percent of green, and 28 percent of blue.

UniS 18 Sample Uses of Blending Consider, picture composed of three translucent surfaces, some obscuring others, and all over a solid background. Assume the farthest surface transmits 80 percent of the color behind it, the next transmits 40 percent, and the closest transmits 90 percent. Draw the background first with the default source and destination factors Then change the blending factors to GL_SRC_ALPHA (source) and GL_ONE_MINUS_SRC_ALPHA (destination). Next, draw the farthest surface with an alpha of 0.2, then the middle surface with an alpha of 0.6, and finally the closest surface with an alpha of 0.1.

UniS 19 Solid alpha = 0.2 alpha = 0.6 alpha = 0.1

UniS 20 Antialiasing; jaggies Lines, especially nearly horizontal or nearly vertical ones, can appear jagged. These jaggies appear because the ideal line is approximated by a series of pixels that must lie on the pixel grid. The jaggedness is called aliasing,

UniS 21 Antialiasing; jaggies Alpha value for a square overlapped by geometric line is given by percentage of square covered by line

UniS 22 Antialiasing Points or Lines Enable with –gl.glEnable(GL.GL_POINT_SMOOTH) –gl.glEnable(GL.GL_LINE_SMOOTH) Then enable blending, common setting is gl.glBlendFunc ( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); For further details see Chapter 6 of the Redbook

UniS 23 Fog Computer images sometimes seem unrealistically sharp and well defined. Antialiasing makes an object appear more realistic by smoothing its edges. Additionally, you can make an entire image appear more natural by adding fog, which makes objects fade into the distance. Fog is a general term that describes similar forms of atmospheric effects. It can be used to simulate haze, mist, smoke, or pollution.

UniS 24 Fog When fog is enabled, objects that are farther from the viewpoint begin to fade into the fog color. You can control the density of the fog. That determines the rate at which objects fade as the distance increases, as well as the fog's color. Fog is applied after matrix transformations, lighting, and texturing are performed, hence it affects transformed, lit, and textured objects.

UniS 25 Fog gl.glEnable(GL.GL_FOG); FloatBuffer fogColor = FloatBuffer.wrap( new float[ ]{0.0f,0.0f,0.0f,0.0f} ); gl.glFogi(GL.GL_FOG_MODE,GL.GL_EXP); gl.glFogfv(GL.GL_FOG_COLOR, fogColor); gl.glFogf(GL.GL_FOG_DENSITY, f); gl.glHint(GL.GL_FOG_HINT, GL.GL_NICEST);

UniS 26 Fog Fog blends a fog color with an incoming fragment's color using a fog blending factor f. This factor, f, is computed with one of the three equations on the next slide and then clamped to the range [0,1]. Let z be the eye-coordinate distance between the viewpoint and the fragment center. Let density be the value set with the command gl.glFogf(GL.GL_FOG_DENSITY, f); Let C i be the current colour of the fragements RGBA Let C f be colour assigned with gl.glFogfv(GL.GL_FOG_COLOR, fogColor); Then the fog colour C is defined as follows:

UniS 27 Fog