Add loading support for AmbientOcclusion
authorMikko Rasa <tdb@tdb.fi>
Wed, 20 Jun 2018 10:37:51 +0000 (13:37 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 20 Jun 2018 10:37:51 +0000 (13:37 +0300)
source/ambientocclusion.cpp
source/ambientocclusion.h
source/pipelinetemplate.cpp

index 3d56f3f0269c32cc128d8fc70b075547716e19d5..91e10ad7a4f33f4325cc12762fe65a5e2e347148 100644 (file)
@@ -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<AmbientOcclusion> 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<Template, PostProcessor::Template::Loader>(t)
+{
+       add("darkness", &Template::darkness);
+       add("occlusion_radius", &Template::occlusion_radius);
+       add("samples", &Template::n_samples);
+}
+
 } // namespace GL
 } // namespace Msp
index b6daa776d6af8804f5cf1186cb7974d1b5f3783d..e7829c181dce39bce8c74f69a631a56fcc9990b0 100644 (file)
@@ -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<Template, PostProcessor::Template::Loader>
+               {
+               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;
index 6dbfd0a247721edbb6e4f88521d6bee02a742b45..4493e72c80b38e60c008547280f854629f76dabc 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/maputils.h>
 #include <msp/datafile/collection.h>
+#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<AmbientOcclusion>);
        add("bloom", &Loader::postprocessor<Bloom>);
        add("colorcurve", &Loader::postprocessor<ColorCurve>);
        add("hdr", &PipelineTemplate::hdr);