]> git.tdb.fi Git - libs/gl.git/blobdiff - source/effects/shadowmap.h
Refactor ShadowMap to support multiple lights
[libs/gl.git] / source / effects / shadowmap.h
index 67103b86f8abfe11ab56ead2ea801759c5138b1c..c3c7bd55a7f53430937cce8faf6f6955b220f61d 100644 (file)
@@ -5,6 +5,7 @@
 #include "effect.h"
 #include "framebuffer.h"
 #include "programdata.h"
+#include "rect.h"
 #include "texture2d.h"
 #include "vector.h"
 
@@ -22,22 +23,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<ShadowedLight> lights;
        Renderable &shadow_caster;
        Framebuffer fbo;
-       Camera shadow_camera;
-       Matrix shadow_matrix;
        Texture2D depth_buf;
        const Sampler &sampler;
        Vector3 target;
        float radius;
        float depth_bias;
+       float darkness;
        ProgramData shdata;
        bool rendered;
+       std::string debug_name;
 
+       ShadowMap(unsigned, unsigned, Renderable &, const Lighting *, Renderable &);
 public:
        ShadowMap(unsigned, Renderable &, const Light &, Renderable &);
+       ShadowMap(unsigned, unsigned, Renderable &, const Lighting &, Renderable &);
+
+       void add_light(const Light &, 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,7 +71,6 @@ 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();