dhpoware logo
navbar
home products source demos contact us
navbar navbar
box top left corner box top right corner
 
 
OpenGL 2.0 Shading Language Fragment Lighting Demo.

This Windows demo implements the per-fragment Blinn-Phong lighting model with a series of OpenGL Shading Language (GLSL) shader programs. This demo implements specular highlights using a local viewer lighting model rather than the OpenGL default infinite viewer lighting model. Each of the three light source types - directional, point, and spot - are each implemented as separate GLSL shader programs.

The demo consists of a single textured cube centered at the world origin. The light source is fixed and located directly in front of the cube where the virtual camera is located in the scene. The mouse can be used to rotate the cube and to zoom in and out of the scene. Note that the cube has a very low polygon count to emphasize the fact that realistic per-fragment lighting is independent of the geometry's level of tessellation.

A direct per-fragment implementation of the OpenGL spot light model will produce a very sharp falloff around the spot light's cutoff. This demo uses dual spot light cones: an inner cone, and an outer cone. Using the inner and outer cone convention will produce a more softer falloff around the spot light's cutoff. Fixed function Direct3D uses a similar approach. The spot light shader program that accompanies the demo includes both models: the dual (inner and outer) cones model, and the standard OpenGL model. The dual cones model is enabled by default since it produces a more visually appealing effect.

Note:
1. This is an OpenGL 2.0 demo. This demo will not run on OpenGL 1.x hardware.
2. This demo requires the Visual C++ 2010 Library Runtimes. Download instructions can be found here.

screenshot

zip file Download executable, source, and Visual C++ 2010 solution files.

Change History:

10 July 2010.
Added missing .vcxproj.filters file to the project.

13 June 2010.
Updated solution to Microsoft Visual Studio 2010.

1 April 2008.
gl_font.cpp: Fixed bug in drawTextEnd() method where the vertex buffer was not being unmapped when there's no text to draw. Thanks goes to Ari Ohvo for spotting this bug.

2 February 2008.
Updated solution to Microsoft Visual Studio 2008.

6 January 2008.
Renamed the file decal_map.tga to color_map.tga.

In all three shaders renamed the uniform sampler2D variable from decalMap to colorMap.

main.cpp: Major rewrite to use the same format and structure as the more recent OpenGL demos. Added font support. Added diagnostic output text. Added help text. Added ability to toggle textures on and off. Added support for Vista.

8 December 2006.
main.cpp: Changed the clear color to CornflowerBlue. Replaced the procedurally generated checker pattern with the same stone wall decal map texture as used in the bump mapping and parallax bump mapping demos. Much of the code has been rewritten to more closely match the structure of the bump mapping and parallax bump mapping demos.

18 November 2006.
main.cpp: The UpdateLighting() function was not being called when the camera was being dollied. This was causing the spot light's cone to remain fixed in size as the camera was being dollied.

12 November 2006.
fragment_lighting_dir.glsl: Removed unused position varying variable from the vertex and fragment shader.

 
box bottom left corner content box box bottom right corner
logo logo