Use fractal reservoirs as Zyphos terrain path
This commit is contained in:
parent
c599310195
commit
5b3f1c9bb5
10 changed files with 50 additions and 35 deletions
|
|
@ -459,6 +459,8 @@ public sealed class AquariumFractalReservoirField
|
|||
|
||||
public IReadOnlyList<AquariumPackedFractalIfsTransform> ProgramTransforms { get; init; } = [];
|
||||
|
||||
public Vector4 WorldCenterRadius { get; init; }
|
||||
|
||||
public bool HasInput =>
|
||||
SplatCount > 0 &&
|
||||
Depth > 0 &&
|
||||
|
|
|
|||
|
|
@ -609,7 +609,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
activeFractalReservoirField.HasInput ? activeFractalReservoirField.SplatCount : 0,
|
||||
visibleFractalSplatCount,
|
||||
activeFractalReservoirField.HasInput ? activeFractalReservoirField.ReservoirUpdatesPerPass : 0,
|
||||
activeFractalReservoirField.HasInput ? activeFractalReservoirField.CandidatesPerReservoirUpdate : 0)));
|
||||
activeFractalReservoirField.HasInput ? activeFractalReservoirField.CandidatesPerReservoirUpdate : 0),
|
||||
activeFractalReservoirField.HasInput ? activeFractalReservoirField.WorldCenterRadius : Vector4.Zero));
|
||||
frameResources.FrameConstantsDescriptor = frameResources.TransientShaderDescriptors.Allocate();
|
||||
device.CreateConstantBufferView(
|
||||
new ConstantBufferViewDescription(frameConstants.GpuVirtualAddress, frameConstants.SizeInBytes),
|
||||
|
|
@ -2864,7 +2865,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
Vector4 CursorWorlds,
|
||||
Vector4 TemporalGaussianInfo,
|
||||
Vector4 GpuFusionInfo,
|
||||
Vector4 FractalReservoirInfo);
|
||||
Vector4 FractalReservoirInfo,
|
||||
Vector4 FractalReservoirFrame);
|
||||
|
||||
private sealed record D3D12ShaderPaths(
|
||||
string HeightField,
|
||||
|
|
|
|||
|
|
@ -85,9 +85,11 @@ float3 FractalPoint(uint index, out float radius)
|
|||
float s = transform.rotationDomain.y;
|
||||
float2 local = float2(rx * transform.radiiRotationFalloff.x, ry * transform.radiiRotationFalloff.y) * 0.65;
|
||||
float2 rotated = float2((local.x * c) - (local.y * s), (local.x * s) + (local.y * c));
|
||||
radius = max(max(transform.radiiRotationFalloff.x, transform.radiiRotationFalloff.y) * (0.34 + Random01(h + 104729u) * 0.16), 0.0001);
|
||||
float z = transform.offsetScaleAmplitude.w + (Random01(h + 1299721u) - 0.5) * radius * 0.2;
|
||||
return float3(transform.offsetScaleAmplitude.xy + rotated, z + transform.materialSeedShape.x * 0.05);
|
||||
radius = max(max(transform.radiiRotationFalloff.x, transform.radiiRotationFalloff.y) * (0.045 + Random01(h + 104729u) * 0.02), 0.0001);
|
||||
float relief = transform.offsetScaleAmplitude.w * 0.06 + (Random01(h + 1299721u) - 0.5) * radius * 0.25;
|
||||
float2 surfacePoint = transform.offsetScaleAmplitude.xy + rotated;
|
||||
float3 dir = normalize(float3(surfacePoint.x, surfacePoint.y, 1.0 + relief));
|
||||
return dir * (1.0 + relief + transform.materialSeedShape.x * 0.012);
|
||||
}
|
||||
|
||||
if (ProgramTransformCount > 0u)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ cbuffer AquariumFrame : register(b0)
|
|||
float4 temporalGaussianInfo;
|
||||
float4 gpuFusionInfo;
|
||||
float4 fractalReservoirInfo;
|
||||
float4 fractalReservoirFrame;
|
||||
};
|
||||
|
||||
struct FractalSdfSplat
|
||||
|
|
@ -71,8 +72,11 @@ struct FractalSplatVertexOut
|
|||
nointerpolation uint splatIndex : TEXCOORD0;
|
||||
float2 quad : TEXCOORD1;
|
||||
float travel : TEXCOORD2;
|
||||
float reservoirConfidence : TEXCOORD3;
|
||||
float radiosityEnergy : TEXCOORD4;
|
||||
nointerpolation float3 centerWorld : TEXCOORD3;
|
||||
nointerpolation float worldRadius : TEXCOORD4;
|
||||
nointerpolation float3 basisRight : TEXCOORD5;
|
||||
nointerpolation float3 basisUp : TEXCOORD6;
|
||||
nointerpolation float3 basisForward : TEXCOORD7;
|
||||
};
|
||||
|
||||
struct SceneOut
|
||||
|
|
@ -121,13 +125,14 @@ FractalSplatVertexOut D3D12FractalSplatVS(uint vertexId : SV_VertexID, uint inst
|
|||
float3 right;
|
||||
float3 up;
|
||||
cameraBasis(cameraPosition, cameraTarget, forward, right, up);
|
||||
float worldScale = max(viewRadius * 0.16, 0.05);
|
||||
float3 center = cameraTarget + centerRadius.xyz * worldScale;
|
||||
float fieldRadius = fractalReservoirFrame.w > 0.0 ? fractalReservoirFrame.w : max(viewRadius * 0.16, 0.05);
|
||||
float3 fieldCenter = fractalReservoirFrame.w > 0.0 ? fractalReservoirFrame.xyz : cameraTarget;
|
||||
float3 center = fieldCenter + centerRadius.xyz * fieldRadius;
|
||||
float3 delta = center - cameraPosition;
|
||||
float z = max(dot(delta, forward), 0.0001);
|
||||
float2 projected = float2(dot(delta, right), dot(delta, up)) / z * 1.6;
|
||||
float clipAspect = resolution.x / max(resolution.y, 1.0);
|
||||
float boundRadius = max(centerRadius.w * worldScale * 1.8, 0.002 * viewRadius);
|
||||
float boundRadius = max(centerRadius.w * fieldRadius * 0.72, 0.00035 * viewRadius);
|
||||
float projectedRadius = boundRadius / z * 1.6 + 0.002;
|
||||
float2 clipCenter = float2(projected.x / clipAspect, projected.y);
|
||||
float2 clipRadius = float2(projectedRadius / clipAspect, projectedRadius);
|
||||
|
|
@ -137,8 +142,11 @@ FractalSplatVertexOut D3D12FractalSplatVS(uint vertexId : SV_VertexID, uint inst
|
|||
output.splatIndex = splatIndex;
|
||||
output.quad = corners[vertexId];
|
||||
output.travel = z;
|
||||
output.reservoirConfidence = sdfResident ? saturate(sdf.validation.x) : saturate(splat.materialConfidence.w) * 0.25;
|
||||
output.radiosityEnergy = 0.0;
|
||||
output.centerWorld = center;
|
||||
output.worldRadius = boundRadius;
|
||||
output.basisRight = right;
|
||||
output.basisUp = up;
|
||||
output.basisForward = forward;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
@ -158,8 +166,11 @@ SceneOut D3D12FractalSplatPS(FractalSplatVertexOut input)
|
|||
bool sdfResident = sdf.weightTargetCount.z > 0.5;
|
||||
bool pbrResident = pbr.weightTargetCount.z > 0.5;
|
||||
bool radiosityResident = radiosity.weightTargetCount.z > 0.5;
|
||||
float falloff = sdfResident ? sdf.radiiFalloff.w : splat.radiiFalloff.w;
|
||||
float weight = pow(saturate(1.0 - r2), max(falloff * 0.35, 0.5));
|
||||
float surfaceZ = sqrt(saturate(1.0 - r2));
|
||||
float3 normal = normalize((input.basisRight * input.quad.x) + (input.basisUp * input.quad.y) - (input.basisForward * surfaceZ));
|
||||
float3 surfaceWorld = input.centerWorld + normal * input.worldRadius;
|
||||
float edgeCoverage = smoothstep(1.0, 0.82, r2);
|
||||
float viewFacing = saturate(dot(normalize(cameraPosition - surfaceWorld), normal));
|
||||
float material = saturate(splat.materialConfidence.x);
|
||||
float3 fallbackColor = lerp(float3(0.05, 0.42, 1.0), float3(1.0, 0.72, 0.18), material);
|
||||
float3 pbrColor = saturate(pbr.baseColorRoughMetal.rgb);
|
||||
|
|
@ -170,18 +181,23 @@ SceneOut D3D12FractalSplatPS(FractalSplatVertexOut input)
|
|||
pbrResident ? saturate(pbr.validation.x) : 0.0,
|
||||
radiosityResident ? saturate(radiosity.validation.x) : 0.0));
|
||||
float3 color = pbrResident ? pbrColor : fallbackColor;
|
||||
color += radiosityResident ? radiosityColor * (0.18 + reservoirConfidence * 0.35) : 0.0;
|
||||
float opacity = saturate(weight * (0.18 + reservoirConfidence * 0.28));
|
||||
float roughness = pbrResident ? saturate(pbr.baseColorRoughMetal.w) : 0.6;
|
||||
float diffuse = 0.28 + 0.72 * viewFacing;
|
||||
float fresnel = pow(saturate(1.0 - viewFacing), 5.0);
|
||||
float3 litColor = color * diffuse;
|
||||
litColor += radiosityResident ? radiosityColor * (0.24 + reservoirConfidence * 0.48) : 0.0;
|
||||
litColor += lerp(float3(0.02, 0.08, 0.14), float3(0.28, 0.42, 0.58), 1.0 - roughness) * fresnel * 0.35;
|
||||
float opacity = saturate(edgeCoverage * (0.62 + reservoirConfidence * 0.38));
|
||||
|
||||
SceneOut output;
|
||||
output.colorTravel = float4(color * opacity, min(input.travel, farDistance + 1.0));
|
||||
output.metadata = float4(FIELD_ID_FRACTAL_SPLAT_BASE, normalize(float3(input.quad, 1.0)));
|
||||
output.colorTravel = float4(litColor * opacity, min(input.travel - surfaceZ * input.worldRadius, farDistance + 1.0));
|
||||
output.metadata = float4(FIELD_ID_FRACTAL_SPLAT_BASE, normal);
|
||||
output.control = float4(opacity, reservoirConfidence, saturate((sdfResident ? sdf.centerRadius.w : splat.centerRadius.w) * 40.0), 0.0);
|
||||
output.reservoirGuide = float4(
|
||||
sdfResident ? saturate(sdf.validation.x) : 0.0,
|
||||
pbrResident ? saturate(pbr.validation.x) : 0.0,
|
||||
radiosityResident ? saturate(radiosity.validation.x) : 0.0,
|
||||
reservoirConfidence);
|
||||
output.depth = saturate(input.travel / max(farDistance, 0.0001));
|
||||
output.depth = saturate((input.travel - surfaceZ * input.worldRadius) / max(farDistance, 0.0001));
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ public static class ZyphosRenderPlan
|
|||
var app = new AquariumApp();
|
||||
app.Shaders
|
||||
.Core("D3D12HeightField.hlsl", "D3D12Scene.hlsl", "D3D12Post.hlsl")
|
||||
.SdfShader("D3D12ZyphosPlanet.hlsl")
|
||||
.SdfShader("D3D12ZyphosUmbros.hlsl")
|
||||
.SdfShader("D3D12ZyphosStar.hlsl");
|
||||
|
||||
var heightField = app.RenderTargets.Create("height-field")
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ public static class ZyphosSceneBuilder
|
|||
FractalReservoirField = new AquariumFractalReservoirField
|
||||
{
|
||||
SplatCount = 2_000_000,
|
||||
ReservoirUpdatesPerPass = 50_000,
|
||||
ReservoirUpdatesPerPass = 20_000,
|
||||
WorldCenterRadius = new Vector4(ZyphosUmbrosSystem.ZyphosCenter, ZyphosUmbrosSystem.ZyphosSurfaceRadius),
|
||||
ProgramTransforms = fractalPlan.GpuProgramTransforms,
|
||||
},
|
||||
SdfObjects = BuildSdfObjects(timeSeconds, previousTimeSeconds),
|
||||
|
|
@ -25,22 +26,11 @@ public static class ZyphosSceneBuilder
|
|||
|
||||
private static AquariumSdfObject[] BuildSdfObjects(float timeSeconds, float previousTimeSeconds)
|
||||
{
|
||||
var planetCenter = ZyphosUmbrosSystem.ZyphosCenter;
|
||||
var rotation = ZyphosUmbrosSystem.MutualPhase(timeSeconds);
|
||||
var umbrosCenter = ZyphosUmbrosSystem.UmbrosCenter(timeSeconds);
|
||||
var previousUmbrosCenter = ZyphosUmbrosSystem.UmbrosCenter(previousTimeSeconds);
|
||||
var starCenter = ZyphosUmbrosSystem.PrimaryStarCenter(timeSeconds);
|
||||
var previousStarCenter = ZyphosUmbrosSystem.PrimaryStarCenter(previousTimeSeconds);
|
||||
|
||||
var objects = new AquariumSdfObject[ZyphosRenderPlan.SdfObjectCount];
|
||||
objects[ZyphosRenderPlan.PlanetIndex] = new AquariumSdfObject(
|
||||
new Vector4(planetCenter, ZyphosUmbrosSystem.ZyphosBoundRadius),
|
||||
new Vector4(planetCenter, 0.0f),
|
||||
new Vector4(ZyphosUmbrosSystem.ZyphosSurfaceRadius, rotation, ZyphosUmbrosSystem.SeaLevel, rotation));
|
||||
objects[ZyphosRenderPlan.UmbrosIndex] = new AquariumSdfObject(
|
||||
new Vector4(umbrosCenter, ZyphosUmbrosSystem.UmbrosBoundRadius),
|
||||
new Vector4(previousUmbrosCenter, 0.0f),
|
||||
new Vector4(ZyphosUmbrosSystem.UmbrosSurfaceRadius, rotation, ZyphosUmbrosSystem.CenterSeparation, 0.0f));
|
||||
objects[ZyphosRenderPlan.StarIndex] = new AquariumSdfObject(
|
||||
new Vector4(starCenter, ZyphosUmbrosSystem.PrimaryStarVisualRadius),
|
||||
new Vector4(previousStarCenter, 0.0f),
|
||||
|
|
|
|||
Loading…
Reference in a new issue