Split body SDF rendering from scene shader

This commit is contained in:
Meta Vens 2026-05-11 22:08:34 +01:00
commit 408244c7ce
9 changed files with 814 additions and 772 deletions

View file

@ -7,10 +7,14 @@ explicit frame graph.
1. `D3D12Grid.hlsl` renders a 128x128 scalar Grid height target.
2. `D3D12Scene.hlsl` traces the background and Grid into scene-linear HDR
targets, then draws one bounded proxy quad per visible body.
3. `D3D12Post.hlsl` builds bloom, resolves diagnostics/history, applies
targets.
3. `D3D12Bodies.hlsl` draws one bounded proxy quad per visible body and
raymarches only that object. Reusable SDF functions live in
`D3D12SdfMath.hlsli`; current role character SDFs live in
`D3D12AgentCharacters.hlsli`.
4. `D3D12Post.hlsl` builds bloom, resolves diagnostics/history, applies
exposure and ACES, then presents.
4. `DirectWriteOverlay` draws crisp final-pixel debug UI after scene rendering.
5. `DirectWriteOverlay` draws crisp final-pixel debug UI after scene rendering.
C# feeds explicit frame constants: resolution, time, Grid radius, camera
position, presentation controls, previous frame state, cursor anchors, and debug
@ -46,10 +50,11 @@ the fixed orbit fallback, renders Body and Imagination as LOD 1 role SDFs inside
bounded per-object proxy draws, and keeps the remaining roles as simple distinct
fallback organs.
The cursor is a revolved MathWorld teardrop SDF with SDF ripples and brass GGX
material. It carries current and previous cursor world anchors so temporal
reprojection can account for object motion. Agent visuals carry their previous
centers in the structured buffer for the same reason.
The cursor is a luminous three-lobed hibiscus SDF that lives on the XY plane:
its center is one cursor radius above XY, so its lower contact tip lands at
Grid z=0 instead of sampling the Grid height field. The previous MathWorld
teardrop formula remains in `D3D12SdfMath.hlsli` for later reuse. Agent visuals
carry their previous centers in the structured buffer for temporal reprojection.
Lighting is currently direct and diegetic: Self is the emitter. No ambient fill
is allowed to quietly solve a bad light story.

View file

@ -41,6 +41,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
private const Format SceneHdrFormat = Format.R16G16B16A16_Float;
private const string GridShaderRelativePath = "Render/Shaders/D3D12Grid.hlsl";
private const string SceneShaderRelativePath = "Render/Shaders/D3D12Scene.hlsl";
private const string BodiesShaderRelativePath = "Render/Shaders/D3D12Bodies.hlsl";
private const string SdfMathShaderRelativePath = "Render/Shaders/D3D12SdfMath.hlsli";
private const string AgentCharactersShaderRelativePath = "Render/Shaders/D3D12AgentCharacters.hlsli";
private const string PostShaderRelativePath = "Render/Shaders/D3D12Post.hlsl";
private const string StudioPmremRelativePath = "Assets/Textures/studio2_pmrem.dds";
private const string StudioIrradianceRelativePath = "Assets/Textures/studio2_irradiance.dds";
@ -599,7 +602,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
gridHeightBrush.Name = "Aquarium D3D12 Grid Height Brush Pipeline";
var scene = CreateScenePipelineState(paths.Scene);
scene.Name = "Aquarium D3D12 Scene Pipeline";
var agentProxy = CreateAgentProxyPipelineState(paths.Scene);
var agentProxy = CreateAgentProxyPipelineState(paths.Bodies);
agentProxy.Name = "Aquarium D3D12 Agent Proxy Pipeline";
var bloomPrefilter = CreateBloomPrefilterPipelineState(paths.Post);
bloomPrefilter.Name = "Aquarium D3D12 Bloom Prefilter Pipeline";
@ -1140,11 +1143,8 @@ public sealed class D3D12Renderer : IAquariumRenderer
new Vector4(1.0f, 1.0f, 0.0f, 0.0f),
new Vector4(0.0f, SelfObjectIndex, 1.0f, 0.0f));
var cursorCenter = BodyCenterAtGridHeight(frame, frame.CursorWorld, CursorBodyRadius);
var previousCursorCenter = BodyCenterAtGridHeight(
new AquariumFrame(frame.Grid, previousCameraPosition, previousTimeSeconds, previousCursorWorld),
previousCursorWorld,
CursorBodyRadius);
var cursorCenter = new Vector3(frame.CursorWorld, CursorBodyRadius);
var previousCursorCenter = new Vector3(previousCursorWorld, CursorBodyRadius);
agentVisuals[CursorObjectIndex] = new AgentVisualGpu(
new Vector4(cursorCenter, CursorBodyBoundRadius),
new Vector4(previousCursorCenter, -1.0f),
@ -1795,7 +1795,45 @@ public sealed class D3D12Renderer : IAquariumRenderer
shaderFlags |= ShaderFlags.Debug | ShaderFlags.SkipOptimization;
#endif
return Compiler.CompileFromFile(path, entryPoint, profile, shaderFlags, EffectFlags.None);
var source = ExpandShaderIncludes(path, []);
return Compiler.Compile(source, entryPoint, path, profile, shaderFlags, EffectFlags.None);
}
private static string ExpandShaderIncludes(string path, HashSet<string> stack)
{
var fullPath = Path.GetFullPath(path);
if (!stack.Add(fullPath))
{
throw new InvalidOperationException($"Circular shader include detected at {fullPath}");
}
var lines = File.ReadAllLines(fullPath);
var expanded = new List<string>(lines.Length);
var directory = Path.GetDirectoryName(fullPath) ?? AppContext.BaseDirectory;
for (var lineIndex = 0; lineIndex < lines.Length; lineIndex++)
{
var line = lines[lineIndex];
var trimmed = line.TrimStart();
if (trimmed.StartsWith("#include \"", StringComparison.Ordinal))
{
var firstQuote = trimmed.IndexOf('"');
var secondQuote = trimmed.IndexOf('"', firstQuote + 1);
if (firstQuote >= 0 && secondQuote > firstQuote)
{
var includeName = trimmed.Substring(firstQuote + 1, secondQuote - firstQuote - 1);
var includePath = Path.GetFullPath(Path.Combine(directory, includeName));
expanded.Add($"#line 1 \"{includePath.Replace("\\", "\\\\")}\"");
expanded.Add(ExpandShaderIncludes(includePath, stack));
expanded.Add($"#line {lineIndex + 2} \"{fullPath.Replace("\\", "\\\\")}\"");
continue;
}
}
expanded.Add(line);
}
stack.Remove(fullPath);
return string.Join(Environment.NewLine, expanded);
}
private static float AgentRadius(int index)
@ -2000,15 +2038,21 @@ public sealed class D3D12Renderer : IAquariumRenderer
private sealed record D3D12ShaderPaths(
string Grid,
string Scene,
string Bodies,
string SdfMath,
string AgentCharacters,
string Post)
{
public IReadOnlyList<string> All { get; } = [Grid, Scene, Post];
public IReadOnlyList<string> All { get; } = [Grid, Scene, Bodies, SdfMath, AgentCharacters, Post];
public static D3D12ShaderPaths FromRoot(string root)
{
return new D3D12ShaderPaths(
Path.Combine(root, Path.GetFileName(GridShaderRelativePath)),
Path.Combine(root, Path.GetFileName(SceneShaderRelativePath)),
Path.Combine(root, Path.GetFileName(BodiesShaderRelativePath)),
Path.Combine(root, Path.GetFileName(SdfMathShaderRelativePath)),
Path.Combine(root, Path.GetFileName(AgentCharactersShaderRelativePath)),
Path.Combine(root, Path.GetFileName(PostShaderRelativePath)));
}
}

View file

