Fetching WebGPU shaders. Created my first bona fide pipeline. The vertex shader compares the built-in vertex index and the numRows/numColumns uniforms to produce a grid of quads with no vertex or index buffer whatsoever!

This commit is contained in:
Rezmason
2021-10-27 01:35:23 -07:00
parent 1827fd94a6
commit 8c62146884
3 changed files with 113 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
[[stage(fragment)]] fn main([[location(0)]] UV : vec2<f32>) -> [[location(0)]] vec4<f32> {
return vec4<f32>(0.0, UV, 1.0);
}

View File

@@ -0,0 +1,39 @@
[[block]] struct Uniforms {
numColumns: i32;
numRows: i32;
};
[[binding(0), group(0)]] var<uniform> uniforms : Uniforms;
struct VertexOutput {
[[builtin(position)]] Position : vec4<f32>;
[[location(0)]] UV : vec2<f32>;
};
[[stage(vertex)]] fn main([[builtin(vertex_index)]] VertexIndex : u32) -> VertexOutput {
var i = i32(VertexIndex);
var quadIndex = i / 6;
var cornerPosition = vec2<f32>(
f32(i % 2),
f32(((i + 1) % 6 / 3))
);
var x = uniforms.numColumns;
var position = cornerPosition;
position = position + vec2<f32>(
f32(quadIndex % uniforms.numColumns),
f32(quadIndex / uniforms.numColumns)
);
position = position / vec2<f32>(
f32(uniforms.numColumns),
f32(uniforms.numRows)
);
position = position * 2.0 - 1.0;
return VertexOutput(
vec4<f32>(position, 1.0, 1.0),
cornerPosition
);
}