diff options
Diffstat (limited to 'src/gpu/effects')
| -rw-r--r-- | src/gpu/effects/flash_effect.cc | 10 | ||||
| -rw-r--r-- | src/gpu/effects/post_process_helper.cc | 15 | ||||
| -rw-r--r-- | src/gpu/effects/post_process_helper.h | 6 |
3 files changed, 20 insertions, 11 deletions
diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc index 217a7bb..5aebe2d 100644 --- a/src/gpu/effects/flash_effect.cc +++ b/src/gpu/effects/flash_effect.cc @@ -15,7 +15,7 @@ FlashEffect::FlashEffect(const GpuContext& ctx) struct Uniforms { flash_intensity: f32, - _pad0: f32, + intensity: f32, _pad1: f32, _pad2: f32, }; @@ -42,7 +42,9 @@ FlashEffect::FlashEffect(const GpuContext& ctx) let color = textureSample(inputTexture, inputSampler, input.uv); // Add white flash: blend towards white based on flash intensity let white = vec3<f32>(1.0, 1.0, 1.0); - let flashed = mix(color.rgb, white, uniforms.flash_intensity); + let green = vec3<f32>(0.0, 1.0, 0.0); + var flashed = mix(color.rgb, green, uniforms.intensity); + if (input.uv.y > .5) { flashed = mix(color.rgb, white, uniforms.flash_intensity); } return vec4<f32>(flashed, color.a); } )"; @@ -68,9 +70,9 @@ void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat, } // Exponential decay - flash_intensity_ *= 0.85f; + flash_intensity_ *= 0.98f; - float uniforms[4] = {flash_intensity_, 0.0f, 0.0f, 0.0f}; + float uniforms[4] = {flash_intensity_, intensity, 0.0f, 0.0f}; wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, uniforms, sizeof(uniforms)); wgpuRenderPassEncoderSetPipeline(pass, pipeline_); diff --git a/src/gpu/effects/post_process_helper.cc b/src/gpu/effects/post_process_helper.cc index db89d77..0a2ac22 100644 --- a/src/gpu/effects/post_process_helper.cc +++ b/src/gpu/effects/post_process_helper.cc @@ -1,6 +1,7 @@ // This file is part of the 64k demo project. // It implements helper functions for post-processing effects. +#include "post_process_helper.h" #include "../demo_effects.h" #include "gpu/gpu.h" #include <cstring> @@ -18,15 +19,15 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, wgpuDeviceCreateShaderModule(device, &shader_desc); WGPUBindGroupLayoutEntry bgl_entries[3] = {}; - bgl_entries[0].binding = 0; + bgl_entries[0].binding = PP_BINDING_SAMPLER; bgl_entries[0].visibility = WGPUShaderStage_Fragment; bgl_entries[0].sampler.type = WGPUSamplerBindingType_Filtering; - bgl_entries[1].binding = 1; + bgl_entries[1].binding = PP_BINDING_TEXTURE; bgl_entries[1].visibility = WGPUShaderStage_Fragment; bgl_entries[1].texture.sampleType = WGPUTextureSampleType_Float; bgl_entries[1].texture.viewDimension = WGPUTextureViewDimension_2D; - bgl_entries[2].binding = 2; - bgl_entries[2].visibility = WGPUShaderStage_Fragment; + bgl_entries[2].binding = PP_BINDING_UNIFORMS; + bgl_entries[2].visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment; bgl_entries[2].buffer.type = WGPUBufferBindingType_Uniform; WGPUBindGroupLayoutDescriptor bgl_desc = {}; @@ -74,11 +75,11 @@ void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, sd.maxAnisotropy = 1; WGPUSampler sampler = wgpuDeviceCreateSampler(device, &sd); WGPUBindGroupEntry bge[3] = {}; - bge[0].binding = 0; + bge[0].binding = PP_BINDING_SAMPLER; bge[0].sampler = sampler; - bge[1].binding = 1; + bge[1].binding = PP_BINDING_TEXTURE; bge[1].textureView = input_view; - bge[2].binding = 2; + bge[2].binding = PP_BINDING_UNIFORMS; bge[2].buffer = uniforms.buffer; bge[2].size = uniforms.size; WGPUBindGroupDescriptor bgd = { diff --git a/src/gpu/effects/post_process_helper.h b/src/gpu/effects/post_process_helper.h index 1986ff3..45757cf 100644 --- a/src/gpu/effects/post_process_helper.h +++ b/src/gpu/effects/post_process_helper.h @@ -5,7 +5,13 @@ #include "gpu/gpu.h" +// Standard post-process bind group layout (group 0): +#define PP_BINDING_SAMPLER 0 // Sampler for input texture +#define PP_BINDING_TEXTURE 1 // Input texture (previous render pass) +#define PP_BINDING_UNIFORMS 2 // Custom uniforms buffer + // Helper to create a standard post-processing pipeline +// Uniforms are accessible to both vertex and fragment shaders WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPUTextureFormat format, const char* shader_code); |
