Migrated changes to WebGPU

This commit is contained in:
Rezmason
2022-09-16 21:08:00 -07:00
parent ab280a95d3
commit 9ab9924294
15 changed files with 181 additions and 179 deletions

View File

@@ -2,6 +2,7 @@ struct Config {
bloomStrength : f32,
ditherMagnitude : f32,
backgroundColor : vec3<f32>,
cursorColor : vec3<f32>
};
struct Palette {
@@ -54,17 +55,19 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
var uv = vec2<f32>(coord) / vec2<f32>(screenSize);
var brightnessRGB = getBrightness(uv);
// Combine the texture and bloom
var brightness = brightnessRGB.r + brightnessRGB.g + brightnessRGB.b;
var brightness = getBrightness(uv);
// Dither: subtract a random value from the brightness
brightness -= randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
var paletteIndex = clamp(i32(brightness * 512.0), 0, 511);
// Map the brightness to a position in the palette texture
textureStore(outputTex, coord, vec4<f32>(palette.colors[paletteIndex] + config.backgroundColor, 1.0));
var paletteIndex = clamp(i32(brightness.r * 512.0), 0, 511);
textureStore(outputTex, coord, vec4<f32>(
palette.colors[paletteIndex]
+ min(config.cursorColor * brightness.g, vec3<f32>(1.0))
+ config.backgroundColor,
1.0
));
}