summaryrefslogtreecommitdiff
path: root/doc/EFFECT_WORKFLOW.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/EFFECT_WORKFLOW.md')
-rw-r--r--doc/EFFECT_WORKFLOW.md39
1 files changed, 22 insertions, 17 deletions
diff --git a/doc/EFFECT_WORKFLOW.md b/doc/EFFECT_WORKFLOW.md
index c4010db..46aebd2 100644
--- a/doc/EFFECT_WORKFLOW.md
+++ b/doc/EFFECT_WORKFLOW.md
@@ -44,14 +44,18 @@ void render(WGPUCommandEncoder encoder,
void declare_nodes(NodeRegistry& registry) override;
```
-**Uniforms**:
+**Uniforms** (auto-updated by base class):
```cpp
+// Available in render() via params:
params.time; // Physical seconds
params.beat_time; // Musical beats
params.beat_phase; // Fractional beat 0.0-1.0
params.audio_intensity; // Audio peak
params.resolution; // vec2(width, height)
params.aspect_ratio; // width/height
+
+// uniforms_buffer_ automatically initialized and updated
+// No need to call init_uniforms_buffer() or uniforms_buffer_.update()
```
### 2. Add Shader to Assets
@@ -143,17 +147,15 @@ class MyEffect : public Effect {
MyEffect::MyEffect(const GpuContext& ctx,
const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr) {
- uniforms_buffer_.init(ctx_.device);
- pipeline_ = create_post_process_pipeline(ctx_.device,
- WGPUTextureFormat_RGBA8Unorm,
- my_shader_wgsl);
-}
+ const std::vector<std::string>& outputs,
+ float start_time, float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time) {
+ HEADLESS_RETURN_IF_NULL(ctx_.device);
-MyEffect::~MyEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
+ // uniforms_buffer_ already initialized by base class
+ pipeline_.set(create_post_process_pipeline(ctx_.device,
+ WGPUTextureFormat_RGBA8Unorm,
+ my_shader_wgsl));
}
void MyEffect::render(WGPUCommandEncoder encoder,
@@ -162,9 +164,9 @@ void MyEffect::render(WGPUCommandEncoder encoder,
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
- uniforms_buffer_.update(ctx_.queue, params);
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
- uniforms_buffer_.get(), {nullptr, 0});
+ // uniforms_buffer_ already updated by base class dispatch_render()
+ pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(),
+ input_view, uniforms_buffer_.get(), {nullptr, 0});
WGPURenderPassColorAttachment color_attachment = {
.view = output_view,
@@ -196,9 +198,12 @@ void MyEffect::render(WGPUCommandEncoder encoder,
class My3DEffect : public Effect {
std::string depth_node_;
- My3DEffect(const GpuContext& ctx, ...)
- : Effect(ctx, inputs, outputs),
- depth_node_(outputs[0] + "_depth") {}
+ My3DEffect(const GpuContext& ctx, ..., float start_time, float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time),
+ depth_node_(outputs[0] + "_depth") {
+ HEADLESS_RETURN_IF_NULL(ctx_.device);
+ // Custom uniforms if needed (don't use base uniforms_buffer_)
+ }
void declare_nodes(NodeRegistry& registry) override {
registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1);