X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Feffects%2Fambientocclusion.h;fp=source%2Feffects%2Fambientocclusion.h;h=6c2c5d7eea938daa6be0e6e5ce2387dd2a361660;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/effects/ambientocclusion.h b/source/effects/ambientocclusion.h new file mode 100644 index 00000000..6c2c5d7e --- /dev/null +++ b/source/effects/ambientocclusion.h @@ -0,0 +1,72 @@ +#ifndef MSP_GL_AMBIENTOCCLUSION_H_ +#define MSP_GL_AMBIENTOCCLUSION_H_ + +#include "framebuffer.h" +#include "mesh.h" +#include "postprocessor.h" +#include "program.h" +#include "programdata.h" +#include "rendertarget.h" +#include "texture2d.h" +#include "texturing.h" + +namespace Msp { +namespace GL { + +/** +Implements screen-space ambient occlusion. + +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; + float edge_depth_threshold; + + Template(); + + virtual AmbientOcclusion *create(unsigned, unsigned) const; + }; + +private: + Texture2D rotate_lookup; + RenderTarget occlude_target; + Texturing texturing; + Program occlude_shader; + Program combine_shader; + mutable ProgramData shdata; + RefPtr quad; + RefPtr linear_sampler; + RefPtr nearest_sampler; + +public: + AmbientOcclusion(unsigned, unsigned, float = 1.0f); + +private: + static float random(unsigned &); + +public: + void set_n_samples(unsigned); + void set_occlusion_radius(float); + void set_edge_depth_threshold(float); + + void set_darkness(float); + + virtual void render(Renderer &, const Texture2D &, const Texture2D &); +}; + +} // namespace GL +} // namespace Msp + +#endif