old school music tracker
1struct VertexOutput {
2 @builtin(position) position: vec4<f32>,
3 @location(0) tex_coords: vec2<f32>,
4};
5
6@vertex
7fn vs_main(
8 @builtin(vertex_index) in_vertex_index: u32,
9) -> VertexOutput {
10 const vertex_outputs: array<VertexOutput, 3> = array(
11 VertexOutput(vec4(-1.0, -1.0, 0.0, 1.0), vec2(0.0, 1.0)), // bot left corner
12 VertexOutput(vec4( 3.0, -1.0, 0.0, 1.0), vec2(2.0, 1.0)), // bot right overshoot
13 VertexOutput(vec4(-1.0, 3.0, 0.0, 1.0), vec2(0.0, -1.0)), // top left overshoot
14 );
15
16 return vertex_outputs[in_vertex_index];
17}
18
19@group(0) @binding(0) var texture: texture_2d<f32>;
20@group(0) @binding(1) var texture_sampler: sampler;
21@group(0) @binding(2) var colors: texture_1d<f32>;
22@group(0) @binding(3) var color_sampler: sampler;
23
24@fragment
25fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
26 // const colors: array<vec4<f32>, 4> = array(
27 // vec4(0., 0.2, 0.7, 0.),
28 // vec4(0.3, 0., 0.5, 0.),
29 // vec4(0.4, 0.4, 0., 0.),
30 // vec4(0.2, 0.2, 0.2, 0.),
31 // );
32 let idx = textureSample(texture, texture_sampler, in.tex_coords)[0] * 16;
33
34 return textureSample(colors, color_sampler, idx);
35 //return textureSample(texture_diffuse, sampler_diffuse, in.tex_coords);
36 // let idx = textureSample(texture_diffuse, sampler_diffuse, in.tex_coords);
37
38 // return vec4(idx[0], idx[0], idx[0], 0);
39 // return colors[u32(idx[0])];
40 // return textureLoad(texture_diffuse, in.tex_coords, 0);
41}