X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fshadowmap.cpp;h=eaf6e1373cb126a387d535e9e2b1352199eed2e7;hp=0e32210f49a044a36f4977fc1e069854ee42f57a;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=929a2d975be0590503fe6701526dd9536e60e026 diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 0e32210f..eaf6e137 100644 --- a/source/shadowmap.cpp +++ b/source/shadowmap.cpp @@ -12,6 +12,8 @@ using namespace std; namespace Msp { namespace GL { +WeakPtr ShadowMap::shadow_sampler; + ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l): Effect(r), size(s), @@ -20,11 +22,16 @@ ShadowMap::ShadowMap(unsigned s, Renderable &r, const Light &l): depth_bias(4), rendered(false) { - depth_buf.set_min_filter(LINEAR); - depth_buf.set_compare_enabled(true); - depth_buf.set_compare_func(LEQUAL); - depth_buf.set_wrap(CLAMP_TO_EDGE); - depth_buf.storage(DEPTH_COMPONENT, size, size, 1); + sampler = shadow_sampler; + if(!sampler) + { + sampler = new Sampler; + sampler->set_filter(LINEAR); + sampler->set_compare(LEQUAL); + sampler->set_wrap(CLAMP_TO_EDGE); + shadow_sampler = sampler; + } + depth_buf.storage(DEPTH_COMPONENT32F, size, size, 1); fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0); fbo.require_complete(); @@ -101,6 +108,7 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const int iunit = unit; shdata.uniform("shadow_map", iunit); + Bind _bind_sampler(*sampler, unit); Bind _bind_depth(depth_buf, unit); if(const Camera *camera = renderer.get_camera())