From 9f5f027d1c93e541a12b8e4c04bd25b11edbe132 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 20 Jun 2018 13:37:51 +0300 Subject: [PATCH] Add loading support for AmbientOcclusion --- source/ambientocclusion.cpp | 25 +++++++++++++++++++++++++ source/ambientocclusion.h | 18 ++++++++++++++++++ source/pipelinetemplate.cpp | 2 ++ 3 files changed, 45 insertions(+) diff --git a/source/ambientocclusion.cpp b/source/ambientocclusion.cpp index 3d56f3f0..91e10ad7 100644 --- a/source/ambientocclusion.cpp +++ b/source/ambientocclusion.cpp @@ -108,5 +108,30 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const quad.draw(renderer); } + +AmbientOcclusion::Template::Template(): + n_samples(16), + occlusion_radius(0.5f), + darkness(1.0f) +{ } + +AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const +{ + RefPtr ao = new AmbientOcclusion(width/size_divisor, height/size_divisor); + ao->set_n_samples(n_samples); + ao->set_occlusion_radius(occlusion_radius); + ao->set_darkness(darkness); + return ao.release(); +} + + +AmbientOcclusion::Template::Loader::Loader(Template &t): + DataFile::DerivedObjectLoader(t) +{ + add("darkness", &Template::darkness); + add("occlusion_radius", &Template::occlusion_radius); + add("samples", &Template::n_samples); +} + } // namespace GL } // namespace Msp diff --git a/source/ambientocclusion.h b/source/ambientocclusion.h index b6daa776..e7829c18 100644 --- a/source/ambientocclusion.h +++ b/source/ambientocclusion.h @@ -20,6 +20,24 @@ http://en.wikipedia.org/wiki/Screen_Space_Ambient_Occlusion */ class AmbientOcclusion: public PostProcessor { +public: + struct Template: PostProcessor::Template + { + class Loader: public DataFile::DerivedObjectLoader + { + public: + Loader(Template &); + }; + + unsigned n_samples; + float occlusion_radius; + float darkness; + + Template(); + + virtual AmbientOcclusion *create(unsigned, unsigned) const; + }; + private: Texture2D rotate_lookup; RenderTarget occlude_target; diff --git a/source/pipelinetemplate.cpp b/source/pipelinetemplate.cpp index 6dbfd0a2..4493e72c 100644 --- a/source/pipelinetemplate.cpp +++ b/source/pipelinetemplate.cpp @@ -1,5 +1,6 @@ #include #include +#include "ambientocclusion.h" #include "blend.h" #include "bloom.h" #include "colorcurve.h" @@ -37,6 +38,7 @@ PipelineTemplate::Loader::Loader(PipelineTemplate &t, Collection &c): void PipelineTemplate::Loader::init() { + add("ambient_occlusion", &Loader::postprocessor); add("bloom", &Loader::postprocessor); add("colorcurve", &Loader::postprocessor); add("hdr", &PipelineTemplate::hdr); -- 2.45.2