X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Feffects%2Fshadowmap.h;h=611f56f51040a2204055e29f37d0e67a68d48b7c;hp=e142fc8cafdd56023459035f53d48e73205c997b;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266 diff --git a/source/effects/shadowmap.h b/source/effects/shadowmap.h index e142fc8c..611f56f5 100644 --- a/source/effects/shadowmap.h +++ b/source/effects/shadowmap.h @@ -1,20 +1,22 @@ #ifndef MSP_GL_SHADOWMAP_H_ #define MSP_GL_SHADOWMAP_H_ +#include "camera.h" #include "effect.h" #include "framebuffer.h" #include "programdata.h" +#include "rect.h" #include "texture2d.h" #include "vector.h" namespace Msp { namespace GL { +class DirectionalLight; class Light; -class Scene; /** -Creates shadows on a Scene through a shadow map texture. In the preparation +Creates shadows on a renderable through a shadow map texture. In the setup 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. @@ -22,22 +24,36 @@ texture coordinate generation to determine whether each fragment is lit. class ShadowMap: public Effect { private: - unsigned size; - const Light &light; + struct ShadowedLight + { + const Light *light; + unsigned index; + Rect region; + Camera shadow_camera; + }; + + unsigned width; + unsigned height; + const Lighting *lighting; + std::vector lights; + Renderable &shadow_caster; Framebuffer fbo; - Matrix shadow_matrix; Texture2D depth_buf; - RefPtr sampler; + const Sampler &sampler; Vector3 target; - float radius; - float depth_bias; - mutable ProgramData shdata; - bool rendered; - - static WeakPtr shadow_sampler; + float radius = 1.0f; + float depth_bias = 4.0f; + float darkness = 1.0f; + ProgramData shdata; + bool rendered = false; + std::string debug_name; + ShadowMap(unsigned, unsigned, Renderable &, const Lighting *, Renderable &); public: - ShadowMap(unsigned, Renderable &, const Light &); + ShadowMap(unsigned, Renderable &, const DirectionalLight &, Renderable &); + ShadowMap(unsigned, unsigned, Renderable &, const Lighting &, Renderable &); + + void add_light(const DirectionalLight &, unsigned); /** Sets the ShadowMap target point and radius. The transformation matrix is computed so that a sphere with the specified parameters will be completely @@ -56,12 +72,13 @@ public: void set_depth_bias(float); const Texture2D &get_depth_texture() const { return depth_buf; } - const Matrix &get_shadow_matrix() const { return shadow_matrix; } virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; + + virtual void set_debug_name(const std::string &); }; } // namespace GL