CP2060 - Lecture 23 - Ray Tracing & OpenGL Blending

 

Ray Tracing

Notes on ray tracing...

Ray Tracing is a more time-consuming, but more accurate method of rendering scenes, that doesn't require that objects be built out of polygons. So a sphere can actually be 'modelled' and rendered as a sphere, not just a bunch of triangles approximating a sphere.

The ray tracing process also solves the hidden surface removal problem automatically, without it needing to perform an extra step.

OpenGL - Blending

Chapter 10.3 (pages 543 - 549).

Blending allows you to draw a partially transparent image over another image. This is done by adding a fourth component to colour values, an alpha value. The alpha value specifies the opacity of the pixel/object to be drawn, with 0 being completely transparent, and 1 being completely opaque.

A weighted average is then found of the source and destination pixels where D = aS + (1-a)D. a = alpha, D = Destination, S = Source. (The source is the "incoming primitive" and the destination is that which is already in the frame buffer. The alpha value can be varied for different pixels.

To use blending in OpenGL, you need to do three things:

  • Enable blending - glEnable(GL_BLEND);
  • Set a blend mode - glBlendFunc(sourcefactor, destfactor);
  • Set alpha values in the colour specifications for objects you want to make semi-transparent - glColor4f(r,g,b,a);

For the blend mode, you define the source and destination scaling factors. The most common (and useful) is perhaps to use:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This sets OpenGL to do blending based on the function above - D = aS + (1-a)D.
Look up the glBlendFunc() in the OpenGL help files for more options.

 

 

 

 Announcements

Lecture notes are provided as a guide of the content of lectures for pre-reading, revision and for students who cannot attend lectures. While almost every effort is made to make the online notes as complete as possible, there is always material discussed in lectures that is not in the notes.
You should not rely on these notes only!
If you miss a lecture and you do not understand something in the notes, you should consult (in this order) other students, the tutors, or the lecturer to try to work it out.

You are expected to read these lecture notes as well as attending lectures, as vital information is contained in both.

 

 Subject Coordinator: Lindsay {w} | {e}.

Last Update: October 23, 2001