]> git.tdb.fi Git - libs/gl.git/commitdiff
Provide the necessary uniforms from ShadowMap
authorMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 07:50:17 +0000 (10:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 28 Aug 2012 07:50:17 +0000 (10:50 +0300)
With the recent changes to the Effect and Renderer, it's finally possible
to avoid the need to specify the shadow map texture unit everywhere, and
get rid of the hardcoded gl_EyePlane* indices.

source/program.cpp
source/shadowmap.cpp
source/shadowmap.h

index adbb5c4cfd1a4ccf7ffd3fe41dc75646c33a1a6c..f11206677b94890ebe7d89dfdeefbc5af425e7f4 100644 (file)
@@ -17,6 +17,7 @@ namespace {
 
 const char *standard_vertex_src[] =
 {
+       "s",   "uniform int shadow_unit;\n",
        "n",   "attribute vec3 tangent;\n",
        "n",   "attribute vec3 binormal;\n",
        "t|n", "varying vec2 v_texcoord;\n",
@@ -46,7 +47,7 @@ const char *standard_vertex_src[] =
        "p|en",  "\tv_eye_dir = vec3(dot(eye_tangent, eye_dir), dot(eye_binormal, eye_dir), dot(eye_normal, eye_dir));\n",
        "p|e!n", "\tv_eye_dir = eye_dir;\n",
        "t|n", "\tv_texcoord = gl_MultiTexCoord0.xy;\n",
-       "s",   "\tv_shadowcoord = vec3(dot(gl_EyePlaneS[3], eye_pos), dot(gl_EyePlaneT[3], eye_pos), dot(gl_EyePlaneR[3], eye_pos));\n",
+       "s",   "\tv_shadowcoord = vec3(dot(gl_EyePlaneS[shadow_unit], eye_pos), dot(gl_EyePlaneT[shadow_unit], eye_pos), dot(gl_EyePlaneR[shadow_unit], eye_pos));\n",
        "!lm", "\tv_color = gl_Color;\n",
         0,    "}",
        0, 0
index a9edacfc3f9282ca6c1128d351c21712922494c7..95ef8583ccc9ab8e6b85fce1476f36d95d789cb2 100644 (file)
@@ -18,7 +18,6 @@ ShadowMap::ShadowMap(unsigned s, const Renderable &r, const Light &l):
        Effect(r),
        size(s),
        light(l),
-       unit(3),
        radius(1)
 {
        depth_buf.set_min_filter(LINEAR);
@@ -27,6 +26,8 @@ ShadowMap::ShadowMap(unsigned s, const Renderable &r, const Light &l):
        depth_buf.set_wrap(CLAMP_TO_EDGE);
        depth_buf.storage(DEPTH_COMPONENT, size, size);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
+
+       set_texture_unit(3);
 }
 
 void ShadowMap::set_target(const Vector3 &t, float r)
@@ -38,6 +39,10 @@ void ShadowMap::set_target(const Vector3 &t, float r)
 void ShadowMap::set_texture_unit(unsigned u)
 {
        unit = u;
+
+       int i = unit;
+       shdata.uniform("shadow", i);
+       shdata.uniform("shadow_unit", i);
 }
 
 void ShadowMap::render(Renderer &renderer, const Tag &tag) const
@@ -119,6 +124,8 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const
        tg_r.bind_to(RCOORD);
        TexUnit::activate(0);
 
+       Renderer::Push _push_rend(renderer);
+       renderer.add_shader_data(shdata);
        renderable.render(renderer, tag);
 
        Texture::unbind_from(unit);
index 11407462c3e1922c48cd9bb0b3725829e207f595..af3cf6f72c2b9af398e7faa317f6fdeaa810627f 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "effect.h"
 #include "framebuffer.h"
+#include "programdata.h"
 #include "texture2d.h"
 #include "vector.h"
 
@@ -28,6 +29,7 @@ private:
        Texture2D depth_buf;
        Vector3 target;
        float radius;
+       ProgramData shdata;
 
 public:
        ShadowMap(unsigned, const Renderable &, const Light &);