X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Feffects%2Fambientocclusion.cpp;h=8c31a53fb115ddfe5ff25dd1f540e60132f6dc5b;hp=430ac0ba86556747005fb046ce5a3e32aaaddb7d;hb=c8520aa336e92f2eaf9a38c3430c608520a90324;hpb=28965eccb61d06a497645e0770826de161b0e4cb diff --git a/source/effects/ambientocclusion.cpp b/source/effects/ambientocclusion.cpp index 430ac0ba..8c31a53f 100644 --- a/source/effects/ambientocclusion.cpp +++ b/source/effects/ambientocclusion.cpp @@ -2,10 +2,10 @@ #include "ambientocclusion.h" #include "blend.h" #include "camera.h" +#include "mesh.h" #include "renderer.h" #include "resources.h" -#include "shader.h" -#include "tests.h" +#include "texture2d.h" using namespace std; @@ -14,7 +14,7 @@ namespace GL { AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float): rotate_lookup(get_or_create_rotate_lookup()), - occlude_target(w, h, (RENDER_COLOR,R8)), + occlude_target(w, h, (COLOR_ATTACHMENT,R8)), occlude_shader(Resources::get_global().get("_ambientocclusion_occlude.glsl.shader")), combine_shader(Resources::get_global().get("_ambientocclusion_combine.glsl.shader")), quad(Resources::get_global().get("_fullscreen_quad.mesh")), @@ -32,7 +32,7 @@ const Texture2D &AmbientOcclusion::get_or_create_rotate_lookup() { Resources &resources = Resources::get_global(); - static const string name = "_ambientocclusion_rotate.tex2d"; + static const string name = "_ambientocclusion_rotate.tex"; Texture2D *rotate_lookup = resources.find(name); if(rotate_lookup) return *rotate_lookup; @@ -67,10 +67,10 @@ float AmbientOcclusion::radical_inverse(unsigned n) void AmbientOcclusion::set_n_samples(unsigned n) { - if(n<1 || n>32) + if(n<1 || n>128) throw out_of_range("AmbientOcclusion::set_n_samples"); - Vector3 sample_points[32]; + vector sample_points(n); for(unsigned i=0; i(i)/n; @@ -100,29 +100,33 @@ void AmbientOcclusion::set_edge_depth_threshold(float edt) void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const Texture2D &depth) { + const Framebuffer *out_fbo = renderer.get_framebuffer(); + Renderer::Push push(renderer); renderer.set_texture("source", &color, &nearest_clamp_sampler); renderer.set_texture("depth", &depth, &nearest_clamp_sampler); - renderer.set_texture("occlusion", &occlude_target.get_target_texture(RENDER_COLOR), &linear_sampler); + renderer.set_texture("occlusion", &occlude_target.get_target_texture(COLOR_ATTACHMENT), &linear_sampler); renderer.set_texture("rotate", &rotate_lookup, &nearest_sampler); renderer.set_shader_program(&occlude_shader, &shdata); - { - BindRestore bind_fbo(occlude_target.get_framebuffer()); - quad.draw(renderer); - } + renderer.set_framebuffer(&occlude_target.get_framebuffer()); + quad.draw(renderer); + renderer.set_framebuffer(out_fbo); renderer.set_shader_program(&combine_shader); quad.draw(renderer); } +void AmbientOcclusion::set_debug_name(const string &name) +{ +#ifdef DEBUG + occlude_target.set_debug_name(name+" [RT]"); + shdata.set_debug_name(name+" [UBO]"); +#else + (void)name; +#endif +} -AmbientOcclusion::Template::Template(): - n_samples(16), - occlusion_radius(0.5f), - darkness(1.0f), - edge_depth_threshold(0.1f) -{ } AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const {