mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 22:09:28 -07:00
Merged the vertex and fragment shader WGSL files, because their bindings can't collide anyhow. The rain render shader now accepts a bind group of time uniforms, which change on every frame, as well as MSDF uniforms, along with an MSDF sampler and texture that's loaded in from the PNG. The shader currently renders the correct grid of quads for volumetric mode, displays the first glyph raw in each one, and every sixty frames, turns on and off the blue channel.
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
[[stage(fragment)]] fn main([[location(0)]] UV : vec2<f32>) -> [[location(0)]] vec4<f32> {
|
||||
return vec4<f32>(0.0, UV, 1.0);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
[[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
|
||||
);
|
||||
}
|
||||
69
shaders/rainRenderPass.wgsl
Normal file
69
shaders/rainRenderPass.wgsl
Normal file
@@ -0,0 +1,69 @@
|
||||
let PI:f32 = 3.14159265359;
|
||||
let TWO_PI:f32 = 6.28318530718;
|
||||
|
||||
[[block]] struct Uniforms {
|
||||
numColumns: i32;
|
||||
numRows: i32;
|
||||
};
|
||||
[[group(0), binding(0)]] var<uniform> uniforms:Uniforms;
|
||||
|
||||
[[block]] struct MSDFUniforms {
|
||||
numColumns: i32;
|
||||
};
|
||||
[[group(1), binding(0)]] var<uniform> msdfUniforms:MSDFUniforms;
|
||||
[[group(1), binding(1)]] var msdfSampler: sampler;
|
||||
[[group(1), binding(2)]] var msdfTexture: texture_2d<f32>;
|
||||
|
||||
[[block]] struct TimeUniforms {
|
||||
time: i32;
|
||||
frame: i32;
|
||||
};
|
||||
[[group(2), binding(0)]] var<uniform> timeUniforms:TimeUniforms;
|
||||
|
||||
// Vertex shader
|
||||
|
||||
struct VertexOutput {
|
||||
[[builtin(position)]] Position:vec4<f32>;
|
||||
[[location(0)]] UV:vec2<f32>;
|
||||
};
|
||||
|
||||
[[stage(vertex)]] fn vertMain([[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 = 1.0 - position * 2.0;
|
||||
// position.x = position.x + f32(quadIndex) * 0.01;
|
||||
|
||||
return VertexOutput(
|
||||
vec4<f32>(position, 1.0, 1.0),
|
||||
cornerPosition
|
||||
);
|
||||
}
|
||||
|
||||
// Fragment shader
|
||||
|
||||
[[stage(fragment)]] fn fragMain([[location(0)]] UV:vec2<f32>) -> [[location(0)]] vec4<f32> {
|
||||
var msdf:vec4<f32> = textureSample(msdfTexture, msdfSampler, UV / f32(msdfUniforms.numColumns));
|
||||
// msdf.b = msdf.b * (sin(f32(timeUniforms.time) / 1000.0 * TWO_PI) * 0.5 + 0.5);
|
||||
msdf.b = msdf.b * f32(timeUniforms.frame / 60 % 2);
|
||||
var time = timeUniforms.time;
|
||||
|
||||
return msdf;
|
||||
}
|
||||
Reference in New Issue
Block a user