@ -0,0 +1,79 @@
#ifndef AQUARIUM_D3D12_AGENT_CHARACTERS_HLSLI
#define AQUARIUM_D3D12_AGENT_CHARACTERS_HLSLI
struct AgentSurface
{
float distanceValue;
float materialId;
float costTier;
};
float imaginationPetalSdf(float3 local, float angle, float activity, float heartbeat, float timeSeconds)
{
float2 radial = float2(cos(angle), sin(angle));
float2 tangent = float2(-radial.y, radial.x);
float phase = timeSeconds * 1.15 + angle * 1.7 + heartbeat * 6.28318;
float3 petalCenter = float3(radial * (0.34 + activity * 0.05), 0.028 * sin(phase));
float3 p = local - petalCenter;
float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z);
float3 petalRadius = float3(0.50 + activity * 0.05, 0.13, 0.64 + 0.045 * sin(phase));
return sdEllipsoid(q, petalRadius);
}
AgentSurface agentBodySdf(float3 local, AgentVisual agent)
{
float pulse = agent.state.y;
float core = sdSuperellipsoid(local, float3(0.92, 0.78, 0.62 + pulse * 0.06), 1.26);
float ribA = sdTorus(local.xzy, float2(0.70, 0.024));
float ribB = sdTorus(local.yxz, float2(0.56, 0.020));
float3 nodeA = local - float3(0.45, -0.36, 0.24);
float3 nodeB = local - float3(-0.38, 0.28, -0.18);
float node = min(sdSphere(nodeA, 0.13), sdSphere(nodeB, 0.11));
float shell = min(ribA, min(ribB, node));
AgentSurface surface;
surface.distanceValue = smoothUnion(core, shell, 0.045);
surface.materialId = core <= shell ? 4.0 : 4.35;
surface.costTier = 2.0;
return surface;
}
AgentSurface agentImaginationSdf(float3 local, AgentVisual agent, float timeSeconds)
{
float activity = agent.state.x;
float heartbeat = agent.state.y;
float core = sdSuperellipsoid(local, float3(0.30 + activity * 0.04, 0.30 + activity * 0.04, 0.42), 1.18);
float phase = timeSeconds * 0.42;
float petal0 = imaginationPetalSdf(local, phase, activity, heartbeat, timeSeconds);
float petal1 = imaginationPetalSdf(local, phase + 1.2566371, activity, heartbeat, timeSeconds);
float petal2 = imaginationPetalSdf(local, phase + 2.5132741, activity, heartbeat, timeSeconds);
float petal3 = imaginationPetalSdf(local, phase + 3.7699112, activity, heartbeat, timeSeconds);
float petal4 = imaginationPetalSdf(local, phase + 5.0265482, activity, heartbeat, timeSeconds);
float petals = min(petal0, min(petal1, min(petal2, min(petal3, petal4))));
float bloom = smoothUnion(core, petals, 0.055);
float ring = sdTorus(local, float2(0.72 + activity * 0.08, 0.032));
float halo = sdTorus(local.zxy, float2(0.50, 0.024));
float detail = min(ring, halo);
AgentSurface surface;
surface.distanceValue = smoothUnion(bloom, detail, 0.05);
surface.materialId = bloom <= detail ? 2.0 : 2.4;
surface.costTier = 2.0;
return surface;
}
AgentSurface agentFallbackSdf(float3 local, AgentVisual agent)
{
float roleId = agent.previousCenterRole.w;
float pulse = agent.state.y;
float squareness = lerp(1.18, 1.72, frac(roleId * 0.37));
float core = sdSuperellipsoid(local, float3(0.70, 0.58 + pulse * 0.04, 0.62), squareness);
float belt = sdTorus(local.xzy, float2(0.56, 0.026));
float crown = sdTorus((local - float3(0.0, 0.0, 0.16)).yzx, float2(0.40, 0.018));
float detail = min(belt, crown);
AgentSurface surface;
surface.distanceValue = smoothUnion(core, detail, 0.032);
surface.materialId = roleId + (core <= detail ? 0.0 : 0.22);
surface.costTier = 1.0;
return surface;
}
#endif

View file

