|
From: James W. <ja...@fr...> - 2007-05-30 19:50:22
|
Description The Quesa OpenGL renderer now has an option to render shadows. It produces sharp-edged shadows from any directional, spot, or point light that has its cast-shadows flag set to kQ3True. It respects the casts-shadows style but not the receive-shadows style. Translucent objects do not cast shadows, nor do lines or points. Rendering with shadows can be requested by setting an object property on the renderer object: TQ3Boolean theFlag = kQ3True; Q3Object_SetProperty( theRenderer, kQ3RendererPropertyShadows, sizeof(theFlag), &theFlag ); This option can be used with or without the per-pixel lighting option. It is not intended to work with orthographic cameras. Hardware Requirements In order to render with shadows, your OpenGL drawing context must: 1. Be able to have a stencil buffer at least 8 bits deep, as well as a depth buffer. (This is usually not a problem. One case where it fails is the Windows software renderer.) 2. Support either OpenGL 2.0 or the GL_EXT_stencil_two_side extension. It is preferable, but not essential, to have the extensions GL_EXT_stencil_wrap and GL_NV_depth_clamp as well. Warnings The algorithm sets the "yon" value of your camera range to infinity. To prevent surprises, it would be a good idea to set "yon" to infinity yourself. While it is true that you get the best depth resolution when hither is as large as possible and yon is as small as possible, it is much more important to make hither as large as possible. If you are using Quesa on Windows, beware that Windows does not allow setting the pixel format of a window more than once. This means that if you start rendering without shadows, and then attempt to turn on shadows, it will fail, because you will not be able to get a stencil buffer. You can work around this problem by explicitly requesting a stencil buffer from the start, using kQ3DrawContextPropertyGLStencilBufferDepth. Performance Shadows require a multi-pass rendering algorithm. The first pass handles ambient light and non-shadow-casting lights, assuming there are no more than 8 of them. Then for each shadow-casting light, there is a stencil marking pass followed by a lighting pass. Naturally, this will be slower than a single-pass algorithm. There is even more of a speed hit if you combine per-pixel lighting with shadows, since each lighting pass will be slower. Naturally, you can improve performance by designating some lights and some objects as not casting shadows. It also helps to use the Remove backfacing style when feasible, and to ensure that your TriMeshes supply face normal vectors. |