diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-04-30 10:06:32 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-04-30 10:06:32 -0400 |
| commit | 961f8c6d405c9c6fcf9aaf4fb6f199b0e5c60d88 (patch) | |
| tree | a26797d6314fa8c193a459e988427c7bfe7f19a7 /assets/shaders | |
| parent | 25255a8b9147d27aa40b28d6aadb62c0ab275d32 (diff) | |
| download | systemic4x-961f8c6d405c9c6fcf9aaf4fb6f199b0e5c60d88.tar.gz systemic4x-961f8c6d405c9c6fcf9aaf4fb6f199b0e5c60d88.tar.bz2 systemic4x-961f8c6d405c9c6fcf9aaf4fb6f199b0e5c60d88.zip | |
add orbit rendering for bodies
Diffstat (limited to 'assets/shaders')
| -rw-r--r-- | assets/shaders/tacmap/body.wgsl (renamed from assets/shaders/tacbody.wgsl) | 33 | ||||
| -rw-r--r-- | assets/shaders/tacmap/grid.wgsl | 4 | ||||
| -rw-r--r-- | assets/shaders/tacmap/orbit.wgsl | 61 |
3 files changed, 83 insertions, 15 deletions
diff --git a/assets/shaders/tacbody.wgsl b/assets/shaders/tacmap/body.wgsl index 62adcdd..7156150 100644 --- a/assets/shaders/tacbody.wgsl +++ b/assets/shaders/tacmap/body.wgsl @@ -1,10 +1,6 @@ -struct VertexInput { - @location(0) position: vec3<f32> -}; - struct InstanceInput { - @location(2) position: vec3<f32>, - @location(3) radius: f32 + @location(0) position: vec3<f32>, + @location(1) radius: f32 }; struct VertexOutput { @@ -15,32 +11,43 @@ struct VertexOutput { struct CameraUniform { view: mat4x4<f32>, proj: mat4x4<f32>, + pos: vec3<f32>, scale: f32 }; @group(0) @binding(0) var<uniform> camera: CameraUniform; +const QUAD_VERTICES = array<vec3<f32>,6>( + vec3<f32>(-1.0, -1.0, 0.0), + vec3<f32>(-1.0, 1.0 , 0.0), + vec3<f32>(1.0, 1.0 , 0.0), + vec3<f32>(1.0, 1.0 , 0.0), + vec3<f32>(1.0, -1.0, 0.0), + vec3<f32>(-1.0, -1.0, 0.0), +); + @vertex fn vs_main( - model: VertexInput, + @builtin(vertex_index) index: u32, instance: InstanceInput ) -> VertexOutput { var out: VertexOutput; + let model = QUAD_VERTICES[index]; var view = camera.view; - + //Billboard the circle let camera_right = vec3<f32>(view[0][0], view[1][0], view[2][0]); let camera_up = vec3<f32>(view[0][1], view[1][1], view[2][1]); - let model_pos = camera_right * model.position.x + - camera_up * model.position.y; + let model_pos = camera_right * model.x + + camera_up * model.y; let min_size = 0.025; //Scale the world around the camera scale and translate about the camera's //absolute (/target) position - let instance_pos = (instance.position) * camera.scale; + let instance_pos = (instance.position - camera.pos) * camera.scale; let view_proj = camera.proj * view; @@ -50,12 +57,12 @@ fn vs_main( let vertex_dist = length(vertex_view_pos - center_view_pos) / center_view_pos.w; if vertex_dist < min_size { out.clip_position = center_view_pos / center_view_pos.w; - out.clip_position += camera.proj * vec4<f32>(model.position.xy * (min_size / 2.0), 0.0, 0.0); + out.clip_position += camera.proj * vec4<f32>(model.xy * (min_size / 2.0), 0.0, 0.0); }else{ out.clip_position = vertex_view_pos; } - out.local_position = model.position; + out.local_position = model; return out; } diff --git a/assets/shaders/tacmap/grid.wgsl b/assets/shaders/tacmap/grid.wgsl index 625dc7f..822e957 100644 --- a/assets/shaders/tacmap/grid.wgsl +++ b/assets/shaders/tacmap/grid.wgsl @@ -7,6 +7,7 @@ struct VertexOutput { struct CameraUniform { view: mat4x4<f32>, proj: mat4x4<f32>, + pos: vec3<f32>, scale: f32 }; @@ -47,7 +48,6 @@ const cell_line_thickness: f32 = 0.001; const subcell_line_thickness: f32 = 0.0001; const cell_line_color: vec4<f32> = vec4<f32>(0.25, 0.25, 0.25, 0.5); -const subcell_line_color: vec4<f32> = vec4<f32>(0.125, 0.125, 0.125, 0.5); @fragment fn fs_main(in: VertexOutput @@ -79,7 +79,7 @@ fn fs_main(in: VertexOutput var color = vec4<f32>(0.0); if subcell_dist.x < sclt_real.x || subcell_dist.y < sclt_real.y - { color = subcell_line_color * subcell_falloff; } + { color = cell_line_color * subcell_falloff; } if cell_dist.x < clt_real.x || cell_dist.y < clt_real.y { color = cell_line_color; } diff --git a/assets/shaders/tacmap/orbit.wgsl b/assets/shaders/tacmap/orbit.wgsl new file mode 100644 index 0000000..d054a05 --- /dev/null +++ b/assets/shaders/tacmap/orbit.wgsl @@ -0,0 +1,61 @@ +struct VertexInput { + @builtin(vertex_index) index: u32, + @location(0) origin: u32, + @location(1) position: vec3<f32>, +}; + +struct VertexOutput { + @builtin(position) clip_position: vec4<f32>, +}; + +struct CameraUniform { + view: mat4x4<f32>, + proj: mat4x4<f32>, + pos: vec3<f32>, + scale: f32 +}; + +@group(0) @binding(0) +var<uniform> camera: CameraUniform; + +@group(1) @binding(0) +var<storage> origins: array<array<f32,3>>; + +const POINT_NORMALS = array<vec2<f32>,4>( + vec2<f32>(0.0, -0.5), + vec2<f32>(0.0, 0.5), + vec2<f32>(0.5, -0.5), + vec2<f32>(0.5, 0.5) +); + +@vertex +fn vs_main( + model: VertexInput, +) -> VertexOutput { + var out: VertexOutput; + + let index = model.index % 4u; + let normal = POINT_NORMALS[index]; + let origin = vec3<f32>( + origins[model.origin][0], + origins[model.origin][1], + origins[model.origin][2]); + + let model_pos = (origin + model.position - camera.pos) * camera.scale; + let view_proj = camera.proj * camera.view; + + //Scale the world around the camera scale and translate about the camera's + //absolute (/target) position + + let point_view_pos = view_proj * vec4<f32>(model_pos, 1.0); + out.clip_position = point_view_pos; + out.clip_position += vec4<f32>(normal * 0.01, 0.0, 0.0) * point_view_pos.w; + + return out; +} + +@fragment +fn fs_main(in: VertexOutput +) -> @location(0) vec4<f32> { + return vec4<f32>(0.25, 1.0, 0.25, 1.0); +} |
