]> git.tdb.fi Git - libs/gl.git/commitdiff
Use RenderTargets in the Sky effect
authorMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2021 20:11:26 +0000 (23:11 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 24 Apr 2021 20:18:32 +0000 (23:18 +0300)
source/effects/sky.cpp
source/effects/sky.h

index 8fa00cfbd4d44e884cdfadfd6268226705e039d2..c7e748794a4e3a6f6dbf58d1771000c053721154 100644 (file)
@@ -12,8 +12,10 @@ namespace GL {
 Sky::Sky(Resources &resources, Renderable &r, const Light &s):
        Effect(r),
        sun(s),
+       transmittance_lookup(128, 64, (RENDER_COLOR, RGB16F)),
        transmittance_shprog(resources.get<Program>("_sky_transmittance.glsl.shader")),
        transmittance_lookup_dirty(true),
+       distant(256, 128, (RENDER_COLOR, RGB16F)),
        distant_shprog(resources.get<Program>("_sky_distant.glsl.shader")),
        fullscreen_mesh(resources.get<Mesh>("_fullscreen_quad.mesh")),
        backdrop_shprog(resources.get<Program>("_sky_backdrop.glsl.shader")),
@@ -21,12 +23,6 @@ Sky::Sky(Resources &resources, Renderable &r, const Light &s):
        wrap_sampler(resources.get<Sampler>("_linear_clamp_v.samp")),
        rendered(false)
 {
-       transmittance_lookup.storage(RGB16F, 128, 64, 1);
-       transmittance_fbo.attach(COLOR_ATTACHMENT0, transmittance_lookup);
-
-       distant.storage(RGB16F, 256, 128, 1);
-       distant_fbo.attach(COLOR_ATTACHMENT0, distant);
-
        shdata.uniform("n_steps", 50);
 
        set_planet(Planet::earth());
@@ -68,14 +64,14 @@ void Sky::setup_frame(Renderer &renderer)
        if(transmittance_lookup_dirty)
        {
                transmittance_lookup_dirty = false;
-               Bind bind_fbo(transmittance_fbo);
+               Bind bind_fbo(transmittance_lookup.get_framebuffer());
                renderer.set_shader_program(&transmittance_shprog, &shdata);
                fullscreen_mesh.draw(renderer);
        }
 
-       Bind bind_fbo(distant_fbo);
+       Bind bind_fbo(distant.get_framebuffer());
        renderer.set_shader_program(&distant_shprog, &shdata);
-       renderer.set_texture("transmittance_lookup", &transmittance_lookup, &sampler);
+       renderer.set_texture("transmittance_lookup", &transmittance_lookup.get_target_texture(0), &sampler);
        fullscreen_mesh.draw(renderer);
 
        renderable.setup_frame(renderer);
@@ -97,7 +93,7 @@ void Sky::render(Renderer &renderer, Tag tag) const
        Renderer::Push push(renderer);
 
        renderer.set_shader_program(&backdrop_shprog, &shdata);
-       renderer.set_texture("distant", &distant, &wrap_sampler);
+       renderer.set_texture("distant", &distant.get_target_texture(0), &wrap_sampler);
        fullscreen_mesh.draw(renderer);
 }
 
index eb4f618d9607569bcdb32a9151a44ebf7442d8bd..5cc7bdaa668a6d6935be713f890f9c20991fc891 100644 (file)
@@ -4,7 +4,7 @@
 #include "effect.h"
 #include "framebuffer.h"
 #include "programdata.h"
-#include "texture2d.h"
+#include "rendertarget.h"
 
 namespace Msp {
 namespace GL {
@@ -42,13 +42,11 @@ public:
 
 private:
        const Light &sun;
-       Texture2D transmittance_lookup;
+       RenderTarget transmittance_lookup;
        const Program &transmittance_shprog;
-       Framebuffer transmittance_fbo;
        bool transmittance_lookup_dirty;
-       Texture2D distant;
+       RenderTarget distant;
        const Program &distant_shprog;
-       Framebuffer distant_fbo;
        const Mesh &fullscreen_mesh;
        const Program &backdrop_shprog;
        const Sampler &sampler;