@ -0,0 +1,576 @@
cbuffer AquariumFrame : register(b0)
{
float2 resolution;
float timeSeconds;
float gridRadius;
float3 cameraPosition;
float farDistance;
float2 gridCenter;
float frameIndex;
float previousTimeSeconds;
float3 previousCameraPosition;
float previousGridRadius;
float2 previousGridCenter;
float2 jitterPixels;
float2 previousJitterPixels;
float renderDebugMode;
float exposure;
float bloomIntensity;
float bloomVeilIntensity;
float4 cursorWorlds;
};
TextureCube<float4> studioPmremTexture : register(t22);
TextureCube<float4> studioIrradianceTexture : register(t23);
SamplerState gridSampler : register(s0);
struct BodyLight
{
float4 centerRadius;
float4 radianceFieldId;
};
StructuredBuffer<BodyLight> bodyLights : register(t12);
struct AgentVisual
{
float4 centerRadius;
float4 previousCenterRole;
float4 state;
float4 lodIndexFlags;
};
StructuredBuffer<AgentVisual> agentVisuals : register(t24);
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"
static const int AGENT_VISUAL_COUNT = 7;
static const int SELF_OBJECT_INDEX = AGENT_VISUAL_COUNT - 2;
static const int CURSOR_OBJECT_INDEX = AGENT_VISUAL_COUNT - 1;
static const int ROLE_AGENT_COUNT = AGENT_VISUAL_COUNT - 2;
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_AGENT_BASE = 10.0;
static const float CURSOR_RADIUS = 0.56;
static const float PI = 3.14159265359;
static const int BODY_LIGHT_COUNT = 8;
static const float STUDIO_PMREM_MAX_LOD = 9.0;
static const float STUDIO_PMREM_SPECULAR_INTENSITY = 0.34;
static const float STUDIO_IRRADIANCE_INTENSITY = 0.74;
struct AgentProxyVertexOut
{
float4 position : SV_Position;
nointerpolation float agentIndex : TEXCOORD0;
};
struct SceneOut
{
float4 colorTravel : SV_Target0;
float4 metadata : SV_Target1;
float4 control : SV_Target2;
float4 eventColor : SV_Target3;
float4 eventMetadata : SV_Target4;
float depth : SV_Depth;
};
struct SolidHit
{
bool hit;
float travel;
float3 normal;
float fieldId;
int primitiveId;
float roleId;
float materialId;
float stepCount;
float lodTier;
float costTier;
};
void cameraBasis(float3 camera, float2 center, out float3 forward, out float3 right, out float3 up)
{
float3 target = float3(center, 0.0);
forward = normalize(target - camera);
right = normalize(cross(forward, float3(0.0, 0.0, 1.0)));
up = cross(right, forward);
}
float3 rayDirectionForPixel(float2 pixel, float2 jitter, float3 camera, float2 center)
{
float2 ndc = ((pixel + jitter) * 2.0 - resolution) / resolution.y;
float3 forward;
float3 right;
float3 up;
cameraBasis(camera, center, forward, right, up);
return normalize(forward * 1.6 + right * ndc.x + up * ndc.y);
}
float hash21(float2 p)
{
p = frac(p * float2(123.34, 456.21));
p += dot(p, p + 45.32);
return frac(p.x * p.y);
}
bool traceSphere(float3 origin, float3 direction, float3 center, float radius, out float travel)
{
float3 oc = origin - center;
float b = dot(oc, direction);
float c = dot(oc, oc) - radius * radius;
float h = b * b - c;
if (h < 0.0)
{
travel = farDistance + 1.0;
return false;
}
h = sqrt(h);
float t = -b - h;
if (t < 0.0)
{
t = -b + h;
}
travel = t;
return t > 0.0 && t < farDistance;
}
bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float radius, float intervalStart, float intervalEnd, out float travel)
{
if (!traceSphere(origin, direction, center, radius, travel))
{
return false;
}
return travel >= intervalStart && travel <= intervalEnd;
}
float cursorHibiscusSdf(float3 p)
{
AgentVisual cursor = agentVisuals[CURSOR_OBJECT_INDEX];
float3 local = (p - cursor.centerRadius.xyz) / CURSOR_RADIUS;
return sdHibiscusCursor(local, timeSeconds) * CURSOR_RADIUS;
}
float3 cursorHibiscusNormal(float3 p)
{
float epsilon = 0.006;
float dx = cursorHibiscusSdf(p + float3(epsilon, 0.0, 0.0)) - cursorHibiscusSdf(p - float3(epsilon, 0.0, 0.0));
float dy = cursorHibiscusSdf(p + float3(0.0, epsilon, 0.0)) - cursorHibiscusSdf(p - float3(0.0, epsilon, 0.0));
float dz = cursorHibiscusSdf(p + float3(0.0, 0.0, epsilon)) - cursorHibiscusSdf(p - float3(0.0, 0.0, epsilon));
return normalize(float3(dx, dy, dz));
}
AgentSurface agentVisualSdf(float3 p, int agentIndex)
{
AgentVisual agent = agentVisuals[agentIndex];
float radius = max(agent.centerRadius.w, 0.001);
float3 local = (p - agent.centerRadius.xyz) / radius;
float roleId = agent.previousCenterRole.w;
AgentSurface surface = agentFallbackSdf(local, agent);
if (agentIndex == SELF_OBJECT_INDEX)
{
surface.distanceValue = sdSphere(local, 1.0);
surface.materialId = 0.0;
surface.costTier = 0.0;
}
else if (agentIndex == CURSOR_OBJECT_INDEX)
{
surface.distanceValue = cursorHibiscusSdf(p);
surface.materialId = 5.0;
surface.costTier = 1.0;
return surface;
}
else if (abs(roleId - 2.0) < 0.25)
{
surface = agentImaginationSdf(local, agent, timeSeconds);
}
else if (abs(roleId - 4.0) < 0.25)
{
surface = agentBodySdf(local, agent);
}
surface.distanceValue *= radius;
return surface;
}
float3 agentVisualNormal(float3 p, int agentIndex)
{
float epsilon = 0.006;
float dx = agentVisualSdf(p + float3(epsilon, 0.0, 0.0), agentIndex).distanceValue - agentVisualSdf(p - float3(epsilon, 0.0, 0.0), agentIndex).distanceValue;
float dy = agentVisualSdf(p + float3(0.0, epsilon, 0.0), agentIndex).distanceValue - agentVisualSdf(p - float3(0.0, epsilon, 0.0), agentIndex).distanceValue;
float dz = agentVisualSdf(p + float3(0.0, 0.0, epsilon), agentIndex).distanceValue - agentVisualSdf(p - float3(0.0, 0.0, epsilon), agentIndex).distanceValue;
return normalize(float3(dx, dy, dz));
}
bool traceAgentVisual(float3 origin, float3 direction, int agentIndex, float intervalStart, float intervalEnd, out float travel, out float3 normal, out float materialId, out float stepCount, out float costTier)
{
AgentVisual agent = agentVisuals[agentIndex];
float boundRadius = max(agent.centerRadius.w * 1.42, 0.001);
if (!traceSphere(origin, direction, agent.centerRadius.xyz, boundRadius, travel))
{
normal = 0.0;
materialId = 0.0;
stepCount = 0.0;
costTier = 0.0;
return false;
}
float3 oc = origin - agent.centerRadius.xyz;
float b = dot(oc, direction);
float c = dot(oc, oc) - boundRadius * boundRadius;
float h = sqrt(max(b * b - c, 0.0));
float startTravel = max(max(-b - h, intervalStart), 0.0);
float endTravel = min(-b + h, intervalEnd);
travel = startTravel;
normal = 0.0;
materialId = 0.0;
stepCount = 0.0;
costTier = 0.0;
[loop]
for (int stepIndex = 0; stepIndex < 72; stepIndex++)
{
if (travel > endTravel)
{
return false;
}
float3 p = origin + direction * travel;
AgentSurface surface = agentVisualSdf(p, agentIndex);
stepCount = (float)(stepIndex + 1);
costTier = max(costTier, surface.costTier);
if (abs(surface.distanceValue) < max(0.0016, travel * 0.00018))
{
normal = agentVisualNormal(p, agentIndex);
materialId = surface.materialId;
return true;
}
travel += max(abs(surface.distanceValue) * 0.12, 0.0016);
}
return false;
}
float3 primitiveCenterAt(int primitiveId)
{
int agentIndex = clamp(primitiveId, 0, AGENT_VISUAL_COUNT - 1);
return agentVisuals[agentIndex].centerRadius.xyz;
}
float primitiveRadius(int primitiveId)
{
int agentIndex = clamp(primitiveId, 0, AGENT_VISUAL_COUNT - 1);
return agentVisuals[agentIndex].centerRadius.w;
}
float primitiveFieldId(int primitiveId)
{
if (primitiveId == SELF_OBJECT_INDEX)
{
return FIELD_ID_SELF;
}
if (primitiveId == CURSOR_OBJECT_INDEX)
{
return FIELD_ID_CURSOR;
}
return FIELD_ID_AGENT_BASE + (float)primitiveId;
}
void considerPrimitiveHit(float3 origin, float3 direction, int primitiveId, float intervalStart, float intervalEnd, inout SolidHit nearest)
{
if (primitiveId < 0 || primitiveId >= AGENT_VISUAL_COUNT)
{
return;
}
if (primitiveId < SELF_OBJECT_INDEX || primitiveId == CURSOR_OBJECT_INDEX)
{
float hitTravel;
float3 hitNormal;
float materialId;
float stepCount;
float costTier;
if (traceAgentVisual(origin, direction, primitiveId, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal, materialId, stepCount, costTier))
{
nearest.hit = true;
nearest.travel = hitTravel;
nearest.normal = hitNormal;
nearest.fieldId = primitiveFieldId(primitiveId);
nearest.primitiveId = primitiveId;
nearest.roleId = primitiveId < SELF_OBJECT_INDEX ? agentVisuals[primitiveId].previousCenterRole.w : 0.0;
nearest.materialId = materialId;
nearest.stepCount = stepCount;
nearest.lodTier = agentVisuals[primitiveId].lodIndexFlags.x;
nearest.costTier = costTier;
}
return;
}
float radius = primitiveRadius(primitiveId);
float3 center = primitiveCenterAt(primitiveId);
float hitTravel;
if (traceSphereInInterval(origin, direction, center, radius, intervalStart, min(intervalEnd, nearest.travel), hitTravel))
{
float3 p = origin + direction * hitTravel;
nearest.hit = true;
nearest.travel = hitTravel;
nearest.normal = normalize(p - center);
nearest.fieldId = primitiveFieldId(primitiveId);
nearest.primitiveId = primitiveId;
nearest.roleId = 0.0;
nearest.materialId = 0.0;
nearest.stepCount = 1.0;
nearest.lodTier = 0.0;
nearest.costTier = 0.0;
}
}
float3 studioPmremDirection(float3 worldDirection)
{
return normalize(float3(worldDirection.x, worldDirection.z, worldDirection.y));
}
float3 studioPmremSample(float3 worldDirection, float lod)
{
return studioPmremTexture.SampleLevel(gridSampler, studioPmremDirection(worldDirection), lod).rgb;
}
float3 primitiveEmissionRadiance(float fieldId)
{
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
if (abs(light.radianceFieldId.w - fieldId) < 0.25)
{
return light.radianceFieldId.rgb;
}
}
return 0.0;
}
float3 bodyLightIrradianceAt(float3 p, float3 normal)
{
float3 irradiance = 0.0;
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
float3 radiance = light.radianceFieldId.rgb;
if (dot(radiance, radiance) <= 0.000001)
{
continue;
}
float3 toLight = light.centerRadius.xyz - p;
float distanceSquared = max(dot(toLight, toLight), 0.01);
float3 lightDirection = toLight * rsqrt(distanceSquared);
float cosine = saturate(dot(normal, lightDirection));
float radius = max(light.centerRadius.w, 0.001);
float solidAngle = saturate((radius * radius) / distanceSquared);
irradiance += radiance * cosine * solidAngle * 6.0;
}
return irradiance;
}
float3 cursorSpecularBodyLightRadiance(float3 p, float3 normal)
{
static const float MinimumRoughness = 0.045;
static const float CursorRoughness = 0.22;
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float roughness = max(CursorRoughness, MinimumRoughness);
float alpha = roughness * roughness;
float alpha2 = alpha * alpha;
float k = (roughness + 1.0);
k = (k * k) * 0.125;
float geometryV = ndv / max(ndv * (1.0 - k) + k, 0.00001);
float3 f0 = float3(1.0, 0.38, 0.72);
float3 result = 0.0;
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
float3 radiance = light.radianceFieldId.rgb;
if (dot(radiance, radiance) <= 0.000001)
{
continue;
}
float3 toLight = light.centerRadius.xyz - p;
float distanceSquared = max(dot(toLight, toLight), 0.01);
float3 lightDirection = toLight * rsqrt(distanceSquared);
float radius = max(light.centerRadius.w, 0.001);
float3 irradiance = radiance * saturate((radius * radius) / distanceSquared) * 7.0;
float3 halfVector = normalize(lightDirection + viewDirection);
float ndl = saturate(dot(normal, lightDirection));
float ndh = saturate(dot(normal, halfVector));
float vdh = saturate(dot(viewDirection, halfVector));
float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0;
float distribution = alpha2 / max(PI * denominator * denominator, 0.00001);
float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001);
float geometry = geometryL * geometryV;
float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0);
float3 specular = (distribution * geometry) * fresnel / max(4.0 * ndl * ndv, 0.00001);
result += specular * irradiance * ndl;
}
return result;
}
float3 fresnelSchlickRoughness(float cosine, float3 f0, float roughness)
{
return f0 + (max(1.0 - roughness, f0) - f0) * pow(1.0 - cosine, 5.0);
}
float3 studioPmremSpecularRadiance(float3 p, float3 normal, float roughness, float3 f0)
{
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float3 reflectionDirection = reflect(-viewDirection, normal);
float lod = saturate(roughness) * STUDIO_PMREM_MAX_LOD;
float3 radiance = studioPmremSample(reflectionDirection, lod);
float3 fresnel = fresnelSchlickRoughness(ndv, f0, roughness);
return radiance * fresnel * STUDIO_PMREM_SPECULAR_INTENSITY;
}
float3 studioIrradianceDiffuseRadiance(float3 p, float3 normal, float3 albedo, float roughness, float3 f0)
{
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float3 fresnel = fresnelSchlickRoughness(ndv, f0, roughness);
float3 diffuseShare = 1.0 - fresnel;
float3 irradiance = studioIrradianceTexture.SampleLevel(gridSampler, studioPmremDirection(normal), 0.0).rgb;
return diffuseShare * albedo * irradiance * (STUDIO_IRRADIANCE_INTENSITY / PI);
}
float3 cursorEmissionRadiance(float3 p, float3 normal)
{
AgentVisual cursor = agentVisuals[CURSOR_OBJECT_INDEX];
float3 local = (p - cursor.centerRadius.xyz) / CURSOR_RADIUS;
float petal = 0.55 + 0.45 * cos(atan2(local.y, local.x) * 3.0 - timeSeconds * 1.8);
float throat = exp(-dot(local.xy, local.xy) * 7.0) * smoothstep(0.46, -0.28, local.z);
float rim = pow(1.0 - saturate(dot(normal, normalize(cameraPosition - p))), 2.0);
float3 petalColor = lerp(float3(1.25, 0.12, 0.56), float3(1.0, 0.42, 0.88), petal);
float3 throatColor = float3(1.0, 0.76, 0.22);
return petalColor * (0.82 + rim * 0.75) + throatColor * throat * 1.7;
}
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitiveId)
{
float fieldId = primitiveFieldId(primitiveId);
float3 emission = primitiveEmissionRadiance(fieldId);
if (primitiveId == SELF_OBJECT_INDEX)
{
return emission;
}
if (primitiveId == CURSOR_OBJECT_INDEX)
{
static const float CursorRoughness = 0.22;
float3 cursorF0 = float3(1.0, 0.38, 0.72);
return cursorEmissionRadiance(p, normal)
+ cursorSpecularBodyLightRadiance(p, normal)
+ studioPmremSpecularRadiance(p, normal, CursorRoughness, cursorF0);
}
int agentIndex = clamp(primitiveId, 0, ROLE_AGENT_COUNT - 1);
float roleId = agentVisuals[agentIndex].previousCenterRole.w;
float materialPulse = agentVisuals[agentIndex].state.y;
float3 albedo = lerp(float3(0.34, 0.42, 0.18), float3(0.70, 0.76, 0.42), hash21(float2(primitiveId, 6.3)));
float roughness = lerp(0.46, 0.72, hash21(float2(primitiveId, 11.9)));
if (abs(roleId - 2.0) < 0.25)
{
albedo = lerp(float3(0.38, 0.18, 0.72), float3(0.98, 0.56, 0.92), materialPulse);
roughness = 0.38;
emission += albedo * (0.08 + materialPulse * 0.08);
}
else if (abs(roleId - 4.0) < 0.25)
{
albedo = lerp(float3(0.18, 0.43, 0.50), float3(0.72, 0.86, 0.72), materialPulse);
roughness = 0.58;
}
float3 dielectricF0 = 0.04;
return emission
+ albedo * bodyLightIrradianceAt(p, normal) / PI
+ studioIrradianceDiffuseRadiance(p, normal, albedo, roughness, dielectricF0)
+ studioPmremSpecularRadiance(p, normal, roughness, dielectricF0);
}
AgentProxyVertexOut D3D12AgentProxyVS(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
{
float2 corners[6] =
{
float2(-1.0, -1.0),
float2(1.0, -1.0),
float2(1.0, 1.0),
float2(-1.0, -1.0),
float2(1.0, 1.0),
float2(-1.0, 1.0),
};
AgentVisual agent = agentVisuals[instanceId];
float3 forward;
float3 right;
float3 up;
cameraBasis(cameraPosition, gridCenter, forward, right, up);
float3 delta = agent.centerRadius.xyz - 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 = agent.centerRadius.w * 1.58;
float projectedRadius = boundRadius / z * 1.6 + 0.035;
float2 clipCenter = float2(projected.x / clipAspect, -projected.y);
float2 clipRadius = float2(projectedRadius / clipAspect, projectedRadius);
AgentProxyVertexOut output;
output.position = float4(clipCenter + corners[vertexId] * clipRadius, 0.0, 1.0);
output.agentIndex = (float)instanceId;
return output;
}
SceneOut D3D12AgentProxyPS(AgentProxyVertexOut input)
{
float2 pixel = input.position.xy;
float2 uv = float2(pixel.x / max(resolution.x, 1.0), 1.0 - pixel.y / max(resolution.y, 1.0));
float3 rayDirection = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
SolidHit hit;
hit.hit = false;
hit.travel = farDistance;
hit.normal = 0.0;
hit.fieldId = 0.0;
hit.primitiveId = -1;
hit.roleId = 0.0;
hit.materialId = 0.0;
hit.stepCount = 0.0;
hit.lodTier = 0.0;
hit.costTier = 0.0;
int agentIndex = clamp((int)round(input.agentIndex), 0, AGENT_VISUAL_COUNT - 1);
considerPrimitiveHit(cameraPosition, rayDirection, agentIndex, 0.0, farDistance, hit);
if (!hit.hit)
{
discard;
}
float3 p = cameraPosition + rayDirection * hit.travel;
SceneOut output;
output.colorTravel = float4(shadeBody(uv, hit.travel, p, hit.normal, hit.primitiveId), min(hit.travel, farDistance + 1.0));
output.metadata = float4(hit.fieldId, hit.normal);
output.control = float4(hit.materialId, 1.0, hit.stepCount / 72.0, hit.lodTier + hit.costTier * 0.1);
output.eventColor = float4(0.0, 0.0, 0.0, 0.0);
output.eventMetadata = float4(FIELD_ID_GRID, farDistance + 1.0, 0.0, 0.0);
output.depth = saturate(hit.travel / max(farDistance, 0.001));
return output;
}

View file

@ -22,45 +22,11 @@ cbuffer AquariumFrame : register(b0)
Texture2D<float4> gridHeightTexture : register(t0);
TextureCube<float4> studioPmremTexture : register(t22);
TextureCube<float4> studioIrradianceTexture : register(t23);
SamplerState gridSampler : register(s0);
struct BodyLight
{
float4 centerRadius;
float4 radianceFieldId;
};
StructuredBuffer<BodyLight> bodyLights : register(t12);
struct AgentVisual
{
float4 centerRadius;
float4 previousCenterRole;
float4 state;
float4 lodIndexFlags;
};
StructuredBuffer<AgentVisual> agentVisuals : register(t24);
static const int AGENT_VISUAL_COUNT = 7;
static const int SELF_OBJECT_INDEX = AGENT_VISUAL_COUNT - 2;
static const int CURSOR_OBJECT_INDEX = AGENT_VISUAL_COUNT - 1;
static const int ROLE_AGENT_COUNT = AGENT_VISUAL_COUNT - 2;
static const float SUN_RADIUS = 1.12;
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_AGENT_BASE = 10.0;
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;
static const float STUDIO_PMREM_MAX_LOD = 9.0;
static const float STUDIO_PMREM_SPECULAR_INTENSITY = 0.34;
static const float STUDIO_IRRADIANCE_INTENSITY = 0.74;
static const float GRID_FLAT_REFLECTION_MAX_LOD = 3.0;
static const float BACKGROUND_PMREM_LOD = 3.0;
static const float BACKGROUND_PMREM_CONE = 0.16;
@ -73,12 +39,6 @@ struct VertexOut
float2 uv : TEXCOORD0;
};
struct AgentProxyVertexOut
{
float4 position : SV_Position;
nointerpolation float agentIndex : TEXCOORD0;
};
struct SceneOut
{
float4 colorTravel : SV_Target0;
@ -89,20 +49,6 @@ struct SceneOut
float depth : SV_Depth;
};
struct SolidHit
{
bool hit;
float travel;
float3 normal;
float fieldId;
int primitiveId;
float roleId;
float materialId;
float stepCount;
float lodTier;
float costTier;
};
struct RayMarchResult
{
float3 color;
@ -110,7 +56,6 @@ struct RayMarchResult
float fieldId;
float3 normal;
float coverage;
float roleId;
float materialId;
float stepCount;
float lodTier;
@ -120,8 +65,6 @@ struct RayMarchResult
float3 eventColor;
};
void cameraBasis(float3 camera, float2 center, out float3 forward, out float3 right, out float3 up);
VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
{
float2 uv = float2((vertexId << 1) & 2, vertexId & 2);
@ -131,38 +74,6 @@ VertexOut FullscreenTriangleVS(uint vertexId : SV_VertexID)
return output;
}
AgentProxyVertexOut D3D12AgentProxyVS(uint vertexId : SV_VertexID, uint instanceId : SV_InstanceID)
{
float2 corners[6] =
{
float2(-1.0, -1.0),
float2(1.0, -1.0),
float2(1.0, 1.0),
float2(-1.0, -1.0),
float2(1.0, 1.0),
float2(-1.0, 1.0),
};
AgentVisual agent = agentVisuals[instanceId];
float3 forward;
float3 right;
float3 up;
cameraBasis(cameraPosition, gridCenter, forward, right, up);
float3 delta = agent.centerRadius.xyz - 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 = agent.centerRadius.w * 1.58;
float projectedRadius = boundRadius / z * 1.6 + 0.035;
float2 clipCenter = float2(projected.x / clipAspect, -projected.y);
float2 clipRadius = float2(projectedRadius / clipAspect, projectedRadius);
AgentProxyVertexOut output;
output.position = float4(clipCenter + corners[vertexId] * clipRadius, 0.0, 1.0);
output.agentIndex = (float)instanceId;
return output;
}
void cameraBasis(float3 camera, float2 center, out float3 forward, out float3 right, out float3 up)
{
float3 target = float3(center, 0.0);
@ -181,40 +92,6 @@ float3 rayDirectionForPixel(float2 pixel, float2 jitter, float3 camera, float2 c
return normalize(forward * 1.6 + right * ndc.x + up * ndc.y);
}
float hash21(float2 p)
{
p = frac(p * float2(123.34, 456.21));
p += dot(p, p + 45.32);
return frac(p.x * p.y);
}
float planetRadius(int index)
{
return lerp(0.34, 0.62, hash21(float2(index, 19.7)));
}
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;
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);
float2 gridLocal(float2 p)
{
return (p - gridCenter) / max(gridRadius, 0.001);
@ -244,439 +121,6 @@ float2 terrainGradient(float2 p)
return float2(hRight - hLeft, hUp - hDown) / (texelWorld * 2.0);
}
float3 terrainNormal(float3 p)
{
float2 gradient = terrainGradient(p.xy);
return normalize(float3(-gradient.x, -gradient.y, 1.0));
}
bool traceSphere(float3 origin, float3 direction, float3 center, float radius, out float travel)
{
float3 oc = origin - center;
float b = dot(oc, direction);
float c = dot(oc, oc) - radius * radius;
float h = b * b - c;
if (h < 0.0)
{
travel = farDistance + 1.0;
return false;
}
h = sqrt(h);
float t = -b - h;
if (t < 0.0)
{
t = -b + h;
}
travel = t;
return t > 0.0 && t < farDistance;
}
bool traceSphereInInterval(float3 origin, float3 direction, float3 center, float radius, float intervalStart, float intervalEnd, out float travel)
{
if (!traceSphere(origin, direction, center, radius, travel))
{
return false;
}
return travel >= intervalStart && travel <= intervalEnd;
}
float cursorLocatorProfileRadius(float z)
{
static const float ContactZ = -1.0;
static const float TipZ = 1.15;
static const float RadiusScale = 0.78;
float u = saturate((z - ContactZ) / (TipZ - ContactZ));
float x = u * 2.0 - 1.0;
float halfTerm = (1.0 - x) * 0.5;
float teardropWeight = halfTerm * halfTerm * halfTerm;
float baseRadius = RadiusScale * sqrt(saturate(1.0 - x * x)) * teardropWeight;
float rippleEnvelope = smoothstep(0.08, 0.22, u) * (1.0 - smoothstep(0.76, 0.94, u));
float rippleWave = sin(z * 28.0 - timeSeconds * 4.0);
float rippleRadius = min(0.014, baseRadius * 0.07) * rippleWave * rippleEnvelope;
return max(baseRadius + rippleRadius, 0.0);
}
float cursorLocatorSdf(float3 p)
{
static const float ContactZ = -1.0;
static const float TipZ = 1.15;
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);
float radialDistance = samplePoint.x - profileRadius;
float topDistance = samplePoint.y - TipZ;
float bottomDistance = ContactZ - samplePoint.y;
float boundedDistance = max(radialDistance, max(topDistance, bottomDistance));
return boundedDistance * CURSOR_RADIUS;
}
float3 cursorLocatorNormal(float3 p)
{
float epsilon = 0.006;
float dx = cursorLocatorSdf(p + float3(epsilon, 0.0, 0.0)) - cursorLocatorSdf(p - float3(epsilon, 0.0, 0.0));
float dy = cursorLocatorSdf(p + float3(0.0, epsilon, 0.0)) - cursorLocatorSdf(p - float3(0.0, epsilon, 0.0));
float dz = cursorLocatorSdf(p + float3(0.0, 0.0, epsilon)) - cursorLocatorSdf(p - float3(0.0, 0.0, epsilon));
return normalize(float3(dx, dy, dz));
}
struct AgentSurface
{
float distanceValue;
float materialId;
float costTier;
};
float sdSphere(float3 p, float radius)
{
return length(p) - radius;
}
float sdTorus(float3 p, float2 radius)
{
float2 q = float2(length(p.xy) - radius.x, p.z);
return length(q) - radius.y;
}
float sdSuperellipsoid(float3 p, float3 scale, float exponent)
{
float3 q = abs(p) / scale;
float value = pow(pow(q.x, exponent) + pow(q.y, exponent) + pow(q.z, exponent), 1.0 / exponent);
return (value - 1.0) * min(scale.x, min(scale.y, scale.z));
}
float sdEllipsoid(float3 p, float3 radius)
{
float3 safeRadius = max(radius, 0.001);
float k0 = length(p / safeRadius);
float k1 = length(p / (safeRadius * safeRadius));
return k0 * (k0 - 1.0) / max(k1, 0.001);
}
float smoothUnion(float a, float b, float radius)
{
float h = saturate(0.5 + 0.5 * (b - a) / radius);
return lerp(b, a, h) - radius * h * (1.0 - h);
}
float imaginationPetalSdf(float3 local, float angle, float activity, float heartbeat)
{
float2 radial = float2(cos(angle), sin(angle));
float2 tangent = float2(-radial.y, radial.x);
float phase = timeSeconds * 1.15 + angle * 1.7 + heartbeat * 6.28318;
float3 petalCenter = float3(radial * (0.34 + activity * 0.05), 0.028 * sin(phase));
float3 p = local - petalCenter;
float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z);
float3 petalRadius = float3(0.50 + activity * 0.05, 0.13, 0.64 + 0.045 * sin(phase));
return sdEllipsoid(q, petalRadius);
}
AgentSurface agentBodySdf(float3 local, AgentVisual agent)
{
float pulse = agent.state.y;
float core = sdSuperellipsoid(local, float3(0.92, 0.78, 0.62 + pulse * 0.06), 1.26);
float ribA = sdTorus(local.xzy, float2(0.70, 0.024));
float ribB = sdTorus(local.yxz, float2(0.56, 0.020));
float3 nodeA = local - float3(0.45, -0.36, 0.24);
float3 nodeB = local - float3(-0.38, 0.28, -0.18);
float node = min(sdSphere(nodeA, 0.13), sdSphere(nodeB, 0.11));
float shell = min(ribA, min(ribB, node));
AgentSurface surface;
surface.distanceValue = smoothUnion(core, shell, 0.045);
surface.materialId = core <= shell ? 4.0 : 4.35;
surface.costTier = 2.0;
return surface;
}
AgentSurface agentImaginationSdf(float3 local, AgentVisual agent)
{
float activity = agent.state.x;
float heartbeat = agent.state.y;
float core = sdSuperellipsoid(local, float3(0.30 + activity * 0.04, 0.30 + activity * 0.04, 0.42), 1.18);
float phase = timeSeconds * 0.42;
float petal0 = imaginationPetalSdf(local, phase, activity, heartbeat);
float petal1 = imaginationPetalSdf(local, phase + 1.2566371, activity, heartbeat);
float petal2 = imaginationPetalSdf(local, phase + 2.5132741, activity, heartbeat);
float petal3 = imaginationPetalSdf(local, phase + 3.7699112, activity, heartbeat);
float petal4 = imaginationPetalSdf(local, phase + 5.0265482, activity, heartbeat);
float petals = min(petal0, min(petal1, min(petal2, min(petal3, petal4))));
float bloom = smoothUnion(core, petals, 0.055);
float ring = sdTorus(local, float2(0.72 + activity * 0.08, 0.032));
float halo = sdTorus(local.zxy, float2(0.50, 0.024));
float detail = min(ring, halo);
AgentSurface surface;
surface.distanceValue = smoothUnion(bloom, detail, 0.05);
surface.materialId = bloom <= detail ? 2.0 : 2.4;
surface.costTier = 2.0;
return surface;
}
AgentSurface agentFallbackSdf(float3 local, AgentVisual agent)
{
float roleId = agent.previousCenterRole.w;
float pulse = agent.state.y;
float squareness = lerp(1.18, 1.72, frac(roleId * 0.37));
float core = sdSuperellipsoid(local, float3(0.70, 0.58 + pulse * 0.04, 0.62), squareness);
float belt = sdTorus(local.xzy, float2(0.56, 0.026));
float crown = sdTorus((local - float3(0.0, 0.0, 0.16)).yzx, float2(0.40, 0.018));
float detail = min(belt, crown);
AgentSurface surface;
surface.distanceValue = smoothUnion(core, detail, 0.032);
surface.materialId = roleId + (core <= detail ? 0.0 : 0.22);
surface.costTier = 1.0;
return surface;
}
AgentSurface agentVisualSdf(float3 p, int agentIndex)
{
AgentVisual agent = agentVisuals[agentIndex];
float radius = max(agent.centerRadius.w, 0.001);
float3 local = (p - agent.centerRadius.xyz) / radius;
float roleId = agent.previousCenterRole.w;
AgentSurface surface = agentFallbackSdf(local, agent);
if (agentIndex == SELF_OBJECT_INDEX)
{
surface.distanceValue = sdSphere(local, 1.0);
surface.materialId = 0.0;
surface.costTier = 0.0;
}
else if (agentIndex == CURSOR_OBJECT_INDEX)
{
surface.distanceValue = cursorLocatorSdf(p);
surface.materialId = 5.0;
surface.costTier = 1.0;
return surface;
}
else if (abs(roleId - 2.0) < 0.25)
{
surface = agentImaginationSdf(local, agent);
}
else if (abs(roleId - 4.0) < 0.25)
{
surface = agentBodySdf(local, agent);
}
surface.distanceValue *= radius;
return surface;
}
float3 agentVisualNormal(float3 p, int agentIndex)
{
float epsilon = 0.006;
float dx = agentVisualSdf(p + float3(epsilon, 0.0, 0.0), agentIndex).distanceValue - agentVisualSdf(p - float3(epsilon, 0.0, 0.0), agentIndex).distanceValue;
float dy = agentVisualSdf(p + float3(0.0, epsilon, 0.0), agentIndex).distanceValue - agentVisualSdf(p - float3(0.0, epsilon, 0.0), agentIndex).distanceValue;
float dz = agentVisualSdf(p + float3(0.0, 0.0, epsilon), agentIndex).distanceValue - agentVisualSdf(p - float3(0.0, 0.0, epsilon), agentIndex).distanceValue;
return normalize(float3(dx, dy, dz));
}
bool traceAgentVisual(float3 origin, float3 direction, int agentIndex, float intervalStart, float intervalEnd, out float travel, out float3 normal, out float materialId, out float stepCount, out float costTier)
{
AgentVisual agent = agentVisuals[agentIndex];
float boundRadius = max(agent.centerRadius.w * 1.42, 0.001);
if (!traceSphere(origin, direction, agent.centerRadius.xyz, boundRadius, travel))
{
normal = 0.0;
materialId = 0.0;
stepCount = 0.0;
costTier = 0.0;
return false;
}
float3 oc = origin - agent.centerRadius.xyz;
float b = dot(oc, direction);
float c = dot(oc, oc) - boundRadius * boundRadius;
float h = sqrt(max(b * b - c, 0.0));
float startTravel = max(max(-b - h, intervalStart), 0.0);
float endTravel = min(-b + h, intervalEnd);
travel = startTravel;
normal = 0.0;
materialId = 0.0;
stepCount = 0.0;
costTier = 0.0;
[loop]
for (int stepIndex = 0; stepIndex < 72; stepIndex++)
{
if (travel > endTravel)
{
return false;
}
float3 p = origin + direction * travel;
AgentSurface surface = agentVisualSdf(p, agentIndex);
stepCount = (float)(stepIndex + 1);
costTier = max(costTier, surface.costTier);
if (abs(surface.distanceValue) < max(0.0016, travel * 0.00018))
{
normal = agentVisualNormal(p, agentIndex);
materialId = surface.materialId;
return true;
}
travel += max(abs(surface.distanceValue) * 0.12, 0.0016);
}
return false;
}
bool traceCursorLocator(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float travel, out float3 normal)
{
float sphereTravel;
float3 center = bodyCenterAtGridHeight(cursorWorlds.xy, CURSOR_RADIUS);
if (!traceSphere(origin, direction, center, CURSOR_BOUND_RADIUS, sphereTravel))
{
travel = farDistance + 1.0;
normal = 0.0;
return false;
}
float3 oc = origin - center;
float b = dot(oc, direction);
float c = dot(oc, oc) - CURSOR_BOUND_RADIUS * CURSOR_BOUND_RADIUS;
float h = sqrt(max(b * b - c, 0.0));
float startTravel = max(max(-b - h, intervalStart), 0.0);
float endTravel = min(-b + h, intervalEnd);
travel = startTravel;
normal = 0.0;
[loop]
for (int stepIndex = 0; stepIndex < 48; stepIndex++)
{
if (travel > endTravel)
{
return false;
}
float3 p = origin + direction * travel;
float distanceValue = cursorLocatorSdf(p);
if (abs(distanceValue) < max(0.0025, travel * 0.00025))
{
normal = cursorLocatorNormal(p);
return true;
}
travel += max(abs(distanceValue) * 0.36, 0.0025);
}
return false;
}
float3 primitiveCenterAt(int primitiveId, float sampleTime)
{
int agentIndex = clamp(primitiveId, 0, AGENT_VISUAL_COUNT - 1);
return agentVisuals[agentIndex].centerRadius.xyz;
}
float primitiveRadius(int primitiveId)
{
int agentIndex = clamp(primitiveId, 0, AGENT_VISUAL_COUNT - 1);
return agentVisuals[agentIndex].centerRadius.w;
}
float primitiveFieldId(int primitiveId)
{
if (primitiveId == SELF_OBJECT_INDEX)
{
return FIELD_ID_SELF;
}
if (primitiveId == CURSOR_OBJECT_INDEX)
{
return FIELD_ID_CURSOR;
}
return FIELD_ID_AGENT_BASE + (float)primitiveId;
}
void considerPrimitiveHit(float3 origin, float3 direction, int primitiveId, float intervalStart, float intervalEnd, inout SolidHit nearest)
{
if (primitiveId < 0 || primitiveId >= AGENT_VISUAL_COUNT)
{
return;
}
if (primitiveId < SELF_OBJECT_INDEX)
{
float agentTravel;
float3 agentNormal;
float materialId;
float stepCount;
float costTier;
if (traceAgentVisual(origin, direction, primitiveId, intervalStart, min(intervalEnd, nearest.travel), agentTravel, agentNormal, materialId, stepCount, costTier))
{
nearest.hit = true;
nearest.travel = agentTravel;
nearest.normal = agentNormal;
nearest.fieldId = primitiveFieldId(primitiveId);
nearest.primitiveId = primitiveId;
nearest.roleId = agentVisuals[primitiveId].previousCenterRole.w;
nearest.materialId = materialId;
nearest.stepCount = stepCount;
nearest.lodTier = agentVisuals[primitiveId].lodIndexFlags.x;
nearest.costTier = costTier;
}
return;
}
if (primitiveId == CURSOR_OBJECT_INDEX)
{
float hitTravel;
float3 hitNormal;
if (traceCursorLocator(origin, direction, intervalStart, min(intervalEnd, nearest.travel), hitTravel, hitNormal))
{
nearest.hit = true;
nearest.travel = hitTravel;
nearest.normal = hitNormal;
nearest.fieldId = FIELD_ID_CURSOR;
nearest.primitiveId = primitiveId;
nearest.roleId = 0.0;
nearest.materialId = 5.0;
nearest.stepCount = 1.0;
nearest.lodTier = 0.0;
nearest.costTier = 1.0;
}
return;
}
float radius = primitiveRadius(primitiveId);
float3 center = primitiveCenterAt(primitiveId, timeSeconds);
float hitTravel;
if (traceSphereInInterval(origin, direction, center, radius, intervalStart, min(intervalEnd, nearest.travel), hitTravel))
{
float3 p = origin + direction * hitTravel;
nearest.hit = true;
nearest.travel = hitTravel;
nearest.normal = normalize(p - center);
nearest.fieldId = primitiveFieldId(primitiveId);
nearest.primitiveId = primitiveId;
nearest.roleId = 0.0;
nearest.materialId = 0.0;
nearest.stepCount = 1.0;
nearest.lodTier = 0.0;
nearest.costTier = 0.0;
}
}
void considerAllPrimitiveHits(float3 origin, float3 direction, float intervalStart, float intervalEnd, inout SolidHit nearest)
{
[unroll]
for (int i = 0; i < AGENT_VISUAL_COUNT; i++)
{
considerPrimitiveHit(origin, direction, i, intervalStart, intervalEnd, nearest);
}
}
float gridSurfaceDistanceAt(float3 origin, float3 direction, float travel)
{
float3 p = origin + direction * travel;
return p.z - terrainHeight(p.xy);
}
bool traceGridSurfaceDirect(float3 origin, float3 direction, float intervalStart, float intervalEnd, out float3 hitPosition, out float travel)
{
travel = max(intervalStart, 0.0);
@ -770,7 +214,7 @@ float3 backgroundRadiance(float3 direction)
return studioPmremConeSample(direction, BACKGROUND_PMREM_LOD, BACKGROUND_PMREM_CONE);
}
RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 direction)
RayMarchResult traverseRay(float3 origin, float3 direction)
{
RayMarchResult result;
result.color = backgroundRadiance(direction);
@ -778,7 +222,6 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir
result.fieldId = 0.0;
result.normal = 0.0;
result.coverage = 0.0;
result.roleId = 0.0;
result.materialId = 0.0;
result.stepCount = 0.0;
result.lodTier = 0.0;
@ -798,178 +241,18 @@ RayMarchResult traverseRay(float2 uv, float2 screenUv, float3 origin, float3 dir
result.fieldId = FIELD_ID_GRID;
result.normal = gridNormal;
result.coverage = 1.0;
result.roleId = 0.0;
result.materialId = 0.0;
result.stepCount = 0.0;
result.lodTier = 0.0;
result.costTier = 0.0;
return result;
}
return result;
}
float3 primitiveEmissionRadiance(float fieldId)
{
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
if (abs(light.radianceFieldId.w - fieldId) < 0.25)
{
return light.radianceFieldId.rgb;
}
}
return 0.0;
}
float3 bodyLightIrradianceAt(float3 p, float3 normal)
{
float3 irradiance = 0.0;
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
float3 radiance = light.radianceFieldId.rgb;
if (dot(radiance, radiance) <= 0.000001)
{
continue;
}
float3 toLight = light.centerRadius.xyz - p;
float distanceSquared = max(dot(toLight, toLight), 0.01);
float3 lightDirection = toLight * rsqrt(distanceSquared);
float cosine = saturate(dot(normal, lightDirection));
float radius = max(light.centerRadius.w, 0.001);
float solidAngle = saturate((radius * radius) / distanceSquared);
irradiance += radiance * cosine * solidAngle * 6.0;
}
return irradiance;
}
float3 cursorSpecularBodyLightRadiance(float3 p, float3 normal)
{
static const float MinimumRoughness = 0.045;
static const float CursorRoughness = 0.16;
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float roughness = max(CursorRoughness, MinimumRoughness);
float alpha = roughness * roughness;
float alpha2 = alpha * alpha;
float k = (roughness + 1.0);
k = (k * k) * 0.125;
float geometryV = ndv / max(ndv * (1.0 - k) + k, 0.00001);
float3 f0 = float3(0.95, 0.62, 0.26);
float3 result = 0.0;
[loop]
for (int i = 0; i < BODY_LIGHT_COUNT; i++)
{
BodyLight light = bodyLights[i];
float3 radiance = light.radianceFieldId.rgb;
if (dot(radiance, radiance) <= 0.000001)
{
continue;
}
float3 toLight = light.centerRadius.xyz - p;
float distanceSquared = max(dot(toLight, toLight), 0.01);
float3 lightDirection = toLight * rsqrt(distanceSquared);
float radius = max(light.centerRadius.w, 0.001);
float3 irradiance = radiance * saturate((radius * radius) / distanceSquared) * 7.0;
float3 halfVector = normalize(lightDirection + viewDirection);
float ndl = saturate(dot(normal, lightDirection));
float ndh = saturate(dot(normal, halfVector));
float vdh = saturate(dot(viewDirection, halfVector));
float denominator = ndh * ndh * (alpha2 - 1.0) + 1.0;
float distribution = alpha2 / max(PI * denominator * denominator, 0.00001);
float geometryL = ndl / max(ndl * (1.0 - k) + k, 0.00001);
float geometry = geometryL * geometryV;
float3 fresnel = f0 + (1.0 - f0) * pow(1.0 - vdh, 5.0);
float3 specular = (distribution * geometry) * fresnel / max(4.0 * ndl * ndv, 0.00001);
result += specular * irradiance * ndl;
}
return result;
}
float3 fresnelSchlickRoughness(float cosine, float3 f0, float roughness)
{
return f0 + (max(1.0 - roughness, f0) - f0) * pow(1.0 - cosine, 5.0);
}
float3 studioPmremSpecularRadiance(float3 p, float3 normal, float roughness, float3 f0)
{
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float3 reflectionDirection = reflect(-viewDirection, normal);
float lod = saturate(roughness) * STUDIO_PMREM_MAX_LOD;
float3 radiance = studioPmremSample(reflectionDirection, lod);
float3 fresnel = fresnelSchlickRoughness(ndv, f0, roughness);
return radiance * fresnel * STUDIO_PMREM_SPECULAR_INTENSITY;
}
float3 studioIrradianceDiffuseRadiance(float3 p, float3 normal, float3 albedo, float roughness, float3 f0)
{
float3 viewDirection = normalize(cameraPosition - p);
float ndv = saturate(dot(normal, viewDirection));
float3 fresnel = fresnelSchlickRoughness(ndv, f0, roughness);
float3 diffuseShare = 1.0 - fresnel;
float3 irradiance = studioIrradianceTexture.SampleLevel(gridSampler, studioPmremDirection(normal), 0.0).rgb;
return diffuseShare * albedo * irradiance * (STUDIO_IRRADIANCE_INTENSITY / PI);
}
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int primitiveId)
{
float fieldId = primitiveFieldId(primitiveId);
float3 emission = primitiveEmissionRadiance(fieldId);
if (primitiveId == SELF_OBJECT_INDEX)
{
return emission;
}
if (primitiveId == CURSOR_OBJECT_INDEX)
{
static const float CursorRoughness = 0.16;
float3 cursorF0 = float3(0.95, 0.62, 0.26);
return emission
+ cursorSpecularBodyLightRadiance(p, normal)
+ studioPmremSpecularRadiance(p, normal, CursorRoughness, cursorF0);
}
int agentIndex = clamp(primitiveId, 0, ROLE_AGENT_COUNT - 1);
float roleId = agentVisuals[agentIndex].previousCenterRole.w;
float materialPulse = agentVisuals[agentIndex].state.y;
float3 albedo = lerp(float3(0.34, 0.42, 0.18), float3(0.70, 0.76, 0.42), hash21(float2(primitiveId, 6.3)));
float roughness = lerp(0.46, 0.72, hash21(float2(primitiveId, 11.9)));
if (abs(roleId - 2.0) < 0.25)
{
albedo = lerp(float3(0.38, 0.18, 0.72), float3(0.98, 0.56, 0.92), materialPulse);
roughness = 0.38;
emission += albedo * (0.08 + materialPulse * 0.08);
}
else if (abs(roleId - 4.0) < 0.25)
{
albedo = lerp(float3(0.18, 0.43, 0.50), float3(0.72, 0.86, 0.72), materialPulse);
roughness = 0.58;
}
float3 dielectricF0 = 0.04;
return emission
+ albedo * bodyLightIrradianceAt(p, normal) / PI
+ studioIrradianceDiffuseRadiance(p, normal, albedo, roughness, dielectricF0)
+ studioPmremSpecularRadiance(p, normal, roughness, dielectricF0);
}
SceneOut D3D12ScenePS(VertexOut input)
{
float2 screenUv = float2(input.uv.x, 1.0 - input.uv.y);
float2 pixel = screenUv * resolution;
float3 rayDirection = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
RayMarchResult result = traverseRay(input.uv, screenUv, cameraPosition, rayDirection);
RayMarchResult result = traverseRay(cameraPosition, rayDirection);
SceneOut output;
output.colorTravel = float4(result.color, min(result.travel, farDistance + 1.0));
@ -980,38 +263,3 @@ SceneOut D3D12ScenePS(VertexOut input)
output.depth = saturate(result.travel / max(farDistance, 0.001));
return output;
}
SceneOut D3D12AgentProxyPS(AgentProxyVertexOut input)
{
float2 pixel = input.position.xy;
float2 uv = float2(pixel.x / max(resolution.x, 1.0), 1.0 - pixel.y / max(resolution.y, 1.0));
float3 rayDirection = rayDirectionForPixel(pixel, jitterPixels, cameraPosition, gridCenter);
SolidHit hit;
hit.hit = false;
hit.travel = farDistance;
hit.normal = 0.0;
hit.fieldId = 0.0;
hit.primitiveId = -1;
hit.roleId = 0.0;
hit.materialId = 0.0;
hit.stepCount = 0.0;
hit.lodTier = 0.0;
hit.costTier = 0.0;
int agentIndex = clamp((int)round(input.agentIndex), 0, AGENT_VISUAL_COUNT - 1);
considerPrimitiveHit(cameraPosition, rayDirection, agentIndex, 0.0, farDistance, hit);
if (!hit.hit)
{
discard;
}
float3 p = cameraPosition + rayDirection * hit.travel;
SceneOut output;
output.colorTravel = float4(shadeBody(uv, hit.travel, p, hit.normal, hit.primitiveId), min(hit.travel, farDistance + 1.0));
output.metadata = float4(hit.fieldId, hit.normal);
output.control = float4(hit.materialId, 1.0, hit.stepCount / 72.0, hit.lodTier + hit.costTier * 0.1);
output.eventColor = float4(0.0, 0.0, 0.0, 0.0);
output.eventMetadata = float4(FIELD_ID_GRID, farDistance + 1.0, 0.0, 0.0);
output.depth = saturate(hit.travel / max(farDistance, 0.001));
return output;
}

