mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-18 06:09:30 -07:00
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:
3
shaders/rainPass.frag.wgsl
Normal file
3
shaders/rainPass.frag.wgsl
Normal 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);
|
||||
}
|
||||
39
shaders/rainPass.vert.wgsl
Normal file
39
shaders/rainPass.vert.wgsl
Normal 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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user