From bb4638a8470b0be2f960709368ec0d360a64f8ac Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 24 Apr 2021 23:11:26 +0300 Subject: [PATCH] Use RenderTargets in the Sky effect --- source/effects/sky.cpp | 16 ++++++---------- source/effects/sky.h | 8 +++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/source/effects/sky.cpp b/source/effects/sky.cpp index 8fa00cfb..c7e74879 100644 --- a/source/effects/sky.cpp +++ b/source/effects/sky.cpp @@ -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("_sky_transmittance.glsl.shader")), transmittance_lookup_dirty(true), + distant(256, 128, (RENDER_COLOR, RGB16F)), distant_shprog(resources.get("_sky_distant.glsl.shader")), fullscreen_mesh(resources.get("_fullscreen_quad.mesh")), backdrop_shprog(resources.get("_sky_backdrop.glsl.shader")), @@ -21,12 +23,6 @@ Sky::Sky(Resources &resources, Renderable &r, const Light &s): wrap_sampler(resources.get("_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); } diff --git a/source/effects/sky.h b/source/effects/sky.h index eb4f618d..5cc7bdaa 100644 --- a/source/effects/sky.h +++ b/source/effects/sky.h @@ -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; -- 2.45.2