summaryrefslogtreecommitdiff
path: root/src/effects/rotating_cube_effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-16 11:54:46 +0100
committerskal <pascal.massimino@gmail.com>2026-02-16 11:54:46 +0100
commitaf5d0e4c3a6cb773a4fb51ac32f4c33a7f8d8224 (patch)
treea76464ca40a43d6042ed5431547008cfbe746c34 /src/effects/rotating_cube_effect.cc
parent8eeadaf0d5653c21b948103e4d328f634b739a17 (diff)
feat(sequence): complete v2 migration with DAG-based routing
Phase 4 complete: V1 system removed, v2 fully operational. Architecture Changes: - Explicit Node system with typed buffers (u8x4_norm, f32x4, depth24) - DAG effect routing with multi-input/multi-output support - Python compiler (seq_compiler_v2.py) with topological sort and ping-pong optimization - Compile-time node aliasing for framebuffer reuse V1 Removal (~4KB): - Deleted effect.h/cc base classes (1.4KB) - Deleted 19 v1 effect pairs: heptagon, particles, passthrough, gaussian_blur, solarize, scene1, chroma_aberration, vignette, hybrid_3d, flash_cube, theme_modulation, fade, flash, circle_mask, rotating_cube, sdf_test, distort, moving_ellipse, particle_spray (2.7KB) V2 Effects Ported: - PassthroughEffectV2, PlaceholderEffectV2 - GaussianBlurEffectV2 (multi-pass with temp nodes) - HeptagonEffectV2 (scene effect with dummy texture) - ParticlesEffectV2 (compute + render, format fixed) - RotatingCubeEffectV2 (3D with depth node) - Hybrid3DEffectV2 (Renderer3D integration, dummy textures for noise/sky) Compiler Features: - DAG validation (cycle detection, connectivity checks) - Topological sort for execution order - Ping-pong optimization (aliased node detection) - Surface-based and encoder-based RenderV2Timeline generation - init_effect_nodes() automatic generation Fixes Applied: - WebGPU binding layout validation (standard v2 post-process layout) - Surface format mismatch (ctx.format for blit, RGBA8Unorm for framebuffers) - Depth attachment compatibility (removed forced depth from gpu_create_render_pass) - Renderer3D texture initialization (created dummy 1x1 white textures) - ParticlesEffectV2 format (changed from ctx.format to RGBA8Unorm) - Encoder-based RenderV2Timeline (added missing preprocess() call) Testing: - 34/36 tests passing (2 v1-dependent tests disabled) - demo64k runs successfully (no crashes) - All seek positions work (--seek 12, --seek 15 validated) Documentation: - Updated PROJECT_CONTEXT.md (v2 status, reference to SEQUENCE_v2.md) - Added completion entry to COMPLETED.md TODO (Future): - Port CNN effects to v2 - Implement flatten mode (--flatten code generation) - Port remaining 10+ effects - Update HTML timeline editor for v2 (deferred) handoff(Claude): Sequence v2 migration complete, v1 removed, system operational. Phase 5 (editor) deferred per user preference. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/effects/rotating_cube_effect.cc')
-rw-r--r--src/effects/rotating_cube_effect.cc204
1 files changed, 0 insertions, 204 deletions
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
deleted file mode 100644
index c03eccb..0000000
--- a/src/effects/rotating_cube_effect.cc
+++ /dev/null
@@ -1,204 +0,0 @@
-// This file is part of the 64k demo project.
-// It implements RotatingCubeEffect for bump-mapped rotating cube rendering.
-// Uses auxiliary texture masking to render only inside a circular region.
-
-#include "effects/rotating_cube_effect.h"
-#include "generated/assets.h"
-#include "gpu/bind_group_builder.h"
-#include "gpu/gpu.h"
-#include "gpu/sampler_cache.h"
-#include "gpu/shader_composer.h"
-#include "util/asset_manager_utils.h"
-
-RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx) : Effect(ctx) {
-}
-
-RotatingCubeEffect::~RotatingCubeEffect() {
- // Samplers owned by SamplerCache - don't release
- if (noise_view_)
- wgpuTextureViewRelease(noise_view_);
- if (noise_texture_)
- wgpuTextureRelease(noise_texture_);
- if (bind_group_1_)
- wgpuBindGroupRelease(bind_group_1_);
- if (bind_group_0_)
- wgpuBindGroupRelease(bind_group_0_);
- if (pipeline_)
- wgpuRenderPipelineRelease(pipeline_);
-}
-
-void RotatingCubeEffect::init(MainSequence* demo) {
- demo_ = demo;
-
- uniform_buffer_ =
- gpu_create_buffer(ctx_.device, sizeof(Uniforms),
- WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst);
- object_buffer_ =
- gpu_create_buffer(ctx_.device, sizeof(ObjectData),
- WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst);
-
- TextureWithView noise = gpu_create_texture_2d(
- ctx_.device, 1, 1, WGPUTextureFormat_RGBA8Unorm,
- (WGPUTextureUsage)(WGPUTextureUsage_TextureBinding |
- WGPUTextureUsage_RenderAttachment),
- 1);
- noise_texture_ = noise.texture;
- noise_view_ = noise.view;
-
- noise_sampler_ =
- SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::linear());
- mask_sampler_ =
- SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp());
-
- size_t shader_size;
- const char* shader_code =
- (const char*)GetAsset(AssetId::ASSET_MASKED_CUBE_SHADER, &shader_size);
-
- ShaderComposer::CompositionMap composition_map;
- composition_map["render/scene_query_mode"] = "render/scene_query_linear";
- composed_shader_ = ShaderComposer::Get().Compose(
- {}, std::string(shader_code, shader_size), composition_map);
-
- WGPUShaderSourceWGSL wgsl_src = {};
- wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_src.code = str_view(composed_shader_.c_str());
-
- WGPUShaderModuleDescriptor shader_desc = {};
- shader_desc.nextInChain = &wgsl_src.chain;
- WGPUShaderModule shader_module =
- wgpuDeviceCreateShaderModule(ctx_.device, &shader_desc);
-
- WGPUBindGroupLayout bgl_0 =
- BindGroupLayoutBuilder()
- .uniform(0, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
- sizeof(Uniforms))
- .storage(1, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment,
- sizeof(ObjectData))
- .texture(3, WGPUShaderStage_Fragment)
- .sampler(4, WGPUShaderStage_Fragment)
- .build(ctx_.device);
-
- WGPUBindGroupLayout bgl_1 = BindGroupLayoutBuilder()
- .texture(0, WGPUShaderStage_Fragment)
- .sampler(1, WGPUShaderStage_Fragment)
- .build(ctx_.device);
-
- const WGPUBindGroupLayout bgls[] = {bgl_0, bgl_1};
- const WGPUPipelineLayoutDescriptor pl_desc = {
- .bindGroupLayoutCount = 2,
- .bindGroupLayouts = bgls,
- };
- WGPUPipelineLayout pipeline_layout =
- wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc);
-
- const WGPUColorTargetState color_target = {
- .format = ctx_.format,
- .writeMask = WGPUColorWriteMask_All,
- };
-
- const WGPUDepthStencilState depth_stencil = {
- .format = WGPUTextureFormat_Depth24Plus,
- .depthWriteEnabled = WGPUOptionalBool_True,
- .depthCompare = WGPUCompareFunction_Less,
- };
-
- WGPUFragmentState fragment = {};
- fragment.module = shader_module;
- fragment.entryPoint = str_view("fs_main");
- fragment.targetCount = 1;
- fragment.targets = &color_target;
-
- WGPURenderPipelineDescriptor pipeline_desc = {};
- pipeline_desc.layout = pipeline_layout;
- pipeline_desc.vertex.module = shader_module;
- pipeline_desc.vertex.entryPoint = str_view("vs_main");
- pipeline_desc.primitive.topology = WGPUPrimitiveTopology_TriangleList;
- pipeline_desc.primitive.cullMode = WGPUCullMode_None;
- pipeline_desc.depthStencil = &depth_stencil;
- pipeline_desc.multisample.count = 1;
- pipeline_desc.multisample.mask = 0xFFFFFFFF;
- pipeline_desc.fragment = &fragment;
-
- pipeline_ = wgpuDeviceCreateRenderPipeline(ctx_.device, &pipeline_desc);
- wgpuShaderModuleRelease(shader_module);
- wgpuPipelineLayoutRelease(pipeline_layout);
-
- const WGPUBindGroupEntry entries_0[] = {
- {.binding = 0,
- .buffer = uniform_buffer_.buffer,
- .size = sizeof(Uniforms)},
- {.binding = 1,
- .buffer = object_buffer_.buffer,
- .size = sizeof(ObjectData)},
- {.binding = 3, .textureView = noise_view_},
- {.binding = 4, .sampler = noise_sampler_},
- };
-
- const WGPUBindGroupDescriptor bg_desc_0 = {
- .layout = bgl_0,
- .entryCount = 4,
- .entries = entries_0,
- };
- bind_group_0_ = wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc_0);
- wgpuBindGroupLayoutRelease(bgl_0);
-
- WGPUTextureView mask_view = demo_->get_auxiliary_view("circle_mask");
- const WGPUBindGroupEntry entries_1[] = {
- {.binding = 0, .textureView = mask_view},
- {.binding = 1, .sampler = mask_sampler_},
- };
-
- const WGPUBindGroupDescriptor bg_desc_1 = {
- .layout = bgl_1,
- .entryCount = 2,
- .entries = entries_1,
- };
- bind_group_1_ = wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc_1);
- wgpuBindGroupLayoutRelease(bgl_1);
-}
-
-void RotatingCubeEffect::render(WGPURenderPassEncoder pass,
- const CommonPostProcessUniforms& u) {
- rotation_ += 0.016f * 1.5f;
-
- const vec3 camera_pos = vec3(0, 0, 5);
- const vec3 target = vec3(0, 0, 0);
- const vec3 up = vec3(0, 1, 0);
-
- const mat4 view = mat4::look_at(camera_pos, target, up);
- const float fov = 60.0f * 3.14159f / 180.0f;
- const mat4 proj = mat4::perspective(fov, u.aspect_ratio, 0.1f, 100.0f);
- const mat4 view_proj = proj * view;
-
- const quat rot = quat::from_axis(vec3(0.3f, 1.0f, 0.2f), rotation_);
- const mat4 T = mat4::translate(vec3(0, 0, 0));
- const mat4 R = rot.to_mat();
- const mat4 S = mat4::scale(vec3(1.5f, 1.5f, 1.5f));
- const mat4 model = T * R * S;
- const mat4 inv_model = model.inverse();
-
- const Uniforms uniforms = {
- .view_proj = view_proj,
- .inv_view_proj = view_proj.inverse(),
- .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, u.time),
- .params = vec4(1.0f, 0.0f, 0.0f, 0.0f),
- .resolution = u.resolution,
- };
-
- const ObjectData obj_data = {
- .model = model,
- .inv_model = inv_model,
- .color = vec4(0.8f, 0.4f, 0.2f, 1.0f),
- .params = vec4(1.0f, 0.0f, 0.0f, 0.0f),
- };
-
- wgpuQueueWriteBuffer(ctx_.queue, uniform_buffer_.buffer, 0, &uniforms,
- sizeof(Uniforms));
- wgpuQueueWriteBuffer(ctx_.queue, object_buffer_.buffer, 0, &obj_data,
- sizeof(ObjectData));
-
- wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_0_, 0, nullptr);
- wgpuRenderPassEncoderSetBindGroup(pass, 1, bind_group_1_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0);
-}