View file

@ -0,0 +1,83 @@
#ifndef AQUARIUM_D3D12_SDF_MATH_HLSLI
#define AQUARIUM_D3D12_SDF_MATH_HLSLI
float sdSphere(float3 p, float radius)
{
return length(p) - radius;
}
float sdTorus(float3 p, float2 radius)
{
float2 q = float2(length(p.xy) - radius.x, p.z);
return length(q) - radius.y;
}
float sdSuperellipsoid(float3 p, float3 scale, float exponent)
{
float3 q = abs(p) / scale;
float value = pow(pow(q.x, exponent) + pow(q.y, exponent) + pow(q.z, exponent), 1.0 / exponent);
return (value - 1.0) * min(scale.x, min(scale.y, scale.z));
}
float sdEllipsoid(float3 p, float3 radius)
{
float3 safeRadius = max(radius, 0.001);
float k0 = length(p / safeRadius);
float k1 = length(p / (safeRadius * safeRadius));
return k0 * (k0 - 1.0) / max(k1, 0.001);
}
float smoothUnion(float a, float b, float radius)
{
float h = saturate(0.5 + 0.5 * (b - a) / radius);
return lerp(b, a, h) - radius * h * (1.0 - h);
}
float teardropProfileRadius(float z, float contactZ, float tipZ, float radiusScale, float ripplePhase, float rippleAmount)
{
float u = saturate((z - contactZ) / (tipZ - contactZ));
float x = u * 2.0 - 1.0;
float halfTerm = (1.0 - x) * 0.5;
float teardropWeight = halfTerm * halfTerm * halfTerm;
float baseRadius = radiusScale * sqrt(saturate(1.0 - x * x)) * teardropWeight;
float rippleEnvelope = smoothstep(0.08, 0.22, u) * (1.0 - smoothstep(0.76, 0.94, u));
float rippleRadius = min(rippleAmount, baseRadius * 0.07) * sin(ripplePhase) * rippleEnvelope;
return max(baseRadius + rippleRadius, 0.0);
}
float sdTeardropRevolution(float3 local, float contactZ, float tipZ, float radiusScale, float ripplePhase, float rippleAmount)
{
float2 samplePoint = float2(length(local.xy), local.z);
float profileRadius = teardropProfileRadius(samplePoint.y, contactZ, tipZ, radiusScale, ripplePhase, rippleAmount);
float radialDistance = samplePoint.x - profileRadius;
float topDistance = samplePoint.y - tipZ;
float bottomDistance = contactZ - samplePoint.y;
return max(radialDistance, max(topDistance, bottomDistance));
}
float sdHibiscusCursorPetal(float3 local, float angle, float timeSeconds)
{
float2 radial = float2(cos(angle), sin(angle));
float2 tangent = float2(-radial.y, radial.x);
float phase = timeSeconds * 1.35 + angle * 0.7;
float3 center = float3(radial * 0.18, 0.04 + 0.035 * sin(phase));
float3 p = local - center;
float3 q = float3(dot(p.xy, radial), dot(p.xy, tangent), p.z);
float taper = saturate((q.z + 1.0) * 0.55);
float edgeCurl = 0.035 * sin(q.x * 8.0 + phase) * taper;
return sdEllipsoid(q + float3(0.0, 0.0, edgeCurl), float3(0.62, 0.19, 0.72));
}
float sdHibiscusCursor(float3 local, float timeSeconds)
{
float petal0 = sdHibiscusCursorPetal(local, 0.35 + timeSeconds * 0.12, timeSeconds);
float petal1 = sdHibiscusCursorPetal(local, 2.444395 + timeSeconds * 0.12, timeSeconds);
float petal2 = sdHibiscusCursorPetal(local, 4.53879 + timeSeconds * 0.12, timeSeconds);
float petals = min(petal0, min(petal1, petal2));
float throat = sdEllipsoid(local - float3(0.0, 0.0, -0.12), float3(0.28, 0.28, 0.50));
float body = smoothUnion(petals, throat, 0.075);
float contactTip = length(float2(length(local.xy) * 1.22, local.z + 1.0)) - 0.035;
return smoothUnion(body, contactTip, 0.05);
}
#endif

