port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,395 @@
cbuffer cb0 : register(b0) {
float time;
float dummy0, dummy1, dummy2;
float3 viewPosition;
float dummy3;
float3 viewDirection;
float dummy4;
float3 viewUp;
float dummy5;
}
#define FXAA_PC 1
#define FXAA_HLSL_5 1
#define FXAA_QUALITY__PRESET 39
//12
#include "fxaa311.hlsl"
#include "utils.hlsl"
RWTexture2D<float4> out0:register(u0);
SamplerState sampler0 : register(s0);
Texture2D tex0: register(t0);
Texture2D tex1: register(t1);
Texture2D tex2: register(t2);
Texture2D tex3: register(t3);
Texture2D tex4: register(t4);
Texture2D tex5: register(t5);
Texture2D tex6: register(t6);
Texture2D tex7: register(t7);
[numthreads(16, 16, 1)] void csFXAA(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
FxaaTex tex = {sampler0 , tex0};
out0[id.xy] = FxaaPixelShader(tc, float4(0, 0, 0, 0), tex, tex, tex,
1.0/resolution, float4(0, 0, 0, 0), float4(0, 0, 0, 0), float4(0, 0, 0, 0),
0.75, 0.125, 0.0625, 0, 0, 0, 0);
}
//---
// Radial and circumferential blur
//---
static const float rcfMipmapFactor = 1.5;
static const float rcfStepFactor = 5;
static const float rcfStrengthRadial = 0*10;
static const float rcfStrengthCircumferential = 0*10;
static const float rcfRadius = 15;
static const float2 rcfCenter = {0.5, 0.5};
float rcfRadialFalloff(float radius, float amount) {
return radius * (1 + amount*radius*0.01);
}
float4 rcfBlur(float2 tc, float2 resolution, float strength, float circumFerentialStrength) {
// Direction from rcfCenter to the current tc, aspect ratio corrected
float2 d = (tc - rcfCenter) * float2(resolution.x/resolution.y, 1);
// Compute convolution step size
float delta = length(d);
float distortedDelta = rcfRadialFalloff(delta, strength);
float stepSize = abs(delta - distortedDelta) * rcfStepFactor;
float radius = rcfRadius;
// Circumferential blur
if (circumFerentialStrength > 0) {
d = float2(d.y, -d.x);
stepSize *= circumFerentialStrength;
radius = floor(rcfRadius * circumFerentialStrength);
}
// Early exit
if (radius <= 0.5) {// || stepSize <= 1/resolution.x) {
return tex0.SampleLevel(sampler0, tc, 0);
}
// Adjust direction
d = normalize(d) * stepSize / resolution;
// Convolution
float mipLevel = sqrt(stepSize) * rcfMipmapFactor;
float sigma = radius/2;
float twoSigmaSquared = 2 * sigma * sigma;
float4 a = 0;
for (float i = -radius; i <= radius; ++i) {
float weight = exp(-i*i/twoSigmaSquared);
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
return a / sqrt(twoSigmaSquared * PI);
}
[numthreads(16, 16, 1)] void csRadialBlur(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
out0[id.xy] = rcfBlur(tc, resolution, rcfStrengthRadial, 0);
}
[numthreads(16, 16, 1)] void csCircumferentialBlur(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
out0[id.xy] = rcfBlur(tc, resolution, rcfStrengthCircumferential, 1);
}
//---
// Sensor dirt
//---
[numthreads(16, 16, 1)] void csSensorDirt(int3 id:SV_DispatchThreadID) {
float2 tc = id.xy + .5;
}
//---
// Lens dirt
//---
static const float ldMinRadius = 0.025;
static const float ldMaxRadius = 0.075;
static const float ldCellWidth = 3*ldMaxRadius;
static const float ldBorderWidthHalf = 0.00125;
static const float ldSeed = 3;
static const float ldNumLayers = 4;
[numthreads(16, 16, 1)] void csLensDirt(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
tc *= float2(resolution.x/resolution.y, 1);
//float2 tc = id.xy + .5;
rndSeed = ldSeed;
float4 a = 0;
for (int i = 0; i < ldNumLayers; ++i) {
// Modulo repeat, find cell
float2 p = mod(tc, ldCellWidth) - ldCellWidth / 2;
float2 c = floor(tc / ldCellWidth);
// Backup seed
uint seedBackup = rndSeed;
// Modifiy seed with cell coordinates
rndSeed += (c.x + c.y*ldCellWidth + i*ldCellWidth*ldCellWidth) * resolution.x;
// Determine radius and jitter
float r = lerp(ldMinRadius, ldMaxRadius, rnd());
p += float2(srnd(), srnd()) * (ldCellWidth / 2 - r);
// Shapes
// Hexagon
//p = abs(p);
//float d = max(p.y + p.x*0.57735, p.x*1.1547);
// Circle
//float d = length(p);
// Pentagon
//float phi = 0.145;
//float2 n[] = {
// { sin(0*PI/5 + phi), cos(0*PI/5 + phi) },
// { sin(2*PI/5 + phi), cos(2*PI/5 + phi) },
// { sin(4*PI/5 + phi), cos(4*PI/5 + phi) },
// { sin(6*PI/5 + phi), cos(6*PI/5 + phi) },
// { sin(8*PI/5 + phi), cos(8*PI/5 + phi) }
//};
//// Difference between circumcircle and incircle radii
//float delta = r - (1 + sqrt(5)) / 4 * r;
//float d = max(max(max(max(dot(p, n[0]), dot(p, n[1])), dot(p, n[2])), dot(p, n[3])), dot(p, n[4]));
//// Mix between sphere and pentagon
//d = lerp(length(p), d+ delta, 0.5);
float d = length(p);
// Random color
a += (float4(rnd(), rnd(), rnd(), 1) + 0.5) * (smoothstep(r, r - ldBorderWidthHalf * 2, d) + 0.25 * smoothstep(ldBorderWidthHalf, 0, abs(d - r + ldBorderWidthHalf * 2)));
//a += float4(c, 0, 1)*0.1;
// Restore seed
rndSeed = seedBackup;
// Displace grid
tc += ldCellWidth / ldNumLayers;
}
//out0[id.xy] = float4(a.xyz / ldNumLayers, 1);
out0[id.xy] = float4(a.xyz / ldNumLayers, 1);
}
//---
// Blur
//---
static const float bRadius = 160;
static const float bSigma = bRadius / 3.5;
static const float bTwoSigmaSquared = 2 * bSigma * bSigma;
void bBlur(int3 id, float2 direction) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 sourceResolution;
tex0.GetDimensions(sourceResolution.x, sourceResolution.y);
float mipLevel = log2(sourceResolution.x / resolution.x);
float2 tc = (id.xy + 0.5) / resolution;
float2 d = direction / resolution;
float4 a = 0;
for (float i = -bRadius; i <= bRadius; ++i) {
float weight = exp(-i*i/bTwoSigmaSquared);
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
out0[id.xy] = a / sqrt(bTwoSigmaSquared * PI);
}
[numthreads(16, 16, 1)] void csBlurH(int3 id:SV_DispatchThreadID) { bBlur(id, float2(1,0)); }
[numthreads(16, 16, 1)] void csBlurV(int3 id:SV_DispatchThreadID) { bBlur(id, float2(0,1)); }
//---
// Streaks
//---
static const float stRadius = 160;
[numthreads(16, 16, 1)] void csStreaks(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 sourceResolution;
tex0.GetDimensions(sourceResolution.x, sourceResolution.y);
float mipLevel = log2(sourceResolution.x / resolution.x);
float2 tc = (id.xy + 0.5) / resolution;
float2 d = float2(1, 0) / resolution;
// Convolution with parabolic tent filter
float4 a = 0;
for (float i = -stRadius+1; i < stRadius; ++i) {
float weight = (stRadius - abs(i)) * (stRadius - abs(i));
a += tex0.SampleLevel(sampler0, i * d + tc, mipLevel) * weight;
}
out0[id.xy] = a * 1.5 / (stRadius * stRadius * stRadius);
}
//---
// Distort Chroma
//---
static const float dcStrength = 0.0;
static const float2 dcCenter = {0.5, 0.5};
static const int dcSamples = 24;
float dcRadialFalloff(float radius, float amount) {
return radius * (1 + amount*radius*0.01);
}
float4 dcSample(float2 tc, float amount, float2 resolution) {
// Direction from cdCenter to the current tc, aspect ratio corrected
float2 d = (tc - dcCenter) * float2(resolution.x/resolution.y, 1);
float radius = length(d);
d /= radius == 0 ? d : radius;
return tex0.SampleLevel(sampler0, dcCenter + d * dcRadialFalloff(radius, amount) / float2(resolution.x/resolution.y, 1), 0);
}
[numthreads(16, 16, 1)] void csDistortChroma(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
float4 original = tex0.SampleLevel(sampler0, tc, 0);
if (dcStrength == 0) {
out0[id.xy] = original;
return;
}
// Accumulate along spectrum
float4 a = 0;
for (int i = 1; i <= dcSamples; ++i) {
float lambda = 0.4f * (i/float(dcSamples+1)) + 0.35f;
float4 w = float4(pulse(0.65, 0.1, lambda), pulse(0.55, 0.1, lambda), pulse(0.45, 0.1, lambda), 0.25) * 4.0;
a += w * dcSample(tc, -(i-1)/float(dcSamples) * dcStrength , resolution);
}
a /= dcSamples;
out0[id.xy] = lerp(original, a, saturate(dcStrength));
}
//---
// Ghosts
//---
float4 ghRainbow(float angle) {
return float4(sin(angle), sin(angle + 3.1415*2.0/3.0), sin(angle + 3.1415*4.0/3.0), 1) * 0.5 + 0.5;
}
[numthreads(16, 16, 1)] void csGhosts(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
tc = 1 - tc;
float2 texelSize = 1 / resolution;
float2 aspectCorrection = float2(resolution.x/resolution.y, 1);
float2 direction = (0.5 - tc) * 2;
float4 a = 0;
for (int i = 0; i < 5; ++i) {
float2 sc0 = 1 - frac(tc + direction * i * 0.2);
float2 sc1 = 1 - frac(tc + direction * i * 0.1999);
float r = length((sc0 - 0.5) * aspectCorrection);
a += max(0, tex0.SampleLevel(sampler0, sc0, 0) - 0.125) * lerp(1, ghRainbow(r*20), 1.5*r);
a += max(0, tex1.SampleLevel(sampler0, sc0, 0) - 0.125) * lerp(1, ghRainbow(r*15+i), 1.5*r);
}
out0[id.xy] = float4(a.xyz/5, 1);
}
//---
// Merge
//---
float3 saturation(float3 color, float saturation) {
return lerp(dot(color, float3(0.2126, 0.7152, 0.0722)), color, saturation);
}
float3 liftGammaGain(float3 color, float3 lift, float3 gamma, float3 gain) {
return pow(saturate(gain*color + lift*(-gain*color + 1)), 1/gamma);
}
[numthreads(16, 16, 1)] void csMerge(int3 id:SV_DispatchThreadID) {
float2 resolution;
out0.GetDimensions(resolution.x, resolution.y);
float2 tc = (id.xy + 0.5) / resolution;
rndSeed = (id.y * 720 + id.x) * int(time * 1000);
float3 rndNoiseXYT = float3(rnd(), rnd(), rnd());
rndSeed = id.y;
float3 rndNoiseY = float3(rnd(), rnd(), rnd());
float3 base = tex0.SampleLevel(sampler0, tc, 0).xyz;
float3 blur1 = tex1.SampleLevel(sampler0, tc, 0).xyz;
float3 blur8 = tex2.SampleLevel(sampler0, tc, 0).xyz;
float3 blur32 = tex3.SampleLevel(sampler0, tc, 0).xyz;
float3 streaks = tex4.SampleLevel(sampler0, tc, 0).xyz;
//float3 lensDirt = tex5.SampleLevel(sampler0, tc, 0).xyz;
//float3 ghosts = tex6.SampleLevel(sampler0, tc, 0).xyz;
float3 color = base.xyz;
color += blur1 * 0.025;
color += blur8 * 0.025;
color += blur32 * 0.025;
// Streaks
color += streaks * (lerp(1, rndNoiseY.x, 0.25)) * 0.25;// * rnd();
// Lens dirt
//color += lensDirt * 0.25 * max(0, dot(tex2.SampleLevel(sampler0, frac(1-tc), 0).xyz, float3(0.299, 0.587, 0.114)) - 1.0);
// Ghosts
//color += ghosts * 0.125;// * ghosts * 0.25;
// Grain
//color *= lerp(1, rndNoiseXYT, 0.35);
//color = base;
// Tonemapping
color = max(0, uncharted2ToneMappingCompact(max(0, color*0.5)));
//color *= color;
color = liftGammaGain(color, float3(0, 0, 0), float3(1, 1, 1), float3(1, 1, 1));
//color = saturation(color, 1.5);
color = pow(color, 1/2.2);
float4 result = float4(color, dot(color, float3(0.299, 0.587, 0.114)));
out0[id.xy] = result;
}