2006-01-07 02:04:26 +01:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : ShadowMap.h
|
|
|
|
* Project : Pyrogenesis
|
|
|
|
* Description : Shadow mapping related texture and matrix management
|
|
|
|
*
|
|
|
|
* @author Nicolai Hähnle <nicolai@wildfiregames.com>
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHADOWMAP_H
|
|
|
|
#define SHADOWMAP_H
|
|
|
|
|
|
|
|
#include "ogl.h"
|
|
|
|
|
|
|
|
class CBound;
|
|
|
|
class CMatrix3D;
|
|
|
|
|
|
|
|
struct ShadowMapInternals;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup,
|
|
|
|
* including matrix calculations.
|
|
|
|
*
|
|
|
|
* The class will automatically generate a texture the first time the shadow map is rendered into.
|
|
|
|
* The texture will not be resized afterwards.
|
|
|
|
*
|
2006-02-11 19:04:32 +01:00
|
|
|
* Can use a simple luminance map to store shadows (no self-shadowing possible) or
|
|
|
|
* depth textures (with self-shadowing). Default is to use a luminance map, use SetUseDepthTexture
|
|
|
|
* to override the default.
|
2006-01-07 02:04:26 +01:00
|
|
|
*/
|
|
|
|
class ShadowMap
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ShadowMap();
|
|
|
|
~ShadowMap();
|
|
|
|
|
2006-05-31 18:42:50 +02:00
|
|
|
/**
|
|
|
|
* RecreateTexture: Destroy the current shadow texture and force creation of
|
|
|
|
* a new one. Useful when the renderer's size has changed and the texture
|
|
|
|
* should be resized too.
|
|
|
|
*/
|
|
|
|
void RecreateTexture();
|
|
|
|
|
2006-02-11 19:04:32 +01:00
|
|
|
/**
|
|
|
|
* GetUseDepthTexture: Return whether rendering uses a depth texture (instead of
|
|
|
|
* a luminance texture).
|
|
|
|
*
|
|
|
|
* Note that this value may be changed automatically based on OpenGL capabilities.
|
|
|
|
* It is guarantueed that it stays constant after SetupFrame until the end of the
|
|
|
|
* frame or the next call to SetUseDepthTexture.
|
|
|
|
*
|
|
|
|
* @return whether shadow rendering uses depth textures
|
|
|
|
*/
|
2006-03-26 01:54:20 +01:00
|
|
|
bool GetUseDepthTexture() const;
|
2006-02-11 19:04:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SetUseDepthTexture: Set whether shadowing should use depth textures.
|
|
|
|
* Note that even passing @c true for depthTexture does not actually guarantuee that
|
|
|
|
* depth textures will be used (mostly due to OpenGL capabilities). See the comment
|
|
|
|
* for GetUseDepthTexture.
|
|
|
|
*
|
|
|
|
* @param depthTexture whether shadow rendering should use depth textures
|
|
|
|
*/
|
|
|
|
void SetUseDepthTexture(bool depthTexture);
|
|
|
|
|
2006-02-16 00:50:24 +01:00
|
|
|
/**
|
|
|
|
* GetDepthTextureBits: Return the number of bits to use for depth textures when
|
|
|
|
* enabled.
|
|
|
|
*
|
|
|
|
* @return depth texture bit depth
|
|
|
|
*/
|
|
|
|
int GetDepthTextureBits() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled.
|
|
|
|
* Possible values are 16, 24, 32 and 0 (= use default)
|
|
|
|
*
|
|
|
|
* @param bits number of bits
|
|
|
|
*/
|
|
|
|
void SetDepthTextureBits(int bits);
|
|
|
|
|
2006-01-29 18:34:45 +01:00
|
|
|
/**
|
2006-02-11 01:26:40 +01:00
|
|
|
* SetupFrame: Configure light space for the given camera and light direction,
|
|
|
|
* create the shadow texture if necessary, etc.
|
2006-01-29 18:34:45 +01:00
|
|
|
*
|
|
|
|
* @param camera the camera that will be used for world rendering
|
|
|
|
* @param lightdir the direction of the (directional) sunlight
|
|
|
|
*/
|
2006-02-11 01:26:40 +01:00
|
|
|
void SetupFrame(const CCamera& camera, const CVector3D& lightdir);
|
2006-01-29 18:34:45 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AddShadowedBound: Add the bounding box of an object that has to be shadowed.
|
|
|
|
* This is used to calculate the bounds for the shadow map.
|
|
|
|
*
|
|
|
|
* @param bounds world space bounding box
|
|
|
|
*/
|
|
|
|
void AddShadowedBound(const CBound& bounds);
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BeginRender: Set OpenGL state for rendering into the shadow map texture.
|
2006-01-29 18:34:45 +01:00
|
|
|
*
|
2006-01-07 02:04:26 +01:00
|
|
|
* @todo this depends in non-obvious ways on the behaviour of the call-site
|
|
|
|
*/
|
|
|
|
void BeginRender();
|
2006-01-29 18:34:45 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
/**
|
|
|
|
* EndRender: Finish rendering into the shadow map.
|
2006-01-29 18:34:45 +01:00
|
|
|
*
|
2006-01-07 02:04:26 +01:00
|
|
|
* @todo this depends in non-obvious ways on the behaviour of the call-site
|
|
|
|
*/
|
|
|
|
void EndRender();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetTexture: Retrieve the OpenGL texture object name that contains the shadow map.
|
|
|
|
*
|
|
|
|
* @return the texture name of the shadow map texture
|
|
|
|
*/
|
2006-03-26 01:54:20 +01:00
|
|
|
GLuint GetTexture() const;
|
2006-01-29 18:34:45 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
/**
|
|
|
|
* GetTextureMatrix: Retrieve the world-space to shadow map texture coordinates
|
|
|
|
* transformation matrix.
|
|
|
|
*
|
|
|
|
* @return the matrix that transforms world-space coordinates into homogenous
|
|
|
|
* shadow map texture coordinates
|
|
|
|
*/
|
2006-03-26 01:54:20 +01:00
|
|
|
const CMatrix3D& GetTextureMatrix() const;
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-01-29 18:34:45 +01:00
|
|
|
/**
|
|
|
|
* RenderDebugDisplay: Visualize shadow mapping calculations to help in
|
|
|
|
* debugging and optimal shadow map usage.
|
|
|
|
*/
|
|
|
|
void RenderDebugDisplay();
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
private:
|
|
|
|
ShadowMapInternals* m;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SHADOWMAP_H
|