View file

@ -27,3 +27,4 @@
{"timestamp":"2026-05-11T16:34:00+01:00","topic":"imagination-sdf-march-conservatism","lesson":"Visible missing structure in Imagination came from shallow petal overlap plus a too-brave march through chained smooth unions. Petals now sit deeper into the core, use broader axes and larger union radii, and agent tracing uses 72 steps with smaller hit epsilon and 0.12 step scale.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"visible artifact review"}
{"timestamp":"2026-05-11T16:39:00+01:00","topic":"imagination-sdf-petal-legibility","lesson":"Overcorrecting Imagination into a continuous blob destroyed the intended petal read. The better LOD 1 shape uses a small central seed, five narrow ellipsoid petals, and intentional negative space with only a tiny smooth union at the seed.","files":["src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","state/memory.json"],"source":"visible artifact review"}
{"timestamp":"2026-05-11T21:40:00+00:00","topic":"bounded-body-proxy-pass","lesson":"The fullscreen scene pass should own only background and Grid. Self, cursor, and role bodies now render through AgentVisualGpu-driven bounded proxy draws: one instanced conservative screen rectangle per object, object-local raymarching, and travel-derived depth writes so Grid and body occlusion stay honest.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","docs/hlsl-renderer.md","state/map.yaml","state/memory.json"],"source":"user architecture correction"}
{"timestamp":"2026-05-11T22:07:07+01:00","topic":"shader-boundary-body-pass","lesson":"D3D12Scene is now environment/Grid only. Bounded body proxy draws compile from D3D12Bodies.hlsl, reusable SDF math lives in D3D12SdfMath.hlsli, current agent character organs live in D3D12AgentCharacters.hlsli, and D3D12Renderer expands local includes before D3DCompile because the Vortice convenience compile path does not provide a usable include handler here. The cursor is now a luminous three-lobed hibiscus anchored on XY with its contact tip at Grid z=0.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12Bodies.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12AgentCharacters.hlsli","docs/hlsl-renderer.md","state/map.yaml","state/memory.json"],"source":"user architecture correction"}

