X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fshadowmap.h;h=119d369c1eb6db052048d941008c18f7b3d58560;hb=3b159edbe4e80a2bc19c4c2fcd42cb996b9fbfe0;hp=17e17ca9ce940344713c558f8339d9c809fdef92;hpb=41339bc44d076569c680b2c24c75b30ef1254c1b;p=libs%2Fgl.git diff --git a/source/shadowmap.h b/source/shadowmap.h index 17e17ca9..119d369c 100644 --- a/source/shadowmap.h +++ b/source/shadowmap.h @@ -1,15 +1,9 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2009 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#ifndef SHADOWMAP_H_ -#define SHADOWMAP_H_ +#ifndef MSP_GL_SHADOWMAP_H_ +#define MSP_GL_SHADOWMAP_H_ #include "effect.h" #include "framebuffer.h" +#include "programdata.h" #include "texture2d.h" #include "vector.h" @@ -19,24 +13,49 @@ namespace GL { class Light; class Scene; +/** +Creates shadows on a Scene through a shadow map texture. In the preparation +phase, the scene is rendered to a depth texture from the point of view of the +lightsource. This texture is then used in the rendering phase together with +texture coordinate generation to determine whether each fragment is lit. +*/ class ShadowMap: public Effect { private: unsigned size; - const Scene &scene; const Light &light; - Framebuffer fbo; -public: + mutable Framebuffer fbo; + mutable Matrix shadow_matrix; Texture2D depth_buf; -private: Vector3 target; float radius; + float depth_bias; + mutable ProgramData shdata; + mutable bool rendered; public: - ShadowMap(unsigned, const Scene &, const Light &); + ShadowMap(unsigned, const Renderable &, const Light &); + + /** Sets the ShadowMap target point and radius. The transformation matrix is + computed so that a sphere with the specified parameters will be completely + covered by the ShadowMap. */ void set_target(const Vector3 &, float); - virtual void prepare(); - virtual void cleanup(); + + /** Sets the darkness of shadows. Must be in the range between 0.0 and 1.0, + inclusive. Only usable with shaders, and provided through the + shadow_darkness uniform. */ + void set_darkness(float); + + /** Sets a distance beyond objects from which the shadow starts. Expressed + in pixel-sized units. Must be positive; values less than 1.0 are not + recommended. Larger values produce less depth artifacts, but may prevent + thin objects from casting shadows on nearby sufraces. */ + void set_depth_bias(float); + + virtual void setup_frame() const; + virtual void finish_frame() const; + + virtual void render(Renderer &, const Tag &) const; }; } // namespace GL