Cut 10b final polish: Aetheria 3-layer inverse-density soot & core plasma, empty-tile composite skip, foreground spark guard

This commit is contained in:
Meta Vens 2026-12-05 20:51:47 +01:00
commit 8a44da90d0
5 changed files with 208 additions and 147 deletions

View file

@ -618,7 +618,9 @@ public sealed partial class VolumetricCompositorEffect : CompositorEffect
u2.AddId(_halfVolRid);
var u3 = new RDUniform { UniformType = RenderingDevice.UniformType.Image, Binding = 3 };
u3.AddId(colorLayer);
return UniformSetCacheRD.GetCache(_compShaderRid, 0, new Godot.Collections.Array<RDUniform> { u0, u1, u2, u3 });
var u4 = new RDUniform { UniformType = RenderingDevice.UniformType.StorageBuffer, Binding = 4 };
u4.AddId(_tileSsboRid);
return UniformSetCacheRD.GetCache(_compShaderRid, 0, new Godot.Collections.Array<RDUniform> { u0, u1, u2, u3, u4 });
}
public void DisposeRdResources()

View file

@ -918,8 +918,8 @@ public sealed class VolumetricEmitterPool
public void EmitFootstepOrTirePuff(Vector3 pos, Color groundTint, float scale)
{
// Strictly gated under 104 active emitters so combat explosions never drop slots
if (ActiveEmitterCount >= 104)
// Strictly gated under 72 active emitters so combat explosions never drop slots and desert stays punchy
if (ActiveEmitterCount >= 72)
{
return;
}
@ -940,7 +940,7 @@ public sealed class VolumetricEmitterPool
temp1: 0f,
tint0: gLin * 1.1f,
tint1: gLin * 0.75f,
lifetime: 0.52f,
lifetime: 0.44f,
flowSpeed: 0.45f,
softness: 0.50f,
drag: 2.0f,

View file

@ -6,6 +6,7 @@ varying vec2 v_uvCentered;
varying vec2 v_kite;
varying float v_ageNorm;
varying float v_type;
varying float v_camFade;
void vertex() {
vec3 worldPos = MODEL_MATRIX[3].xyz;
@ -30,49 +31,59 @@ void vertex() {
vec3 camUp = INV_VIEW_MATRIX[1].xyz;
vec3 toCamVec = CAMERA_POSITION_WORLD - worldPos;
float toCamLen2 = dot(toCamVec, toCamVec);
vec3 toCam = toCamLen2 > 1e-6 ? toCamVec * inversesqrt(toCamLen2) : INV_VIEW_MATRIX[2].xyz;
if (pType > 2.5) {
// Type 3: Stationary 4-point HDR muzzle starburst
float pulse = sin(ageNorm * 3.14159265);
float sz = widthM * (0.65 + 0.45 * pulse);
vec3 displacedWorld = worldPos + camRight * (v_uvCentered.x * sz) + camUp * (v_uvCentered.y * sz);
float distToCam = sqrt(toCamLen2);
v_camFade = smoothstep(0.9, 1.8, distToCam);
if (distToCam < 0.9) {
MODELVIEW_MATRIX = VIEW_MATRIX;
VERTEX = displacedWorld;
VERTEX = worldPos;
} else {
float speed = length(velWorld);
vec3 vProj = velWorld - toCam * dot(velWorld, toCam);
float vProjLen2 = dot(vProj, vProj);
vec3 axisWorld = vProjLen2 > 1e-4 ? vProj * inversesqrt(vProjLen2) : camRight;
vec3 rawPerp = cross(toCam, axisWorld);
float rawPerpLen2 = dot(rawPerp, rawPerp);
vec3 perpWorld = rawPerpLen2 > 1e-6 ? rawPerp * inversesqrt(rawPerpLen2) : camUp;
vec3 toCam = toCamLen2 > 1e-6 ? toCamVec * inversesqrt(toCamLen2) : INV_VIEW_MATRIX[2].xyz;
float dist = sqrt(toCamLen2);
float halfWidth;
float halfLen;
if (pType > 1.5) {
// Type 2: Tiny flow-blown grit / dust mote
float minGritPx = dist * 0.0010;
halfWidth = max(clamp(widthM * (0.75 + 0.30 * ageNorm), 0.020, 0.055), minGritPx);
halfLen = halfWidth + clamp(speed * 0.006, 0.01, 0.09);
if (pType > 2.5) {
// Type 3: Stationary 4-point HDR muzzle starburst
float pulse = sin(ageNorm * 3.14159265);
float sz = widthM * (0.65 + 0.45 * pulse);
vec3 displacedWorld = worldPos + camRight * (v_uvCentered.x * sz) + camUp * (v_uvCentered.y * sz);
MODELVIEW_MATRIX = VIEW_MATRIX;
VERTEX = displacedWorld;
} else {
// Type 0 (VelocitySpark) & Type 1 (BuoyantEmber): crisp short punchy streaks (halfLen capped 0.04..0.16m)
float minSparkPx = dist * 0.0012;
halfWidth = max(clamp(widthM * mix(0.82, 0.38, ageNorm), 0.012, 0.030), minSparkPx);
float baseLen = clamp(halfWidth * 1.6 + speed * 0.008, 0.04, 0.16);
halfLen = max(halfWidth * 1.8, min(0.16, max(baseLen, minSparkPx * 2.6)));
}
float speed = length(velWorld);
vec3 vProj = velWorld - toCam * dot(velWorld, toCam);
float vProjLen2 = dot(vProj, vProj);
vec3 axisWorld = vProjLen2 > 1e-4 ? vProj * inversesqrt(vProjLen2) : camRight;
vec3 rawPerp = cross(toCam, axisWorld);
float rawPerpLen2 = dot(rawPerp, rawPerp);
vec3 perpWorld = rawPerpLen2 > 1e-6 ? rawPerp * inversesqrt(rawPerpLen2) : camUp;
vec3 displacedWorld = worldPos + axisWorld * (uKite * halfLen) + perpWorld * (vKite * halfWidth);
MODELVIEW_MATRIX = VIEW_MATRIX;
VERTEX = displacedWorld;
float dist = distToCam;
float halfWidth;
float halfLen;
if (pType > 1.5) {
// Type 2: Tiny flow-blown grit / dust mote
float minGritPx = dist * 0.0010;
halfWidth = max(clamp(widthM * (0.75 + 0.30 * ageNorm), 0.020, 0.055), minGritPx);
halfLen = halfWidth + clamp(speed * 0.006, 0.01, 0.09);
} else {
// Type 0 (VelocitySpark) & Type 1 (BuoyantEmber): crisp short punchy streaks (halfLen capped 0.04..0.16m)
float minSparkPx = dist * 0.0012;
halfWidth = max(clamp(widthM * mix(0.82, 0.38, ageNorm), 0.012, 0.030), minSparkPx);
float baseLen = clamp(halfWidth * 1.6 + speed * 0.008, 0.04, 0.16);
halfLen = max(halfWidth * 1.8, min(0.16, max(baseLen, minSparkPx * 2.6)));
}
vec3 displacedWorld = worldPos + axisWorld * (uKite * halfLen) + perpWorld * (vKite * halfWidth);
MODELVIEW_MATRIX = VIEW_MATRIX;
VERTEX = displacedWorld;
}
}
}
void fragment() {
float fade = (1.0 - v_ageNorm * v_ageNorm) * clamp(v_color.a, 0.0, 1.0);
if (v_camFade < 0.02) {
discard;
}
float fade = (1.0 - v_ageNorm * v_ageNorm) * clamp(v_color.a, 0.0, 1.0) * v_camFade;
if (fade < 0.02) {
discard;
}

View file

@ -2,6 +2,16 @@
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
#define MAX_TILE_EMITTERS 24u
struct TileData {
uint count;
float minDepth;
float maxDepth;
uint _pad;
uint packedKeys[MAX_TILE_EMITTERS];
};
layout(set = 0, binding = 0, std140) uniform VolumetricFrame {
mat4 invProj;
vec4 camPosTime;
@ -21,6 +31,9 @@ layout(set = 0, binding = 0, std140) uniform VolumetricFrame {
layout(set = 0, binding = 1) uniform sampler2D u_depthTex;
layout(set = 0, binding = 2) uniform sampler2D u_halfVolTex;
layout(set = 0, binding = 3, rgba16f) uniform image2D u_colorImg;
layout(set = 0, binding = 4, std430) readonly buffer TileBuffer {
TileData tiles[];
} u_tiles;
float linearizeReverseZ(float rawDepth) {
if (rawDepth <= 0.0) {
@ -50,6 +63,13 @@ void main() {
return;
}
// Empty-tile fast exit: coherent across the 16x16 workgroup (32x32 full-res tile)
ivec2 tileCoord = px / 32;
uint tileIdx = uint(tileCoord.y) * u_frame.tileGridParams.z + uint(tileCoord.x);
if (u_tiles.tiles[tileIdx].count == 0u) {
return;
}
ivec2 halfRes = ivec2(u_frame.tileGridParams.xy);
float dFull = linearizeReverseZ(texelFetch(u_depthTex, px, 0).r);
@ -61,6 +81,8 @@ void main() {
float depthScale = max(0.45, 0.055 * dFull);
vec4 volSum = vec4(0.0);
float wSum = 0.0;
float wRawSum = 0.0;
float minHalfDepth = 1e9;
ivec2 offsets[4] = ivec2[4](ivec2(0, 0), ivec2(1, 0), ivec2(0, 1), ivec2(1, 1));
float spatialW[4] = float[4](
@ -74,12 +96,21 @@ void main() {
ivec2 hp = min(h0 + offsets[i], halfRes - ivec2(1));
vec4 vSample = texelFetch(u_halfVolTex, hp, 0);
float dHalf = halfQuadMaxDepth(hp, fullRes);
minHalfDepth = min(minHalfDepth, dHalf);
float wDepth = exp(-abs(dFull - dHalf) / depthScale);
float w = max(1e-5, spatialW[i] * wDepth);
float wRaw = spatialW[i] * wDepth;
wRawSum += wRaw;
float w = max(1e-5, wRaw);
volSum += vSample * w;
wSum += w;
}
// Thin foreground occluder (spark/edge strictly in front of ALL 4 half-res background depth taps):
// do not smear background smoke over it
if (wRawSum < 1e-3 && dFull < minHalfDepth * 0.92) {
return;
}
vec4 vol = volSum / max(1e-5, wSum);
// Skip write when completely transparent
if (vol.a > 0.999 && dot(vol.rgb, vol.rgb) < 1e-7) {

View file

@ -358,121 +358,138 @@ void main() {
continue;
}
// Near-camera fade (0.8..3.0m) so lens-adjacent plumes never whiteout the viewport or stall raymarching
float nearFade = smoothstep(0.8, 3.0, t);
if (nearFade > 0.001) {
vec3 worldPos = ro + rd * t;
vec3 flowUv = (worldPos - u_frame.flowOriginVoxel.xyz) * u_frame.flowInvExtentDt.xyz;
vec4 flowSample = (all(greaterThanEqual(flowUv, vec3(0.0))) && all(lessThanEqual(flowUv, vec3(1.0))))
? textureLod(u_flowField, flowUv, 0.0)
: vec4(0.0);
float shock = clamp(flowSample.a, 0.0, 1.5);
// Near-camera fade (2.0..6.8m) so lens-adjacent plumes never blind the viewport or stall raymarching
if (t >= 2.0) {
float nearFade = smoothstep(2.0, 6.8, t);
if (nearFade > 0.001) {
vec3 worldPos = ro + rd * t;
vec3 flowUv = (worldPos - u_frame.flowOriginVoxel.xyz) * u_frame.flowInvExtentDt.xyz;
vec4 flowSample = (all(greaterThanEqual(flowUv, vec3(0.0))) && all(lessThanEqual(flowUv, vec3(1.0))))
? textureLod(u_flowField, flowUv, 0.0)
: vec4(0.0);
float shock = clamp(flowSample.a, 0.0, 1.5);
float rhoSum = 0.0;
vec3 albedoSum = vec3(0.0);
vec3 emissionSum = vec3(0.0);
float rhoSum = 0.0;
vec3 albedoSum = vec3(0.0);
vec3 radialSum = vec3(0.0);
float tempSum = 0.0;
float plasmaSum = 0.0;
vec3 stepCurl = aetheriaFlow(worldPos - flowSample.rgb * 0.20, 3.2, 0.65, elapsed);
uint am = activeMask;
while (am != 0u) {
int hitSlot = findLSB(am);
am &= am - 1u;
uint k = hitPack[hitSlot] & 0x1Fu;
VolumetricEmitter em = sEmitters[k];
uint am = activeMask;
while (am != 0u) {
int hitSlot = findLSB(am);
am &= am - 1u;
uint k = hitPack[hitSlot] & 0x1Fu;
VolumetricEmitter em = sEmitters[k];
uint flags = floatBitsToUint(em.params.w);
uint emType = flags & 0xFu;
float ageNorm = float((flags >> 4u) & 0xFFu) / 255.0;
float seed = float((flags >> 12u) & 0xFFu) * 0.371;
uint flags = floatBitsToUint(em.params.w);
uint emType = flags & 0xFu;
float ageNorm = float((flags >> 4u) & 0xFFu) / 255.0;
float seed = float((flags >> 12u) & 0xFFu) * 0.371;
float rA = em.posRadius.w;
float rB = em.params.y;
float radAvg = max(0.35, 0.5 * (rA + rB));
float rA = em.posRadius.w;
float rB = em.params.y;
float radAvg = max(0.35, 0.5 * (rA + rB));
// Bound flow + curl displacement strictly inside rBound (1.85 * rad) so zero spherical/tile clipping occurs
vec3 flowOffset = flowSample.rgb * (0.16 + 0.12 * ageNorm);
float fOffLen = length(flowOffset);
if (fOffLen > 0.38 * radAvg) {
flowOffset *= (0.38 * radAvg) / fOffLen;
}
vec3 advectedPos = worldPos - flowOffset;
vec3 A = em.posRadius.xyz;
vec3 B = em.endRadiusTemp.xyz;
vec3 ab = B - A;
float ab2 = dot(ab, ab);
vec3 curl = aetheriaFlow(advectedPos + vec3(seed * 13.7), max(1.5, radAvg * 1.30), abs(em.params.z), elapsed);
vec3 evalPos = advectedPos + curl * (0.42 * radAvg);
// Conservative un-displaced distance guard before running triNoise3d
float preSegT = ab2 > 1e-5 ? clamp(dot(worldPos - A, ab) / ab2, 0.0, 1.0) : 0.0;
float preRad = mix(rA, rB, preSegT);
if (length(worldPos - (A + ab * preSegT)) > 1.05 * preRad + 0.80 * radAvg) {
continue;
}
vec3 A = em.posRadius.xyz;
vec3 B = em.endRadiusTemp.xyz;
vec3 ab = B - A;
float ab2 = dot(ab, ab);
float segT = ab2 > 1e-5 ? clamp(dot(evalPos - A, ab) / ab2, 0.0, 1.0) : 0.0;
vec3 closest = A + ab * segT;
float rad = mix(rA, rB, segT);
float distNorm = length(evalPos - closest) / max(0.15, rad);
// Bound flow + curl displacement strictly inside rBound (1.85 * rad) so zero spherical/tile clipping occurs
vec3 flowOffset = flowSample.rgb * (0.16 + 0.12 * ageNorm);
float fOffLen = length(flowOffset);
if (fOffLen > 0.36 * radAvg) {
flowOffset *= (0.36 * radAvg) / fOffLen;
}
vec3 advectedPos = worldPos - flowOffset;
if (distNorm < 1.05) {
float softness = clamp(em.tintSoftness.a, 0.18, 0.75);
float baseFall = 1.0 - smoothstep(1.0 - softness, 1.04, distNorm);
// High-contrast Aetheria cauliflower billowing folds
float billow = clamp(triNoise3d(evalPos / max(1.35, rad * 0.95) + vec3(seed), elapsed * 0.36) * 1.85, 0.0, 1.0);
float rawDensity = billow * 0.62 + baseFall * 0.78 - 0.30 * distNorm;
float eroded = smoothstep(0.18, 0.72, rawDensity);
float rho_k = baseFall * eroded * em.params.x * nearFade;
float curlScale = 0.38 * radAvg * clamp(0.65 + 0.45 * abs(em.params.z), 0.5, 1.1);
vec3 evalPos = advectedPos + stepCurl * curlScale;
// Shock-front cavity carving + adiabatic compression rim
rho_k *= clamp(1.0 - shock * 0.42, 0.32, 1.0) * (1.0 + 0.45 * smoothstep(0.2, 0.9, shock));
float segT = ab2 > 1e-5 ? clamp(dot(evalPos - A, ab) / ab2, 0.0, 1.0) : 0.0;
vec3 closest = A + ab * segT;
float rad = mix(rA, rB, segT);
vec3 radialVec = evalPos - closest;
float distNorm = length(radialVec) / max(0.15, rad);
if (rho_k > 1e-4) {
rhoSum += rho_k;
albedoSum += em.tintSoftness.rgb * rho_k;
if (distNorm < 1.04) {
float softness = clamp(em.tintSoftness.a, 0.18, 0.75);
float baseFall = 1.0 - smoothstep(1.0 - softness, 1.04, distNorm);
if (baseFall > 0.04) {
// Aetheria Volumetric.cginc:201-212 sculpted pocket carving (macro triNoise3d - 0.5 * high-freq triNoise3d)
vec3 nCoord = evalPos / max(1.35, rad * 0.95) + vec3(seed);
float noise1 = triNoise3d(nCoord, elapsed * 0.36);
float noise2 = triNoise3d(nCoord * 5.5, elapsed * 0.56);
float billow = clamp((noise1 - 0.5 * noise2) * 2.55, 0.0, 1.0);
float rawDensity = billow * 0.66 + baseFall * 0.76 - 0.30 * distNorm;
float eroded = smoothstep(0.16, 0.72, rawDensity);
float rho_k = baseFall * eroded * em.params.x * nearFade;
float coreBoost = smoothstep(0.85, 0.15, distNorm);
float localTemp = max(em.endRadiusTemp.w * (0.45 + 0.85 * coreBoost) * (0.65 + 0.55 * billow), shock * 0.28);
if (localTemp > 0.16) {
vec3 bb = blackbodyRamp(localTemp);
if (emType == 3u || emType == 4u) {
// Plasma / thermal pool accent-tinted HDR emission
bb = mix(bb, em.tintSoftness.rgb * (1.55 + 2.05 * localTemp), 0.75);
// Shock-front cavity carving + adiabatic compression rim
rho_k *= clamp(1.0 - shock * 0.42, 0.32, 1.0) * (1.0 + 0.45 * smoothstep(0.2, 0.9, shock));
if (rho_k > 1e-4) {
rhoSum += rho_k;
albedoSum += em.tintSoftness.rgb * rho_k;
radialSum += safeNorm(radialVec + vec3(0.0, 0.28 * rad, 0.0)) * rho_k;
float coreBoost = smoothstep(0.85, 0.15, distNorm);
float localTemp = max(em.endRadiusTemp.w * (0.45 + 0.85 * coreBoost) * (0.65 + 0.55 * billow), shock * 0.28);
tempSum += localTemp * rho_k;
if (emType == 3u || emType == 4u) {
plasmaSum += rho_k;
}
}
emissionSum += bb * rho_k * (0.85 + 0.75 * localTemp);
}
}
}
}
if (rhoSum > 0.002) {
// 2 tile-local directional sun shadow taps along sunDir (closest 6 tile emitters)
float tauSun = 0.0;
uint shadowCount = min(sTileCount, 6u);
for (int st = 0; st < 2; st++) {
float sDist = st == 0 ? 1.2 : 3.4;
vec3 sPos = worldPos + sunDir * sDist;
for (uint j = 0u; j < shadowCount; j++) {
VolumetricEmitter se = sEmitters[j];
vec3 sA = se.posRadius.xyz;
vec3 sB = se.endRadiusTemp.xyz;
vec3 sAB = sB - sA;
float sAB2 = dot(sAB, sAB);
float sSegT = sAB2 > 1e-5 ? clamp(dot(sPos - sA, sAB) / sAB2, 0.0, 1.0) : 0.0;
float sRad = mix(se.posRadius.w, se.params.y, sSegT);
float dN = length(sPos - (sA + sAB * sSegT)) / max(0.2, sRad);
if (dN < 1.05) {
tauSun += (1.0 - smoothstep(0.25, 1.05, dN)) * se.params.x * 0.90;
if (rhoSum > 0.002) {
float rawDens = rhoSum;
float temp = tempSum / rhoSum;
vec3 albedo = albedoSum / rhoSum;
vec3 localUpOrRadial = safeNorm(radialSum);
// Layer 1 & 2: Aetheria inverse-density charcoal soot contour (CloudShader.shader:96-97)
// Thin wispy outer rims stay bright sunlit vapor (~0.85-1.0); dense mid-body folds plunge into velvety charcoal soot (~0.10-0.22)
float sootContour = 1.0 / (1.0 + 3.2 * rawDens);
float rimBias = 0.65 + 0.45 * clamp(dot(localUpOrRadial, sunDir), -1.0, 1.0);
vec3 vaporAlbedo = mix(albedo, max(albedo, vec3(0.24, 0.23, 0.22)), 0.35 * sootContour);
float vaporEdgeFade = smoothstep(0.0, 0.10, rawDens);
vec3 scatterLum = vaporAlbedo * (sootContour * vaporEdgeFade) * (sunRad * (rimBias + phase * 2.4) + ambRad * 0.48);
// Layer 3: Opposing Dense-Core HDR Plasma / Fire Emission (peaks where density AND temperature peak together)
vec3 plasmaEmit = vec3(0.0);
if (temp > 0.20) {
float coreGlow = pow(clamp(rawDens, 0.0, 1.5), 2.1) * smoothstep(0.25, 1.0, temp);
vec3 bb = blackbodyRamp(temp);
float plasmaMix = plasmaSum / rhoSum;
if (plasmaMix > 0.01) {
bb = mix(bb, albedo * (1.55 + 2.05 * temp), 0.75 * plasmaMix);
}
plasmaEmit = bb * (coreGlow * 6.5);
}
}
float sunTrans = exp(-tauSun * extScale * 1.45);
float powder = 1.0 - exp(-rhoSum * extScale * 2.2);
float lightTerm = mix(sunTrans, sunTrans * (0.45 + 1.35 * powder), 0.75);
vec3 albedo = albedoSum / rhoSum;
vec3 scatter = albedo * (sunRad * lightTerm * (0.42 + phase * 3.4) + ambRad * mix(0.28, 0.55, exp(-tauSun * 0.45)));
float sigmaT = rhoSum * extScale;
float stepTrans = exp(-sigmaT * ds);
vec3 stepLight = (scatter * sigmaT + emissionSum) * (sigmaT > 1e-4 ? (1.0 - stepTrans) / sigmaT : ds);
L += T * stepLight;
T *= stepTrans;
if (T < 0.015) {
T = 0.0;
break;
float sigmaT = rawDens * extScale;
float stepTrans = exp(-sigmaT * ds);
// CloudShader.shader:96-97: do NOT multiply scatterLum by sigmaT before dividing by sigmaT
float integDivExt = sigmaT > 1e-4 ? (1.0 - stepTrans) / sigmaT : ds;
vec3 stepLight = (scatterLum + plasmaEmit) * integDivExt * nearFade;
L += T * stepLight;
T *= stepTrans;
if (T < 0.015) {
T = 0.0;
break;
}
}
}
}