Mirror Grid brush placement for bodies
This commit is contained in:
parent
027d708e59
commit
babae9165b
7 changed files with 116 additions and 39 deletions
|
|
@ -32,6 +32,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const float GridTransparentMaxZ = 0.45f;
|
||||
private const int BloomLevelCount = 3;
|
||||
private const float SunRadius = 1.12f;
|
||||
private const float BodyGridClearanceRadiusScale = 2.0f;
|
||||
private const float SelfGravityRadius = 17.0f;
|
||||
private const float CursorBodyRadius = 0.56f;
|
||||
private const float CursorBodyBoundRadius = 0.72f;
|
||||
private const Format SceneHdrFormat = Format.R16G16B16A16_Float;
|
||||
|
|
@ -280,7 +282,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
|
||||
BuildGridHeightBrushes(frame);
|
||||
BuildBodyLightTable();
|
||||
BuildBodyLightTable(frame);
|
||||
var frameConstants = frameResources.UploadRing.WriteConstant(new FrameConstants(
|
||||
new Vector2(width, height),
|
||||
frame.TimeSeconds,
|
||||
|
|
@ -994,26 +996,28 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
SetGridHeightBrush(
|
||||
0,
|
||||
new Vector2(0.0f, 0.0f),
|
||||
8.5f,
|
||||
SelfGravityRadius,
|
||||
2.85f,
|
||||
-1.34f,
|
||||
0.055f,
|
||||
1.2f,
|
||||
0.74f);
|
||||
0.18f,
|
||||
MathF.Tau,
|
||||
0.82f,
|
||||
1.25f);
|
||||
|
||||
for (var index = 0; index < PlanetCount; index++)
|
||||
{
|
||||
var radius = PlanetRadius(index);
|
||||
var center = PlanetCenter(index, frame.TimeSeconds, radius);
|
||||
var center = PlanetAnchor(index, frame.TimeSeconds);
|
||||
SetGridHeightBrush(
|
||||
index + 1,
|
||||
new Vector2(center.X, center.Y),
|
||||
center,
|
||||
3.8f + radius * 2.5f,
|
||||
2.1f,
|
||||
-0.42f,
|
||||
0.022f,
|
||||
2.4f,
|
||||
1.35f);
|
||||
1.35f,
|
||||
0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1025,20 +1029,22 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
float amplitude,
|
||||
float waveAmplitude,
|
||||
float waveFrequency,
|
||||
float waveSpeed)
|
||||
float waveSpeed,
|
||||
float waveSinePower)
|
||||
{
|
||||
var centerRadius = new Vector4(center, radius, 0.0f);
|
||||
var shape = new Vector4(power, amplitude, 0.0f, 0.0f);
|
||||
var wave = new Vector4(waveAmplitude, waveFrequency, waveSpeed, 0.0f);
|
||||
var wave = new Vector4(waveAmplitude, waveFrequency, waveSpeed, waveSinePower);
|
||||
gridHeightBrushConstants.Set(index, centerRadius, shape, wave);
|
||||
gridHeightBrushes[index] = new GridHeightBrushCpu(center, radius, power, amplitude, waveAmplitude, waveFrequency, waveSpeed);
|
||||
gridHeightBrushes[index] = new GridHeightBrushCpu(center, radius, power, amplitude, waveAmplitude, waveFrequency, waveSpeed, waveSinePower);
|
||||
}
|
||||
|
||||
private void BuildBodyLightTable()
|
||||
private void BuildBodyLightTable(AquariumFrame frame)
|
||||
{
|
||||
Array.Clear(bodyLights);
|
||||
var selfCenter = BodyCenterAtGridHeight(frame, Vector2.Zero, SunRadius);
|
||||
bodyLights[0] = new BodyLightGpu(
|
||||
new Vector4(0.0f, 0.0f, 2.2f, SunRadius),
|
||||
new Vector4(selfCenter, SunRadius),
|
||||
new Vector4(10.0f, 8.7f, 4.2f, 2.0f));
|
||||
}
|
||||
|
||||
|
|
@ -1058,7 +1064,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
}
|
||||
|
||||
var well = PowerPulse(distanceValue, brush.Radius, brush.Power);
|
||||
var ripple = MathF.Sin(distanceValue * brush.WaveFrequency - frame.TimeSeconds * brush.WaveSpeed);
|
||||
var normalized = Math.Clamp(distanceValue / MathF.Max(brush.Radius, 0.001f), 0.0f, 1.0f);
|
||||
var wavePhase = brush.WaveSinePower > 0.0f
|
||||
? MathF.Pow(normalized, brush.WaveSinePower) * brush.WaveFrequency - frame.TimeSeconds * brush.WaveSpeed
|
||||
: distanceValue * brush.WaveFrequency - frame.TimeSeconds * brush.WaveSpeed;
|
||||
var ripple = brush.WaveSinePower > 0.0f ? MathF.Cos(wavePhase) : MathF.Sin(wavePhase);
|
||||
height += brush.Amplitude * well + ripple * well * brush.WaveAmplitude;
|
||||
}
|
||||
|
||||
|
|
@ -1072,6 +1082,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return shaped * shaped * (3.0f - 2.0f * shaped);
|
||||
}
|
||||
|
||||
private Vector3 BodyCenterAtGridHeight(AquariumFrame frame, Vector2 world, float radius)
|
||||
{
|
||||
return new Vector3(world.X, world.Y, EvaluateGridHeight(frame, world) + radius * BodyGridClearanceRadiusScale);
|
||||
}
|
||||
|
||||
private void SignalFrame(FrameResources frameResources)
|
||||
{
|
||||
var signalValue = ++fenceValue;
|
||||
|
|
@ -1606,20 +1621,14 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
return Lerp(0.34f, 0.62f, Hash21(index, 19.7f));
|
||||
}
|
||||
|
||||
private static Vector3 CursorCenter(AquariumFrame frame)
|
||||
{
|
||||
return new Vector3(frame.CursorWorld.X, frame.CursorWorld.Y, CursorBodyRadius);
|
||||
}
|
||||
|
||||
private static Vector3 PlanetCenter(int index, float timeSeconds, float radius)
|
||||
private static Vector2 PlanetAnchor(int index, float timeSeconds)
|
||||
{
|
||||
var f = (float)index;
|
||||
var angle = f * 0.8975979f + timeSeconds * (0.08f + 0.011f * f);
|
||||
var orbitRadius = 4.1f + f * 0.77f;
|
||||
return new Vector3(
|
||||
return new Vector2(
|
||||
MathF.Cos(angle) * orbitRadius,
|
||||
MathF.Sin(angle) * orbitRadius,
|
||||
1.15f + radius * 0.72f);
|
||||
MathF.Sin(angle) * orbitRadius);
|
||||
}
|
||||
|
||||
private static float Hash21(float x, float y)
|
||||
|
|
@ -1736,7 +1745,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
float Amplitude,
|
||||
float WaveAmplitude,
|
||||
float WaveFrequency,
|
||||
float WaveSpeed);
|
||||
float WaveSpeed,
|
||||
float WaveSinePower);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private readonly record struct BodyLightGpu(
|
||||
|
|
|
|||
|
|
@ -113,7 +113,10 @@ float D3D12GridHeightBrushPS(BrushVertexOut input) : SV_Target
|
|||
float2 world = gridWorld(saturate(input.uv));
|
||||
float distanceValue = length(world - input.centerRadius.xy);
|
||||
float well = powerPulse(distanceValue, input.centerRadius.z, input.shape.x);
|
||||
float ripple = sin(distanceValue * input.wave.y - timeSeconds * input.wave.z);
|
||||
float normalizedDistance = saturate(distanceValue / max(input.centerRadius.z, 0.001));
|
||||
float legacyPhase = distanceValue * input.wave.y - timeSeconds * input.wave.z;
|
||||
float radialPhase = pow(normalizedDistance, input.wave.w) * input.wave.y - timeSeconds * input.wave.z;
|
||||
float ripple = input.wave.w > 0.0 ? cos(radialPhase) : sin(legacyPhase);
|
||||
float signedHeight = input.shape.y * well + ripple * well * input.wave.x;
|
||||
return signedHeight;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ static const float FIELD_ID_SELF = 2.0;
|
|||
static const float FIELD_ID_GRID = 4.0;
|
||||
static const float FIELD_ID_CURSOR = 5.0;
|
||||
static const float FIELD_ID_PLANET_BASE = 10.0;
|
||||
static const float BODY_GRID_CLEARANCE_RADIUS_SCALE = 2.0;
|
||||
static const float SELF_GRAVITY_RADIUS = 17.0;
|
||||
static const float MAX_HISTORY_AGE = 32.0;
|
||||
VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
|
||||
{
|
||||
|
|
@ -128,13 +130,61 @@ float planetRadius(int index)
|
|||
return lerp(0.34, 0.62, hash21(float2(index, 19.7)));
|
||||
}
|
||||
|
||||
float3 planetCenterAt(int index, float sampleTime)
|
||||
float2 planetAnchorAt(int index, float sampleTime)
|
||||
{
|
||||
float f = (float)index;
|
||||
float angle = f * 0.8975979 + sampleTime * (0.08 + 0.011 * f);
|
||||
float radius = 4.1 + f * 0.77;
|
||||
float2 xy = float2(cos(angle), sin(angle)) * radius;
|
||||
return float3(xy, 1.15 + planetRadius(index) * 0.72);
|
||||
return float2(cos(angle), sin(angle)) * radius;
|
||||
}
|
||||
|
||||
float powerPulse(float distanceValue, float radius, float power)
|
||||
{
|
||||
float normalized = saturate(distanceValue / max(radius, 0.001));
|
||||
float shaped = pow(1.0 - normalized, power);
|
||||
return shaped * shaped * (3.0 - 2.0 * shaped);
|
||||
}
|
||||
|
||||
float gridBrushHeight(float2 world, float2 center, float radius, float power, float amplitude, float waveAmplitude, float waveFrequency, float waveSpeed, float waveSinePower, float sampleTime)
|
||||
{
|
||||
float distanceValue = length(world - center);
|
||||
if (distanceValue > radius)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float well = powerPulse(distanceValue, radius, power);
|
||||
float normalizedDistance = saturate(distanceValue / max(radius, 0.001));
|
||||
float legacyPhase = distanceValue * waveFrequency - sampleTime * waveSpeed;
|
||||
float radialPhase = pow(normalizedDistance, waveSinePower) * waveFrequency - sampleTime * waveSpeed;
|
||||
float ripple = waveSinePower > 0.0 ? cos(radialPhase) : sin(legacyPhase);
|
||||
return amplitude * well + ripple * well * waveAmplitude;
|
||||
}
|
||||
|
||||
float gridHeightAt(float2 world, float sampleTime)
|
||||
{
|
||||
float height = sin((world.x * 0.08 + world.y * 0.06) + sampleTime * 0.27)
|
||||
* sin((world.x * -0.04 + world.y * 0.07) - sampleTime * 0.19) * 0.035;
|
||||
height += gridBrushHeight(world, 0.0, SELF_GRAVITY_RADIUS, 2.85, -1.34, 0.18, 6.28318530718, 0.82, 1.25, sampleTime);
|
||||
|
||||
[unroll]
|
||||
for (int index = 0; index < PLANET_COUNT; index++)
|
||||
{
|
||||
float radius = planetRadius(index);
|
||||
height += gridBrushHeight(world, planetAnchorAt(index, sampleTime), 3.8 + radius * 2.5, 2.1, -0.42, 0.022, 2.4, 1.35, 0.0, sampleTime);
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
float3 bodyCenterAtGridHeight(float2 xy, float radius, float sampleTime)
|
||||
{
|
||||
return float3(xy, gridHeightAt(xy, sampleTime) + radius * BODY_GRID_CLEARANCE_RADIUS_SCALE);
|
||||
}
|
||||
|
||||
float3 planetCenterAt(int index, float sampleTime)
|
||||
{
|
||||
return bodyCenterAtGridHeight(planetAnchorAt(index, sampleTime), planetRadius(index), sampleTime);
|
||||
}
|
||||
|
||||
void cameraBasis(float3 camera, float2 center, out float3 forward, out float3 right, out float3 up)
|
||||
|
|
@ -167,8 +217,8 @@ float3 temporalPreviousWorldPosition(float3 worldPosition, float fieldId)
|
|||
|
||||
if (abs(fieldId - FIELD_ID_CURSOR) < 0.25)
|
||||
{
|
||||
float3 currentCenter = float3(cursorWorlds.xy, 0.56);
|
||||
float3 previousCenter = float3(cursorWorlds.zw, 0.56);
|
||||
float3 currentCenter = bodyCenterAtGridHeight(cursorWorlds.xy, 0.56, timeSeconds);
|
||||
float3 previousCenter = bodyCenterAtGridHeight(cursorWorlds.zw, 0.56, previousTimeSeconds);
|
||||
return previousCenter + (worldPosition - currentCenter);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ static const float FIELD_ID_PLANET_BASE = 10.0;
|
|||
static const int CURSOR_PRIMITIVE_ID = PLANET_COUNT + 1;
|
||||
static const float CURSOR_RADIUS = 0.56;
|
||||
static const float CURSOR_BOUND_RADIUS = 0.72;
|
||||
static const float BODY_GRID_CLEARANCE_RADIUS_SCALE = 2.0;
|
||||
static const float PI = 3.14159265359;
|
||||
static const float GRID_HEIGHT_TEXEL_COUNT = 128.0;
|
||||
static const int BODY_LIGHT_COUNT = 8;
|
||||
|
|
@ -122,13 +123,24 @@ float planetRadius(int index)
|
|||
return lerp(0.34, 0.62, hash21(float2(index, 19.7)));
|
||||
}
|
||||
|
||||
float3 planetCenterAt(int index, float sampleTime)
|
||||
float terrainHeight(float2 p);
|
||||
|
||||
float2 planetAnchorAt(int index, float sampleTime)
|
||||
{
|
||||
float f = (float)index;
|
||||
float angle = f * 0.8975979 + sampleTime * (0.08 + 0.011 * f);
|
||||
float radius = 4.1 + f * 0.77;
|
||||
float2 xy = float2(cos(angle), sin(angle)) * radius;
|
||||
return float3(xy, 1.15 + planetRadius(index) * 0.72);
|
||||
return float2(cos(angle), sin(angle)) * radius;
|
||||
}
|
||||
|
||||
float3 bodyCenterAtGridHeight(float2 xy, float radius)
|
||||
{
|
||||
return float3(xy, terrainHeight(xy) + radius * BODY_GRID_CLEARANCE_RADIUS_SCALE);
|
||||
}
|
||||
|
||||
float3 planetCenterAt(int index, float sampleTime)
|
||||
{
|
||||
return bodyCenterAtGridHeight(planetAnchorAt(index, sampleTime), planetRadius(index));
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitiveId);
|
||||
|
|
@ -223,7 +235,7 @@ float cursorLocatorSdf(float3 p)
|
|||
static const float ContactZ = -1.0;
|
||||
static const float TipZ = 1.15;
|
||||
|
||||
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
float3 center = bodyCenterAtGridHeight(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
float3 local = (p - center) / CURSOR_RADIUS;
|
||||
float2 samplePoint = float2(length(local.xy), local.z);
|
||||
float profileRadius = cursorLocatorProfileRadius(samplePoint.y);
|
||||
|
|
@ -246,7 +258,7 @@ float3 cursorLocatorNormal(float3 p)
|
|||
bool traceCursorLocator(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
|
||||
{
|
||||
float sphereTravel;
|
||||
float3 center = float3(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
float3 center = bodyCenterAtGridHeight(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
if (!traceSphere(origin, direction, center, CURSOR_BOUND_RADIUS, sphereTravel))
|
||||
{
|
||||
travel = farDistance + 1.0;
|
||||
|
|
@ -288,12 +300,12 @@ float3 primitiveCenterAt(int primitiveId, float sampleTime)
|
|||
{
|
||||
if (primitiveId == 0)
|
||||
{
|
||||
return float3(0.0, 0.0, 2.2);
|
||||
return bodyCenterAtGridHeight(0.0, SUN_RADIUS);
|
||||
}
|
||||
|
||||
if (primitiveId == CURSOR_PRIMITIVE_ID)
|
||||
{
|
||||
return float3(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
return bodyCenterAtGridHeight(cursorWorlds.xy, CURSOR_RADIUS);
|
||||
}
|
||||
|
||||
return planetCenterAt(primitiveId - 1, sampleTime);
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@
|
|||
{"timestamp":"2026-05-11T06:42:00+01:00","topic":"grid-mirror-surface","lesson":"Grid linework was replaced with a terminating perfect mirror surface. Grid hits now write the primary scene packet with FIELD_ID_GRID, terrain normal, full coverage, and Studio3 PMREM mip 0 reflection instead of using the transparent event lane.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/map.yaml","state/memory.json"]}
|
||||
{"timestamp":"2026-05-11T06:50:00+01:00","topic":"pmrem-world-basis","lesson":"Aquarium world space is Z-up while the baked Studio3 PMREM cubemap is sampled as Y-up. Every PMREM lookup must convert world directions with (x, z, y) before TextureCube sampling, or the HDRI appears sideways.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"]}
|
||||
{"timestamp":"2026-05-11T07:00:00+01:00","topic":"studio2-pmrem-probe","lesson":"Active reflection probe switched to Studio2 from E:\\Projects\\Aetheria-Economy\\Assets\\Textures\\studio2.hdr. The renderer loads Assets/Textures/studio2_pmrem.dds through the existing D3D12 TextureCube PMREM path, and the unused Studio3 DDS was cut from live assets.","files":["src/Aquarium.Engine/Assets/Textures/studio2_pmrem.dds","src/Aquarium.Engine/Assets/Textures/studio3_pmrem.dds","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/map.yaml","state/memory.json"],"source":"E:\\Projects\\Aetheria-Economy\\Assets\\Textures\\studio2.hdr"}
|
||||
{"timestamp":"2026-05-11T07:14:00+01:00","topic":"grid-brush-cpu-mirror","lesson":"Self's Grid gravity bowl now uses a 17-world-unit radius and an Aetheria-style radial cosine wave. The brush equation is mirrored across D3D12Grid, CPU body-light placement, D3D12Scene body centers, and D3D12Post temporal reprojection; body centers sit at Grid height plus 2x radius.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Grid.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","state/map.yaml","state/memory.json"],"source":"E:\\Projects\\Aetheria-Economy\\Assets\\Shaders\\Brushes\\RadialWaveBrush.shader"}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ renderer_state:
|
|||
current:
|
||||
- D3D12 default renderer behind IAquariumRenderer with explicit device/queue/swapchain, command allocators, fences, descriptor arenas, upload ring constants, tracked render targets, command events, resize rebuild, HDR/bloom/present, temporal diagnostics, and DirectWrite overlay bridge.
|
||||
- Deferred scalar Grid height target rendered from additive brush passes.
|
||||
- Self Grid brush uses a widened 17-world-unit gravity bowl plus an Aetheria-style radial cosine wave; CPU, Grid shader, scene placement, and temporal reprojection share the same brush equation.
|
||||
- Direct-traced Grid surface is a terminating perfect mirror over the scalar height field, sampling Studio2 PMREM mip 0.
|
||||
- SDF/analytic solids for Self, planets, and the cursor locator.
|
||||
- Body light buffer feeds Self emission and direct body lighting; future other Selves should join this light lane, not a generic field-instance table.
|
||||
|
|
@ -70,5 +71,5 @@ next_actions:
|
|||
- Verify publish output after every packaging-affecting change.
|
||||
- Grow renderer debug controls through the Direct2D/DirectWrite overlay path.
|
||||
- Follow research/rendering/hdr-pbr-presentation.md before changing HDR exposure, bloom, tonemapping, or display transforms.
|
||||
- Follow docs/tsr-inspired-taa-spec.md when changing current temporal diagnostics.
|
||||
- Follow docs/tsr-inspired-taa-spec.md when changing current temporal diagnostics.
|
||||
- Promote future runtime knobs into typed CultCache documents before they become process folklore.
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
"Cursor and camera interactions should project onto the same XY surface used by the Grid contract."
|
||||
],
|
||||
"rendering": [
|
||||
"D3D12 Grid line width normalization uses periodic domains with `fwidth()` and pixel-width constants, not world-space footprint guesses.",
|
||||
"Grid height is defined by the shared brush equation in CPU placement, D3D12Grid, D3D12Scene, and temporal reprojection. Self uses a 17-world-unit gravity bowl plus an Aetheria-style radial cosine wave; body centers sit at Grid height plus 2x body radius.",
|
||||
"The Grid is direct-traced as a terminating mirror surface over the scalar height field. It writes the primary surface packet with FIELD_ID_GRID, terrain normal, full coverage, and Studio2 PMREM mip 0 reflection.",
|
||||
"Mouse/cursor-owned SDF bodies need object-motion reprojection. Carry current and previous cursor world anchors through frame constants and reproject cursor hits from current center to previous center.",
|
||||
"The cursor locator uses the MathWorld teardrop curve profile with m=6, revolved around vertical: x=cos(t), y=sin(t)*sin^m(t/2), radius `sqrt(1 - x^2) * ((1 - x) / 2)^3`. Ripples belong in the SDF radius function. Material is brass GGX metal with brass-tinted F0, no diffuse metal term, non-emissive, and no ambient floor.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue