X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fshadowmap.cpp;h=eaf6e1373cb126a387d535e9e2b1352199eed2e7;hb=860aec7bfaabbad139d27dd7f4738984276e6676;hp=921a1747875b4bf0b349042dac6aab26095cff84;hpb=9319f1c8ed99866966f20fbab952da673af2257e;p=libs%2Fgl.git diff --git a/source/shadowmap.cpp b/source/shadowmap.cpp index 921a1747..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(); @@ -99,8 +106,9 @@ void ShadowMap::render(Renderer &renderer, const Tag &tag) const unsigned unit = renderer.allocate_effect_texunit(); int iunit = unit; - shdata.uniform("shadow", iunit); + shdata.uniform("shadow_map", iunit); + Bind _bind_sampler(*sampler, unit); Bind _bind_depth(depth_buf, unit); if(const Camera *camera = renderer.get_camera())