diff options
Diffstat (limited to 'src/effects/sdf_test_effect.cc')
| -rw-r--r-- | src/effects/sdf_test_effect.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/effects/sdf_test_effect.cc b/src/effects/sdf_test_effect.cc new file mode 100644 index 0000000..28b3513 --- /dev/null +++ b/src/effects/sdf_test_effect.cc @@ -0,0 +1,36 @@ +// This file is part of the 64k demo project. +// It implements the SDFTestEffect. + +#include "effects/sdf_test_effect.h" +#include "gpu/gpu.h" +#include "gpu/shaders.h" + +SDFTestEffect::SDFTestEffect(const GpuContext& ctx) : SDFEffect(ctx) { + ResourceBinding bindings[] = { + {uniforms_.get(), WGPUBufferBindingType_Uniform}, + {camera_params_.get(), WGPUBufferBindingType_Uniform}}; + pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, + sdf_test_shader_wgsl, bindings, 2); + pass_.vertex_count = 3; +} + +void SDFTestEffect::render(WGPURenderPassEncoder pass, + const CommonPostProcessUniforms& uniforms) { + // Update common uniforms + uniforms_.update(ctx_.queue, uniforms); + + // Update camera (simple orbiting camera) + const float radius = 5.0f; + const float speed = 0.3f; + vec3 cam_pos(std::cos(uniforms.time * speed) * radius, 2.0f, + std::sin(uniforms.time * speed) * radius); + vec3 cam_target(0.0f, 0.0f, 0.0f); + vec3 cam_up(0.0f, 1.0f, 0.0f); + update_camera(cam_pos, cam_target, cam_up, 0.785398f, 0.1f, 100.0f, + uniforms.aspect_ratio); + + // Render + wgpuRenderPassEncoderSetPipeline(pass, pass_.pipeline); + wgpuRenderPassEncoderSetBindGroup(pass, 0, pass_.bind_group, 0, nullptr); + wgpuRenderPassEncoderDraw(pass, pass_.vertex_count, 1, 0, 0); +} |
