more shaders and updates/changes
This commit is contained in:
@@ -46,11 +46,16 @@ float noiseHash(float2 p)
|
||||
return frac(sin(dot(p, float2(127.1, 311.7))) * 43758.5453123);
|
||||
}
|
||||
|
||||
// Gold Noise (c)2015 dcerisano@standard3d.com, adapted for Slang.
|
||||
float goldNoise(float2 xy, float seed)
|
||||
float staticHash(float2 p)
|
||||
{
|
||||
const float phi = 1.61803398874989484820459;
|
||||
return frac(tan(distance(xy * phi, xy) * seed) * xy.x);
|
||||
float3 p3 = frac(float3(p.x, p.y, p.x) * 0.1031);
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
float seededStaticHash(float2 p, float seed)
|
||||
{
|
||||
return staticHash(p + float2(seed * 37.13, seed * 17.71));
|
||||
}
|
||||
|
||||
float grainScalar(float2 uv)
|
||||
@@ -65,11 +70,13 @@ float3 animatedChromaGrain(float2 uv, float time, float2 outputResolution, float
|
||||
// chroma blocks rather than simply lower-frequency smooth noise.
|
||||
float2 baseUv = uv * outputResolution * float2(0.85, 0.95) / safeGrainSize;
|
||||
float2 grainUv = floor(baseUv) + 0.5;
|
||||
float2 drift = float2(time * 19.7, time * 23.3);
|
||||
float frame = floor(time * 59.94);
|
||||
|
||||
float r = grainScalar(grainUv + drift + float2(13.1, 71.7));
|
||||
float g = grainScalar(grainUv * float2(1.03, 0.97) + drift * 1.11 + float2(47.2, 19.4));
|
||||
float b = grainScalar(grainUv * float2(0.96, 1.05) + drift * 0.91 + float2(83.6, 53.8));
|
||||
// Change the grain field per frame instead of drifting it through UV space;
|
||||
// continuous drift can alias into horizontal bands that march down-frame.
|
||||
float r = staticHash(grainUv + float2(frame * 17.0 + 13.1, frame * 3.0 + 71.7));
|
||||
float g = staticHash(grainUv * float2(1.03, 0.97) + float2(frame * 11.0 + 47.2, frame * 5.0 + 19.4));
|
||||
float b = staticHash(grainUv * float2(0.96, 1.05) + float2(frame * 7.0 + 83.6, frame * 13.0 + 53.8));
|
||||
|
||||
return float3(r, g, b) * 2.0 - 1.0;
|
||||
}
|
||||
@@ -111,15 +118,16 @@ float3 analogStatic(float2 uv, float time, float2 outputResolution)
|
||||
// Several differently skewed hashes keep the snow from forming obvious
|
||||
// diagonal or grid patterns at broadcast frame cadence.
|
||||
float2 goldPixel = pixel + float2(0.37, 0.61) + frame;
|
||||
float snowA = goldNoise(goldPixel, seed + 0.1);
|
||||
float snowB = goldNoise(goldPixel * float2(0.37, 2.11) + float2(19.0, 41.0), seed + 0.2);
|
||||
float snowC = goldNoise(goldPixel * float2(1.73, 0.81) + float2(53.0, 7.0), seed + 0.3);
|
||||
float snowA = seededStaticHash(goldPixel, seed + 0.1);
|
||||
float snowB = seededStaticHash(goldPixel * float2(0.37, 2.11) + float2(19.0, 41.0), seed + 0.2);
|
||||
float snowC = seededStaticHash(goldPixel * float2(1.73, 0.81) + float2(53.0, 7.0), seed + 0.3);
|
||||
float snow = (snowA * 0.72 + snowB * 0.28) * 2.0 - 1.0;
|
||||
|
||||
float lineNoise = tapeLineNoise(uv, time, safeResolution);
|
||||
float dropoutSeed = goldNoise(float2(floor(uv.y * safeResolution.y * 0.25) + 1.0, frame + 2.0), seed + 0.4);
|
||||
float dropoutSeed = seededStaticHash(float2(floor(uv.y * safeResolution.y * 0.25) + 1.0, frame + 2.0), seed + 0.4);
|
||||
float dropout = smoothstep(0.965, 1.0, dropoutSeed);
|
||||
float fleck = smoothstep(0.988, 1.0, snowA) - smoothstep(0.0, 0.012, snowC);
|
||||
float fleckSeed = seededStaticHash(pixel + float2(frame * 13.0, -frame * 7.0), seed + 0.5);
|
||||
float fleck = smoothstep(0.992, 1.0, fleckSeed) - smoothstep(0.0, 0.008, snowC);
|
||||
|
||||
float scan = sin(uv.y * safeResolution.y * 3.14159265);
|
||||
float scanMask = 0.55 + 0.45 * scan * scan;
|
||||
@@ -146,6 +154,85 @@ float3 softBloom(float2 uv, float2 outputResolution, float radius)
|
||||
return sum;
|
||||
}
|
||||
|
||||
float3 softCrossBlur(float2 uv, float2 outputResolution, float radius)
|
||||
{
|
||||
float2 pixel = 1.0 / max(outputResolution, float2(1.0, 1.0));
|
||||
float2 offset = pixel * radius;
|
||||
float3 sum = sampleVideo(frac(uv)).rgb * 0.40;
|
||||
sum += sampleVideo(frac(uv + float2(offset.x, 0.0))).rgb * 0.15;
|
||||
sum += sampleVideo(frac(uv - float2(offset.x, 0.0))).rgb * 0.15;
|
||||
sum += sampleVideo(frac(uv + float2(0.0, offset.y))).rgb * 0.15;
|
||||
sum += sampleVideo(frac(uv - float2(0.0, offset.y))).rgb * 0.15;
|
||||
return sum;
|
||||
}
|
||||
|
||||
float3 applyChromaCrawl(float3 color, float2 uv, float time, float2 outputResolution)
|
||||
{
|
||||
float amount = saturate(chromaCrawlAmount);
|
||||
if (amount <= 0.0001)
|
||||
return color;
|
||||
|
||||
float2 pixel = 1.0 / max(outputResolution, float2(1.0, 1.0));
|
||||
float lumaCenter = dot(color, float3(0.299, 0.587, 0.114));
|
||||
float lumaX = dot(sampleVideo(frac(uv + float2(pixel.x, 0.0))).rgb, float3(0.299, 0.587, 0.114));
|
||||
float lumaY = dot(sampleVideo(frac(uv + float2(0.0, pixel.y))).rgb, float3(0.299, 0.587, 0.114));
|
||||
float edge = saturate((abs(lumaX - lumaCenter) + abs(lumaY - lumaCenter)) * 6.0);
|
||||
float phase = sin(uv.y * outputResolution.y * 1.35 + time * 36.0) * cos(uv.x * outputResolution.x * 0.55 - time * 21.0);
|
||||
float2 crawlOffset = float2(phase, -phase * 0.35) * pixel * (1.0 + amount * 8.0);
|
||||
|
||||
float3 shiftedA = sampleVideo(frac(uv + crawlOffset)).rgb;
|
||||
float3 shiftedB = sampleVideo(frac(uv - crawlOffset * 0.75)).rgb;
|
||||
float3 crawled = color;
|
||||
crawled.r = lerp(color.r, shiftedA.r, edge * amount);
|
||||
crawled.b = lerp(color.b, shiftedB.b, edge * amount);
|
||||
return crawled;
|
||||
}
|
||||
|
||||
float3 applyGenerationLoss(float3 color, float2 uv, float2 outputResolution)
|
||||
{
|
||||
float loss = saturate(generationLoss);
|
||||
if (loss <= 0.0001)
|
||||
return color;
|
||||
|
||||
float3 softened = softCrossBlur(uv, outputResolution, 0.85 + loss * 2.2);
|
||||
color = lerp(color, softened, loss * 0.42);
|
||||
|
||||
float luma = dot(color, float3(0.299, 0.587, 0.114));
|
||||
float3 gray = float3(luma, luma, luma);
|
||||
color = lerp(color, gray, loss * 0.32);
|
||||
color = (color - 0.5) * (1.0 - loss * 0.18) + 0.5;
|
||||
color = color * (1.0 - loss * 0.08) + float3(0.035, 0.035, 0.04) * loss;
|
||||
return color;
|
||||
}
|
||||
|
||||
float3 applySharpnessDrift(float3 color, float2 uv, float time, float2 outputResolution)
|
||||
{
|
||||
float drift = saturate(sharpnessDrift);
|
||||
if (drift <= 0.0001)
|
||||
return color;
|
||||
|
||||
float wobble = 0.5 + 0.5 * sin(time * 1.7 + sin(time * 0.37) * 2.0);
|
||||
float radius = 0.35 + wobble * 2.25;
|
||||
float3 softened = softCrossBlur(uv, outputResolution, radius);
|
||||
return lerp(color, softened, drift * (0.35 + 0.65 * wobble));
|
||||
}
|
||||
|
||||
float3 applySubtleScanlines(float3 color, float2 uv, float time, float2 outputResolution)
|
||||
{
|
||||
float amount = saturate(scanlineAmount);
|
||||
if (amount <= 0.0001)
|
||||
return color;
|
||||
|
||||
float scan = sin((uv.y * outputResolution.y + floor(time * 59.94) * 0.5) * 3.14159265);
|
||||
float field = 0.5 + 0.5 * scan;
|
||||
float luma = dot(color, float3(0.299, 0.587, 0.114));
|
||||
float visibility = lerp(1.0, 0.45, saturate(luma));
|
||||
float modulation = 1.0 - amount * visibility * (0.35 + 0.65 * field);
|
||||
color.rgb *= modulation;
|
||||
color.rgb += amount * 0.015 * (1.0 - field);
|
||||
return color;
|
||||
}
|
||||
|
||||
float3 blurVhs(float2 uv, float d, int sampleCount)
|
||||
{
|
||||
float3 sum = float3(0.0, 0.0, 0.0);
|
||||
@@ -241,6 +328,10 @@ float4 finishVhs(ShaderContext context)
|
||||
color = lerp(color, bloomSource, bloomAmount * 0.18);
|
||||
color += bloomSource * float3(1.0, 0.96, 0.92) * bloomMask * 0.24;
|
||||
|
||||
color = applySharpnessDrift(color, context.uv, time, context.outputResolution);
|
||||
color = applyGenerationLoss(color, context.uv, context.outputResolution);
|
||||
color = applyChromaCrawl(color, context.uv, time, context.outputResolution);
|
||||
|
||||
float3 speckle = animatedChromaGrain(context.uv, time, context.outputResolution, noiseSize);
|
||||
float luma = dot(color, float3(0.299, 0.587, 0.114));
|
||||
float noiseMask = lerp(0.65, 1.0, 1.0 - saturate(luma));
|
||||
@@ -262,6 +353,8 @@ float4 finishVhs(ShaderContext context)
|
||||
color = color * (1.0 - fadeAmount * 0.08) + float3(0.055, 0.055, 0.065) * fadeAmount;
|
||||
color = lerp(color, softBloom(context.uv, context.outputResolution, 1.0 + smear), fadeAmount * 0.12);
|
||||
|
||||
color = applySubtleScanlines(color, context.uv, time, context.outputResolution);
|
||||
|
||||
float vignetteBase = context.uv.x * (1.0 - context.uv.x) * context.uv.y * (1.0 - context.uv.y);
|
||||
float vignette = saturate(pow(vignetteBase * 16.0, 0.22));
|
||||
color *= lerp(1.0 - vignetteAmount, 1.0, vignette);
|
||||
|
||||
Reference in New Issue
Block a user