diff --git a/data/pipelines/tonemap.shd b/data/pipelines/tonemap.shd index 1fc3107ccc..1e313fca5c 100644 --- a/data/pipelines/tonemap.shd +++ b/data/pipelines/tonemap.shd @@ -1,23 +1,20 @@ include "pipelines/common.glsl" -vertex_shader [[ +compute_shader [[ struct Output { float2 uv : TEXCOORD0; float4 position : SV_POSITION; }; - Output main(uint vertex_id : SV_VertexID) { - Output output; - output.position = fullscreenQuad(vertex_id, output.uv); - return output; - } -]] - -fragment_shader [[ cbuffer Data : register(b4) { - uint hdr_buffer; + uint input; + uint output; }; - float4 main(float2 uv : TEXCOORD0) : SV_TARGET { - return float4(ACESFilm(sampleBindlessLod(LinearSamplerClamp, hdr_buffer, uv, 0).rgb), 1); + + [numthreads(16, 16, 1)] + void main(uint3 thread_id : SV_DispatchThreadID) { + float4 v = bindless_textures[input][thread_id.xy]; + v = float4(ACESFilm(v.rgb), 1); + bindless_rw_textures[output][thread_id.xy] = v; } ]] \ No newline at end of file diff --git a/src/gui/gui_system.cpp b/src/gui/gui_system.cpp index 2638898ee6..ae8bd56979 100644 --- a/src/gui/gui_system.cpp +++ b/src/gui/gui_system.cpp @@ -80,6 +80,7 @@ struct GUISystemImpl final : GUISystem } RenderBufferHandle renderAfterTonemap(const GBuffer& gbuffer, RenderBufferHandle input, Pipeline& pipeline) override { + pipeline.setRenderTargets(Span(&input, 1)); if (pipeline.getType() != PipelineType::GAME_VIEW) return input; auto* module = (GUIModule*)pipeline.getModule()->getWorld().getModule("gui"); Vec2 size = m_system.m_interface->getSize(); diff --git a/src/renderer/pipeline.cpp b/src/renderer/pipeline.cpp index 28748d7bce..e5d4ab2535 100644 --- a/src/renderer/pipeline.cpp +++ b/src/renderer/pipeline.cpp @@ -35,9 +35,6 @@ #include "texture.h" #include -// TODO must haves: - // TODO check if github CI works - // TODO crashes: // TODO crash when context menu is outside of main window @@ -1053,13 +1050,20 @@ struct PipelineImpl final : Pipeline { beginBlock("tonemap"); const RenderBufferHandle rb = createRenderbuffer({ - .format = is_preview ? gpu::TextureFormat::RGBA8 : gpu::TextureFormat::SRGBA, - .flags = gpu::TextureFlags::RENDER_TARGET | gpu::TextureFlags::NO_MIPS, + .format = gpu::TextureFormat::RGBA8, + .flags = gpu::TextureFlags::RENDER_TARGET | gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::COMPUTE_WRITE, .debug_name = "tonemap" }); - setRenderTargets(Span(&rb, 1)); - setUniform(toBindless(input, m_renderer.getDrawStream())); - drawArray(0, 3, *m_tonemap_shader, 0, gpu::StateFlags::NONE); + DrawStream& stream = m_renderer.getDrawStream(); + struct { + gpu::BindlessHandle input; + gpu::RWBindlessHandle output; + } ubdata { + toBindless(input, stream), + toRWBindless(rb, stream) + }; + setUniform(ubdata); + dispatch(*m_tonemap_shader, (m_viewport.w + 15) / 16, (m_viewport.h + 15) / 16, 1); endBlock(); return rb; }