summaryrefslogtreecommitdiff
path: root/assets/final/shaders/renderer_3d.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-13 08:21:34 +0100
committerskal <pascal.massimino@gmail.com>2026-02-13 08:21:34 +0100
commiteb15703a3f87e4eadc8839b06de12b9c6ec54023 (patch)
tree06dcbb3e40df2f08b433927c96335e104b4d0aa7 /assets/final/shaders/renderer_3d.wgsl
parent10673f00dfece584ba81d581b69c9ba706a5ea5a (diff)
Refactor: Reorganize workspaces and remove assets/ directory
Workspace structure now: - workspaces/{main,test}/obj/ (3D models) - workspaces/{main,test}/shaders/ (WGSL shaders) - workspaces/{main,test}/music/ (audio samples) Changes: - Moved workspaces/*/assets/music/ → workspaces/*/music/ - Updated assets.txt paths (assets/music/ → music/) - Moved test_demo.{seq,track} to tools/ - Moved assets/originals/ → tools/originals/ - Removed assets/common/ (legacy, duplicated in workspaces) - Removed assets/final/ (legacy, superseded by workspaces) - Updated hot-reload paths in main.cc - Updated CMake references for test_demo and validation - Updated gen_spectrograms.sh paths handoff(Claude): Workspace reorganization complete
Diffstat (limited to 'assets/final/shaders/renderer_3d.wgsl')
-rw-r--r--assets/final/shaders/renderer_3d.wgsl167
1 files changed, 0 insertions, 167 deletions
diff --git a/assets/final/shaders/renderer_3d.wgsl b/assets/final/shaders/renderer_3d.wgsl
deleted file mode 100644
index d3b0bae..0000000
--- a/assets/final/shaders/renderer_3d.wgsl
+++ /dev/null
@@ -1,167 +0,0 @@
-#include "common_uniforms"
-#include "math/common_utils"
-#include "math/sdf_utils"
-
-@group(0) @binding(0) var<uniform> globals: GlobalUniforms;
-@group(0) @binding(1) var<storage, read> object_data: ObjectsBuffer;
-
-// Binding 2 is reserved for BVH buffer when enabled
-
-@group(0) @binding(3) var noise_tex: texture_2d<f32>;
-@group(0) @binding(4) var noise_sampler: sampler;
-@group(0) @binding(5) var sky_tex: texture_2d<f32>;
-
-struct VertexOutput {
- @builtin(position) position: vec4<f32>,
- @location(0) local_pos: vec3<f32>,
- @location(1) color: vec4<f32>,
- @location(2) @interpolate(flat) instance_index: u32,
- @location(3) world_pos: vec3<f32>,
- @location(4) transformed_normal: vec3<f32>,
-};
-
-@vertex
-fn vs_main(@builtin(vertex_index) vertex_index: u32,
- @builtin(instance_index) instance_index: u32) -> VertexOutput {
-
- var pos = array<vec3<f32>, 36>(
- vec3(-1.0, -1.0, 1.0), vec3( 1.0, -1.0, 1.0), vec3( 1.0, 1.0, 1.0),
- vec3(-1.0, -1.0, 1.0), vec3( 1.0, 1.0, 1.0), vec3(-1.0, 1.0, 1.0),
- vec3(-1.0, -1.0, -1.0), vec3(-1.0, 1.0, -1.0), vec3( 1.0, 1.0, -1.0),
- vec3(-1.0, -1.0, -1.0), vec3( 1.0, 1.0, -1.0), vec3( 1.0, -1.0, -1.0),
- vec3(-1.0, 1.0, -1.0), vec3(-1.0, 1.0, 1.0), vec3( 1.0, 1.0, 1.0),
- vec3(-1.0, 1.0, -1.0), vec3( 1.0, 1.0, 1.0), vec3( 1.0, 1.0, -1.0),
- vec3(-1.0, -1.0, -1.0), vec3( 1.0, -1.0, -1.0), vec3( 1.0, -1.0, 1.0),
- vec3(-1.0, -1.0, -1.0), vec3( 1.0, -1.0, 1.0), vec3(-1.0, -1.0, 1.0),
- vec3( 1.0, -1.0, -1.0), vec3( 1.0, 1.0, -1.0), vec3( 1.0, 1.0, 1.0),
- vec3( 1.0, -1.0, -1.0), vec3( 1.0, 1.0, 1.0), vec3( 1.0, -1.0, 1.0),
- vec3(-1.0, -1.0, -1.0), vec3(-1.0, -1.0, 1.0), vec3(-1.0, 1.0, 1.0),
- vec3(-1.0, -1.0, -1.0), vec3(-1.0, 1.0, 1.0), vec3(-1.0, 1.0, -1.0)
- );
-
- var p = pos[vertex_index];
- let obj = object_data.objects[instance_index];
- let obj_type = obj.params.x;
-
- if (obj_type == 5.0) { // MESH
- // For meshes, we use the actual vertex data, not proxy geometry.
- // The position here is a placeholder, the real mesh data is handled by mesh_pipeline_.
- var out: VertexOutput;
- out.position = vec4<f32>(0.0, 0.0, 2.0, 1.0); // Outside far plane, so it's not rendered by this pipeline.
- return out;
- }
-
- // Tight fit for Torus proxy hull (major radius 1.0, minor 0.4)
- if (obj_type == 3.0) {
- p.x = p.x * 1.5;
- p.z = p.z * 1.5;
- p.y = p.y * 0.5;
- }
-
- let world_pos = obj.model * vec4<f32>(p, 1.0);
- let clip_pos = globals.view_proj * world_pos;
-
- var out: VertexOutput;
- out.position = clip_pos;
- out.local_pos = p;
- out.color = obj.color;
- out.instance_index = instance_index;
- out.world_pos = world_pos.xyz;
-
- // For SDF primitives, we don't use vertex normals - they are computed analytically in the fragment shader.
- // This field is only used by the mesh pipeline (mesh_render.wgsl), not this SDF pipeline.
- out.transformed_normal = normalize(vec3<f32>(0.0, 1.0, 0.0)); // Placeholder
-
- return out;
-}
-
-#include "render/scene_query_mode"
-#include "render/shadows"
-#include "render/lighting_utils"
-#include "ray_box"
-
-struct FragmentOutput {
- @location(0) color: vec4<f32>,
- @builtin(frag_depth) depth: f32,
-};
-
-@fragment
-fn fs_main(in: VertexOutput) -> FragmentOutput {
- let obj = object_data.objects[in.instance_index];
- let obj_type = obj.params.x;
-
- var p: vec3<f32>;
- var normal: vec3<f32>;
- var base_color = in.color.rgb;
- let light_dir = normalize(vec3<f32>(1.0, 1.0, 1.0));
-
- if (obj_type <= 0.0) { // Raster path (legacy or generic)
- p = in.world_pos;
- // Use the transformed normal passed from the vertex shader for rasterized objects
- normal = normalize(in.transformed_normal);
-
- // Apply grid pattern to floor
- let uv = p.xz * 0.5;
- let grid_val = grid_pattern(uv);
- base_color = base_color * (0.5 + 0.5 * grid_val);
- } else { // SDF path
- let ro_world = globals.camera_pos_time.xyz;
- let rd_world = normalize(in.world_pos - ro_world);
-
- // Ray-Box Intersection in local space to find tight bounds
- let ro_local = (obj.inv_model * vec4<f32>(ro_world, 1.0)).xyz;
- let rd_local = normalize((obj.inv_model * vec4<f32>(rd_world, 0.0)).xyz);
-
- // Proxy box extent (matches vs_main)
- // MESHES use obj.params.yzw for extent
- var extent = vec3<f32>(1.0);
- if (obj.params.x == 3.0) { extent = vec3<f32>(1.5, 0.5, 1.5); } // Torus
- else if (obj.params.x == 5.0) { extent = obj.params.yzw; } // MESH extent
-
- let bounds = ray_box_intersection(ro_local, rd_local, extent);
-
- if (!bounds.hit) { discard; }
-
- var t = bounds.t_entry;
- var hit = false;
- for (var i = 0; i < 64; i = i + 1) {
- let q = ro_local + rd_local * t;
- let d_local = get_dist(q, obj.params);
- if (d_local < 0.0005) { hit = true; break; }
- t = t + d_local;
- if (t > bounds.t_exit) { break; }
- }
- if (!hit) { discard; }
-
- let q_hit = ro_local + rd_local * t;
- p = (obj.model * vec4<f32>(q_hit, 1.0)).xyz; // Correct world position
-
- // Calculate normal with bump mapping (using utility function)
- let disp_strength = 0.05;
- let n_local = get_normal_bump(q_hit, obj.params, noise_tex, noise_sampler, disp_strength);
- normal = transform_normal(obj.inv_model, n_local);
-
- // Apply texture to SDF color
- if (in.instance_index == 0u || obj_type == 4.0) { // Floor (index 0) or PLANE
- let uv_grid = p.xz * 0.5;
- let grid_val = grid_pattern(uv_grid);
- base_color = base_color * (0.5 + 0.5 * grid_val);
- } else {
- let uv_hit = spherical_uv(q_hit);
- let tex_val = textureSample(noise_tex, noise_sampler, uv_hit).r;
- base_color = base_color * (0.7 + 0.3 * tex_val);
- }
- }
-
- let shadow = calc_shadow(p, light_dir, 0.05, 20.0, in.instance_index);
- let lit_color = calculate_lighting(base_color, normal, p, shadow);
-
- var out: FragmentOutput;
- out.color = vec4<f32>(lit_color, 1.0);
-
- // Calculate and write correct depth
- let clip_pos = globals.view_proj * vec4<f32>(p, 1.0);
- out.depth = clip_pos.z / clip_pos.w;
-
- return out;
-} \ No newline at end of file