Arithmetic assignment operators were added

This commit is contained in:
Rezmason
2022-04-30 15:46:58 -07:00
parent 4118faca27
commit e8458a1304
6 changed files with 28 additions and 28 deletions

View File

@@ -34,11 +34,11 @@ fn gaussianPDF(x : f32) -> f32 {
var weightSum = gaussianPDF(0.0);
var sum = textureSampleLevel( tex, linearSampler, uv, 0.0) * weightSum;
for (var x : f32 = 1.0; x < config.bloomRadius; x = x + 1.0) {
for (var x : f32 = 1.0; x < config.bloomRadius; x += 1.0) {
var weight = gaussianPDF(x);
sum = sum + textureSampleLevel( tex, linearSampler, uv + uvOffset * x, 0.0) * weight;
sum = sum + textureSampleLevel( tex, linearSampler, uv - uvOffset * x, 0.0) * weight;
weightSum = weightSum + weight * 2.0;
sum += textureSampleLevel( tex, linearSampler, uv + uvOffset * x, 0.0) * weight;
sum += textureSampleLevel( tex, linearSampler, uv - uvOffset * x, 0.0) * weight;
weightSum += weight * 2.0;
}
textureStore(outputTex, coord, sum / weightSum);

View File

@@ -31,35 +31,35 @@ struct ComputeInput {
var uv = (vec2<f32>(coord) + 0.5) / vec2<f32>(outputSize);
var sum = vec4<f32>(0.0);
// for (var i = 0.0; i < config.pyramidHeight; i = i + 1.0) {
// for (var i = 0.0; i < config.pyramidHeight; i += 1.0) {
// var weight = (1.0 - i / config.pyramidHeight);
// weight = pow(weight + 0.5, 1.0 / 3.0);
// sum = sum + textureSampleLevel( tex, linearSampler, uv, i + 1.0 ) * weight;
// sum += textureSampleLevel( tex, linearSampler, uv, i + 1.0 ) * weight;
// }
{
var i = 0.0;
var weight = (1.0 - i / config.pyramidHeight);
weight = pow(weight + 0.5, 1.0 / 3.0);
sum = sum + textureSampleLevel( tex1, linearSampler, uv, i + 1.0 ) * weight;
sum += textureSampleLevel( tex1, linearSampler, uv, i + 1.0 ) * weight;
}
{
var i = 1.0;
var weight = (1.0 - i / config.pyramidHeight);
weight = pow(weight + 0.5, 1.0 / 3.0);
sum = sum + textureSampleLevel( tex2, linearSampler, uv, i + 1.0 ) * weight;
sum += textureSampleLevel( tex2, linearSampler, uv, i + 1.0 ) * weight;
}
{
var i = 2.0;
var weight = (1.0 - i / config.pyramidHeight);
weight = pow(weight + 0.5, 1.0 / 3.0);
sum = sum + textureSampleLevel( tex3, linearSampler, uv, i + 1.0 ) * weight;
sum += textureSampleLevel( tex3, linearSampler, uv, i + 1.0 ) * weight;
}
{
var i = 3.0;
var weight = (1.0 - i / config.pyramidHeight);
weight = pow(weight + 0.5, 1.0 / 3.0);
sum = sum + textureSampleLevel( tex4, linearSampler, uv, i + 1.0 ) * weight;
sum += textureSampleLevel( tex4, linearSampler, uv, i + 1.0 ) * weight;
}
textureStore(outputTex, coord, sum);

View File

@@ -60,7 +60,7 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
var brightness = brightnessRGB.r + brightnessRGB.g + brightnessRGB.b;
// Dither: subtract a random value from the brightness
brightness = brightness - randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
brightness -= randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
var paletteIndex = clamp(i32(brightness * 512.0), 0, 511);

View File

@@ -171,7 +171,7 @@ fn applyThunderBrightness(brightness : f32, simTime : f32, screenPos : vec2<f32>
thunder = log(thunder * 1.5) * 4.0;
thunder = clamp(thunder, 0.0, 1.0);
thunder = thunder * pow(screenPos.y, 2.0) * 3.0;
thunder *= pow(screenPos.y, 2.0) * 3.0;
return brightness + thunder;
}
@@ -338,8 +338,8 @@ fn computeResult (isFirstFrame : bool, previousResult : vec4<f32>, glyphPos : ve
// Calculate the vertex's world space position
var worldPosition = quadPosition * vec2<f32>(1.0, config.glyphVerticalSpacing);
worldPosition = worldPosition + quadCorner * vec2<f32>(config.density, 1.0);
worldPosition = worldPosition / quadGridSize;
worldPosition += quadCorner * vec2<f32>(config.density, 1.0);
worldPosition /= quadGridSize;
worldPosition = (worldPosition - 0.5) * 2.0;
// "Resurrected" columns are in the green channel,
@@ -353,7 +353,7 @@ fn computeResult (isFirstFrame : bool, previousResult : vec4<f32>, glyphPos : ve
// Convert the vertex's world space position to screen space
var screenPosition = vec4<f32>(worldPosition, quadDepth, 1.0);
if (volumetric) {
screenPosition.x = screenPosition.x / config.glyphHeightToWidth;
screenPosition.x /= config.glyphHeightToWidth;
screenPosition = scene.camera * scene.transform * screenPosition;
} else {
screenPosition = vec4<f32>(screenPosition.xy * scene.screenSize, screenPosition.zw);
@@ -392,9 +392,9 @@ fn getSymbolUV(glyphCycle : f32) -> vec2<f32> {
if (!volumetric) {
if (bool(config.isPolar)) {
// Curve space to make the letters appear to radiate from up above
uv = uv - 0.5;
uv = uv * 0.5;
uv.y = uv.y - 0.5;
uv -= 0.5;
uv *= 0.5;
uv.y -= 0.5;
var radius = length(uv);
var angle = atan2(uv.y, uv.x) / (2.0 * PI) + 0.5;
uv = vec2<f32>(fract(angle * 4.0 - 0.5), 1.5 * (1.0 - sqrt(radius)));
@@ -406,7 +406,7 @@ fn getSymbolUV(glyphCycle : f32) -> vec2<f32> {
(uv.y - 0.5) * config.slantVec.x - (uv.x - 0.5) * config.slantVec.y
) * config.slantScale + 0.5;
}
uv.y = uv.y / config.glyphHeightToWidth;
uv.y /= config.glyphHeightToWidth;
}
// Retrieve values from the data texture
@@ -426,15 +426,15 @@ fn getSymbolUV(glyphCycle : f32) -> vec2<f32> {
brightness = max(effect, brightness);
// In volumetric mode, distant glyphs are dimmer
if (volumetric) {
brightness = brightness * min(1.0, quadDepth);
brightness *= min(1.0, quadDepth);
}
// resolve UV to cropped position of glyph in MSDF texture
var glyphUV = fract(uv * config.gridSize);
glyphUV.y = 1.0 - glyphUV.y; // WebGL -> WebGPU y-flip
glyphUV = glyphUV - 0.5;
glyphUV = glyphUV * clamp(1.0 - config.glyphEdgeCrop, 0.0, 1.0);
glyphUV = glyphUV + 0.5;
glyphUV -= 0.5;
glyphUV *= clamp(1.0 - config.glyphEdgeCrop, 0.0, 1.0);
glyphUV += 0.5;
var msdfUV = (glyphUV + symbolUV) / vec2<f32>(config.glyphTextureGridSize);
// MSDF : calculate brightness of fragment based on distance to shape
@@ -447,7 +447,7 @@ fn getSymbolUV(glyphCycle : f32) -> vec2<f32> {
if (bool(config.showComputationTexture)) {
output.color = vec4<f32>(glyph.r - alpha, glyph.g * alpha, glyph.a - alpha, 1.0);
if (volumetric) {
output.color.g = output.color.g * 0.9 + 0.1;
output.color.g *= 0.9 + 0.1;
}
} else {
output.color = vec4<f32>(input.channel * brightness * alpha, 1.0);

View File

@@ -33,8 +33,8 @@ fn randomFloat( uv : vec2<f32> ) -> f32 {
fn rgbComponent(p : f32, q : f32, t : f32) -> f32 {
var t2 = t;
if (t2 < 0.0) { t2 = t2 + 1.0; }
if (t2 > 1.0) { t2 = t2 - 1.0; }
if (t2 < 0.0) { t2 += 1.0; }
if (t2 > 1.0) { t2 -= 1.0; }
if (t2 < 1.0 / 6.0) { return p + (q - p) * 6.0 * t2; }
if (t2 < 1.0 / 2.0) { return q; }
if (t2 < 2.0 / 3.0) { return p + (q - p) * (2.0 / 3.0 - t2) * 6.0; }
@@ -77,7 +77,7 @@ fn hslToRgb(h : f32, s : f32, l : f32) -> vec3<f32> {
) * 1.25;
// Dither: subtract a random value from the brightness
brightness = brightness - randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
brightness -= randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
// Calculate a hue based on distance from center
var hue = 0.35 + (length(vec2<f32>(uv.x, 1.0 - uv.y) - vec2<f32>(0.5, 1.0)) * -0.4 + 0.2);

View File

@@ -55,7 +55,7 @@ fn getBrightness(uv : vec2<f32>) -> vec4<f32> {
var brightness = getBrightness(uv).r;
// Dither: subtract a random value from the brightness
brightness = brightness - randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
brightness -= randomFloat( uv + vec2<f32>(time.seconds) ) * config.ditherMagnitude;
textureStore(outputTex, coord, vec4<f32>(color * brightness + config.backgroundColor, 1.0));
}