Passing all the rain pass configs through a giant struct into the rain shader. I've included the compute shader fields, because I have hope that the compute pass can use the same shader module.

This commit is contained in:
Rezmason
2021-10-30 12:53:26 -07:00
parent 1516f82554
commit cc75938fcb
4 changed files with 168 additions and 55 deletions

View File

@@ -1,19 +1,53 @@
let NUM_VERTICES_PER_QUAD:i32 = 6;
let NUM_VERTICES_PER_QUAD:i32 = 6; // 2 * 3
let PI:f32 = 3.14159265359;
let TWO_PI:f32 = 6.28318530718;
let SQRT_2:f32 = 1.4142135623730951;
let SQRT_5:f32 = 2.23606797749979;
[[block]] struct Config {
numColumns: i32;
numRows: i32;
glyphHeightToWidth: f32;
// common
animationSpeed : f32;
glyphHeightToWidth : f32;
resurrectingCodeRatio : f32;
numColumns : i32;
numRows : i32;
showComputationTexture : i32;
// compute
brightnessThreshold : f32;
brightnessOverride : f32;
brightnessDecay : f32;
cursorEffectThreshold : f32;
cycleSpeed : f32;
cycleFrameSkip : i32;
fallSpeed : f32;
hasSun : i32;
hasThunder : i32;
raindropLength : f32;
rippleScale : f32;
rippleSpeed : f32;
rippleThickness : f32;
cycleStyle : i32;
rippleType : i32;
// render
forwardSpeed : f32;
glyphVerticalSpacing : f32;
glyphEdgeCrop : f32;
isPolar : i32;
density : f32;
numQuadColumns : i32;
numQuadRows : i32;
quadSize : f32;
slantScale : f32;
slantVec : vec2<f32>;
volumetric : i32;
};
[[group(0), binding(0)]] var<uniform> config:Config;
[[block]] struct MSDF {
glyphTextureColumns: i32;
glyphSequenceLength: i32;
glyphTextureColumns: i32;
};
[[group(0), binding(1)]] var<uniform> msdf:MSDF;
[[group(0), binding(2)]] var msdfSampler: sampler;
@@ -60,6 +94,9 @@ struct VertexOutput {
[[stage(vertex)]] fn vertMain([[builtin(vertex_index)]] VertexIndex:u32) -> VertexOutput {
var timePlaceholder = time.seconds;
var i = i32(VertexIndex);
var quadIndex = i / NUM_VERTICES_PER_QUAD;
@@ -68,16 +105,16 @@ struct VertexOutput {
f32(((i + 1) % NUM_VERTICES_PER_QUAD / 3))
);
var cellPosition = vec2<i32>(
quadIndex % config.numColumns,
quadIndex / config.numColumns
var quadPosition = vec2<i32>(
quadIndex % config.numQuadColumns,
quadIndex / config.numQuadColumns
);
var position = cornerPosition;
position = position + vec2<f32>(cellPosition);
position = position + vec2<f32>(quadPosition);
position = position / vec2<f32>(
f32(config.numColumns),
f32(config.numRows)
f32(config.numQuadColumns),
f32(config.numQuadRows)
);
position = 1.0 - position * 2.0;
@@ -86,8 +123,8 @@ struct VertexOutput {
var depth:f32 = 0.0;
// depth = -0.5
// + sin(time.seconds * 2.0 + f32(cellPosition.x) / f32(config.numColumns) * 10.0) * 0.2
// + sin(time.seconds * 2.0 + f32(cellPosition.y) / f32(config.numColumns) * 10.0) * 0.2;
// + sin(time.seconds * 2.0 + f32(quadPosition.x) / f32(config.numQuadColumns) * 10.0) * 0.2
// + sin(time.seconds * 2.0 + f32(quadPosition.y) / f32(config.numQuadRows) * 10.0) * 0.2;
var pos:vec4<f32> = vec4<f32>(position, depth, 1.0);
pos.x = pos.x / config.glyphHeightToWidth;
@@ -103,8 +140,8 @@ struct VertexOutput {
[[stage(fragment)]] fn fragMain([[location(0)]] UV:vec2<f32>) -> [[location(0)]] vec4<f32> {
var color:vec4<f32> = textureSample(msdfTexture, msdfSampler, UV / f32(msdf.glyphTextureColumns));
// color.b = color.b * (sin(time.seconds * TWO_PI) * 0.5 + 0.5);
color.b = color.b * f32(time.frames / 60 % 2);
color = vec4<f32>(UV, 0.5, 1.0);
return color;
}