diff options
Diffstat (limited to 'assets/shaders/tacmap/fleet.wgsl')
| -rw-r--r-- | assets/shaders/tacmap/fleet.wgsl | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/assets/shaders/tacmap/fleet.wgsl b/assets/shaders/tacmap/fleet.wgsl new file mode 100644 index 0000000..8a87fb9 --- /dev/null +++ b/assets/shaders/tacmap/fleet.wgsl @@ -0,0 +1,73 @@ +struct InstanceInput { + @location(0) rotmat_0: vec3<f32>, + @location(1) rotmat_1: vec3<f32>, + @location(2) rotmat_2: vec3<f32>, + @location(3) origin: vec3<f32>, + @location(4) offset: vec3<f32>, +}; + +struct VertexOutput { + @builtin(position) clip_position: vec4<f32>, + @location(0) color: vec3<f32> +}; + +struct CameraUniform { + view: mat4x4<f32>, + proj: mat4x4<f32>, + abs_pos: vec3<f32>, + rel_pos: vec3<f32>, + scale: f32, +}; + +@group(0) @binding(0) +var<uniform> camera: CameraUniform; + +const FLEET_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, 0.0 , 0.0), + + vec3<f32>(-1.0, 0.0, -1.0), + vec3<f32>(-1.0, 0.0, 1.0 ), + vec3<f32>(1.0, 0.0, 0.0 ), +); + +@vertex +fn vs_main( + @builtin(vertex_index) index: u32, + instance: InstanceInput +) -> VertexOutput { + var out: VertexOutput; + + let rotmat = mat3x3<f32>( + instance.rotmat_0, + instance.rotmat_1, + instance.rotmat_2 + ); + let model_pos = rotmat * FLEET_VERTICES[index] * 0.025; + var view = camera.view; + + let min_size = 0.025; + + //Scale the world around the camera scale and translate about the camera's + //absolute (/target) position + let origin_pos = instance.origin - camera.abs_pos; + let offset_pos = instance.offset - camera.rel_pos; + + let instance_pos = (offset_pos + origin_pos) * camera.scale; + let vertex_pos = instance_pos + model_pos; + + let view_proj = camera.proj * view; + let instance_vp_pos = view_proj * vec4<f32>(instance_pos, 1.0); + let model_vp_pos = view_proj * vec4<f32>(model_pos, 0.0); + + out.clip_position = instance_vp_pos + model_vp_pos; + out.color = vec3<f32>(0.75, 1.0, 0.75); + return out; +} + +@fragment +fn fs_main(in: VertexOutput +) -> @location(0) vec4<f32> { + return vec4<f32>(in.color, 1.0); +} |
