Skip to content

Commit

Permalink
tonemap - pixel -> compute shader
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 13, 2024
1 parent 727f823 commit aa18735
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
21 changes: 9 additions & 12 deletions data/pipelines/tonemap.shd
Original file line number Diff line number Diff line change
@@ -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;
}
]]
1 change: 1 addition & 0 deletions src/gui/gui_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 12 additions & 8 deletions src/renderer/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include "texture.h"
#include <imgui/imgui.h>

// TODO must haves:
// TODO check if github CI works

// TODO crashes:
// TODO crash when context menu is outside of main window

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit aa18735

Please sign in to comment.