View file

@ -15,6 +15,9 @@ current_model:
renderer: src/Aquarium.Engine/Render/D3D12Renderer.cs
grid_shader: src/Aquarium.Engine/Render/Shaders/D3D12Grid.hlsl
scene_shader: src/Aquarium.Engine/Render/Shaders/D3D12Scene.hlsl
bodies_shader: src/Aquarium.Engine/Render/Shaders/D3D12Bodies.hlsl
sdf_math_include: src/Aquarium.Engine/Render/Shaders/D3D12SdfMath.hlsli
agent_characters_include: src/Aquarium.Engine/Render/Shaders/D3D12AgentCharacters.hlsli
post_shader: src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl
overlay_text: src/Aquarium.Engine/Render/DirectWriteOverlay.cs
debug_ui: src/Aquarium.Engine/Render/Ui/DebugUi.cs
@ -57,7 +60,9 @@ renderer_state:
- 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.
- Fullscreen scene pass owns background and Grid only; bodies render through one bounded instanced proxy draw per object with travel-derived depth.
- Fullscreen scene pass owns background and Grid only; D3D12Bodies owns bounded instanced proxy draws, body SDF tracing, body lighting, and travel-derived depth.
- Reusable SDF primitives live in D3D12SdfMath.hlsli; current role character organs live in D3D12AgentCharacters.hlsli.
- Cursor is a luminous three-lobed hibiscus SDF centered one cursor radius above the XY plane so its contact tip reaches Grid z=0 without projecting to the Grid surface.
- SDF/analytic bodies for Self, CPU-authored agent visuals, and the cursor locator upload current and previous centers through `AgentVisualGpu`; Body plus Imagination use LOD 1 role SDFs.
- Agent SDF visual language is documented against Epiphany's published CultNet surfaces: identity from agent memory, motion from heartbeat, posture from role/coordinator/result surfaces, pressure from reorient/pressure surfaces, and expression through bounded orbit wandering plus CPU-visible gravity-well pulses.
- Body light buffer feeds Self emission and direct body lighting; future other Selves should join this light lane, not a generic field-instance table.

