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,90 @@
static const float
f = 0.0535,
k = 0.062,
PI = acos(-1),
TAU = 2 * PI;
static const float3x3 conv = float3x3(.05, .2, 0.05, .2, -1, .2, .05, .2, .05);
float voronoi(float2 p)
{
float2 g = floor(p), o; p -= g;
float3 d = 1;
for (int y = -1; y <= 1; y++)
for (int x = -1; x <= 1; x++)
o = float2(x, y),
o += hash22(g + o) - p,
d.z = dot(o, o),
d.y = max(d.x, min(d.y, d.z)),
d.x = min(d.x, d.z);
return d.y - d.x;
}
//[entrypoint(cs)]
[numthreads(16, 16, 1)] void cs_Stone(uint3 i : SV_DispatchThreadID)
{
float2 dim;
o2d0.GetDimensions(dim.x, dim.y);
float2 p = i.xy / dim;
float c =
voronoi(p * 5. - .35) * .6 +
voronoi((p.yx + .5) * 10.) * .3 +
(1. - voronoi(p * 25.)) * .075 +
voronoi(p * 60.) * .025;
float4 col = t2d0[i.xy];
col.z = c;
o2d0[i.xy] = col;
}
float2 fab(int2 uv)
{
float dim = 2048.;
uv = mod2(uv, dim);
float2 ab = t2d0[uv].xy;
return float2(ab.x, max(ab.y, 0.25*step(0.98, hash12(uv / dim))));
}
float2 Laplace(int2 uv)
{
float2 result = float2(0, 0);
for (int y = -1; y <= 1; y++)
for (int x = -1; x <= 1; x++)
result += fab(uv + int2(x, y)) * conv[x + 1][y + 1];
return result;
}
//[entrypoint(cs)]
[numthreads(16, 16, 1)] void cs_Coral(uint3 i : SV_DispatchThreadID)
{
float2 ab = fab(i.xy), Lab = Laplace(i.xy);
float ab2 = ab.x * ab.y * ab.y;
ab.x += Lab.x - ab2 + f * (1.0 - ab.x);
ab.y += .5 * Lab.y + ab2 - (k + f) * ab.y;
float4 col = t2d0[i.xy];
col.xy = ab;
o2d0[i.xy] = col;
}
//[entrypoint(cs)]
[numthreads(16, 16, 1)] void cs_Caustics(uint3 i : SV_DispatchThreadID)
{
float2 dim;
o2d0.GetDimensions(dim.x, dim.y);
float d = 1315., c = 1., n = 1., t;
for (float2 uv = i.xy / dim, p = mod2(uv*TAU, TAU) - d, z = float2(p); n <= 5.; n++)
t = _s.time * (30. - (1.5 / n)),
z = p + float2(cos(t - z.x) + sin(t + z.y),
sin(t - z.y) + cos(t + z.x)),
c += d / length(float2(p.x / sin(t + z.x),
p.y / cos(t + z.y)));
c = pow(1. - c / n, 4.);
float4 col = t2d0[i.xy];
col.w = c;
o2d0[i.xy] = col;
}