View file

@ -30,11 +30,12 @@
"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 reflective surface over the scalar height field. It writes the primary surface packet with FIELD_ID_GRID, terrain normal, full coverage, and Studio2 PMREM reflection; flat regions sample up to PMREM mip 3 while sloped/waved regions sharpen toward mip 0. Ray misses use a cone-averaged Studio2 PMREM mip 3 as the soft background so low-resolution mip texels do not become visible blocks.",
"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.",
"The cursor locator is currently a luminous three-lobed hibiscus SDF in the body proxy pass. Its center stays at cursor XY with z equal to cursor radius, so its contact tip reaches Grid z=0 without sampling or projecting to the Grid surface. The previous MathWorld teardrop curve profile remains reusable SDF math for future objects: x=cos(t), y=sin(t)*sin^m(t/2), radius `sqrt(1 - x^2) * ((1 - x) / 2)^3`.",
"Role-specific Epiphany agent bodies should be driven by published CultNet surfaces, not private React projection folklore: identity and temperament from epiphany.agent_memory, motion from epiphany.agent_heartbeat, posture from epiphany.surface.roles/coordinator/role_result, and continuity pressure from epiphany.surface.pressure/reorient. The first durable renderer seam should be an AgentVisualState contract before adding per-role SDF organs. Orbit slots are home anchors, not cages: agents may wander a bounded distance for expression, and vertical motion should come from CPU-visible gravity-well pulses that also affect Grid placement.",
"Epiphany publishes semantic state, not Aquarium world anchors. AgentVisualState may derive local evidence, artifact, work, review, and continuity anchors, but those are Aquarium-owned diegetic layout rules. Do not require Epiphany graph nodes, jobs, or artifacts to publish spatial coordinates.",
"Realtime role SDFs must render through per-agent proxy bounds, not a scene-global mega-SDF. Sphere-trace only conservative distance bounds, select one role SDF after proxy hit, give every expensive feature a local bound, compute normals only after hit, and require LOD plus debug views for step count, proxy hits, material id, LOD tier, and SDF cost tier before adding full organ detail.",
"The fullscreen scene pass owns background and Grid only. Self, cursor, and role bodies render through bounded per-object proxy draws using AgentVisualGpu, conservative screen rectangles from center plus bound radius, and travel-derived depth writes for Grid/body occlusion.",
"The fullscreen scene pass owns background and Grid only. Self, cursor, and role bodies render through D3D12Bodies bounded per-object proxy draws using AgentVisualGpu, conservative screen rectangles from center plus bound radius, and travel-derived depth writes for Grid/body occlusion. Do not put body proxy entrypoints or role SDF code back into D3D12Scene.",
"Reusable SDF primitives and preserved formulas belong in D3D12SdfMath.hlsli. Current role character organs belong in D3D12AgentCharacters.hlsli. D3D12Renderer expands local shader includes before D3DCompile because the Vortice convenience path does not provide a working include handler here.",
"The first live AgentVisualState slice uploads current and previous centers, role id, state scalars, and LOD through AgentVisualGpu. Temporal reprojection must use those uploaded centers for agent field ids; do not rederive moving agent centers separately in post.",
"Role SDF animation should avoid raw atan2 polar fields for lobe deformation unless the branch cut is explicitly handled. Use continuous harmonic polynomials over normalized XY directions for rotational lobes so sphere tracing does not open visible seams.",
"If a role SDF still shows cut-through gaps after removing angular branch cuts, stop using radial pseudo-distance deformation for that organ. Prefer smooth unions of analytic primitives with conservative bounds so the marcher sees connected surfaces instead of decorative distance fiction.",