Split agent bodies into role shaders
This commit is contained in:
parent
408244c7ce
commit
3c241356dc
19 changed files with 766 additions and 619 deletions
|
|
@ -8,10 +8,12 @@ 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.
|
||||
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`.
|
||||
3. Each visible body has its own proxy shader and pipeline:
|
||||
`D3D12FaceAgent.hlsl`, `D3D12ImaginationAgent.hlsl`,
|
||||
`D3D12EyesAgent.hlsl`, `D3D12BodyAgent.hlsl`, `D3D12HandsAgent.hlsl`,
|
||||
`D3D12SoulAgent.hlsl`, `D3D12LifeAgent.hlsl`, `D3D12SelfBody.hlsl`, and
|
||||
`D3D12CursorBody.hlsl`. Shared proxy mechanics live in
|
||||
`D3D12BodyCommon.hlsli` and `D3D12BodyProxy.hlsli`.
|
||||
4. `D3D12Post.hlsl` builds bloom, resolves diagnostics/history, applies
|
||||
exposure and ACES, then presents.
|
||||
5. `DirectWriteOverlay` draws crisp final-pixel debug UI after scene rendering.
|
||||
|
|
@ -35,15 +37,15 @@ and fade out on flat surfaces.
|
|||
|
||||
The fullscreen scene pass owns environment and Grid only. Bodies are not folded
|
||||
into that pass. After the Grid writes scene color and travel-derived depth,
|
||||
each body gets an instanced proxy quad whose vertex shader computes a
|
||||
conservative screen rectangle from the uploaded body center and bound radius.
|
||||
The proxy pixel shader raymarches only that object and writes travel-derived
|
||||
depth so the Grid and nearer bodies arbitrate visibility through the depth
|
||||
target.
|
||||
each body gets its own proxy draw and shader pipeline. The shared proxy vertex
|
||||
shader computes a conservative screen rectangle from the uploaded body center
|
||||
and bound radius. The body-specific pixel shader raymarches only that object
|
||||
and writes travel-derived depth so the Grid and nearer bodies arbitrate
|
||||
visibility through the depth target.
|
||||
|
||||
## Solids
|
||||
|
||||
Self, the cursor, and role bodies are uploaded through `AgentVisualGpu`,
|
||||
Self, Face, Imagination, Eyes, Body, Hands, Soul, Life, and the cursor are uploaded through `AgentVisualGpu`,
|
||||
including current center, previous center, role id, activity, heartbeat,
|
||||
pressure, expression, object kind, and LOD tier. The first visual slice keeps
|
||||
the fixed orbit fallback, renders Body and Imagination as LOD 1 role SDFs inside
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private const int GridHeightTextureSize = 128;
|
||||
private const Format GridHeightFormat = Format.R16_Float;
|
||||
private const Format SceneDepthFormat = Format.D32_Float;
|
||||
private const int AgentVisualCount = 7;
|
||||
private const int SelfObjectIndex = AgentVisualCount - 2;
|
||||
private const int RoleAgentCount = 7;
|
||||
private const int AgentVisualCount = RoleAgentCount + 2;
|
||||
private const int SelfObjectIndex = RoleAgentCount;
|
||||
private const int CursorObjectIndex = AgentVisualCount - 1;
|
||||
private const int GridHeightBrushCount = AgentVisualCount - 1;
|
||||
private const int BodyLightCount = 8;
|
||||
|
|
@ -41,7 +42,17 @@ 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 BodyCommonShaderRelativePath = "Render/Shaders/D3D12BodyCommon.hlsli";
|
||||
private const string BodyProxyShaderRelativePath = "Render/Shaders/D3D12BodyProxy.hlsli";
|
||||
private const string FaceAgentShaderRelativePath = "Render/Shaders/D3D12FaceAgent.hlsl";
|
||||
private const string ImaginationAgentShaderRelativePath = "Render/Shaders/D3D12ImaginationAgent.hlsl";
|
||||
private const string EyesAgentShaderRelativePath = "Render/Shaders/D3D12EyesAgent.hlsl";
|
||||
private const string BodyAgentShaderRelativePath = "Render/Shaders/D3D12BodyAgent.hlsl";
|
||||
private const string HandsAgentShaderRelativePath = "Render/Shaders/D3D12HandsAgent.hlsl";
|
||||
private const string SoulAgentShaderRelativePath = "Render/Shaders/D3D12SoulAgent.hlsl";
|
||||
private const string LifeAgentShaderRelativePath = "Render/Shaders/D3D12LifeAgent.hlsl";
|
||||
private const string SelfBodyShaderRelativePath = "Render/Shaders/D3D12SelfBody.hlsl";
|
||||
private const string CursorBodyShaderRelativePath = "Render/Shaders/D3D12CursorBody.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";
|
||||
|
|
@ -82,7 +93,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private ID3D12PipelineState? gridHeightBasePipelineState;
|
||||
private ID3D12PipelineState? gridHeightBrushPipelineState;
|
||||
private ID3D12PipelineState? scenePipelineState;
|
||||
private ID3D12PipelineState? agentProxyPipelineState;
|
||||
private readonly ID3D12PipelineState?[] bodyProxyPipelineStates = new ID3D12PipelineState?[AgentVisualCount];
|
||||
private ID3D12PipelineState? bloomPrefilterPipelineState;
|
||||
private ID3D12PipelineState? bloomDownsamplePipelineState;
|
||||
private ID3D12PipelineState? bloomBlurHorizontalPipelineState;
|
||||
|
|
@ -426,6 +437,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightBasePipelineState is not null
|
||||
&& gridHeightBrushPipelineState is not null
|
||||
&& scenePipelineState is not null
|
||||
&& bodyProxyPipelineStates.All(pipeline => pipeline is not null)
|
||||
&& bloomPrefilterPipelineState is not null
|
||||
&& bloomDownsamplePipelineState is not null
|
||||
&& bloomBlurHorizontalPipelineState is not null
|
||||
|
|
@ -602,8 +614,13 @@ 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.Bodies);
|
||||
agentProxy.Name = "Aquarium D3D12 Agent Proxy Pipeline";
|
||||
var bodyProxies = new ID3D12PipelineState[AgentVisualCount];
|
||||
for (var index = 0; index < AgentVisualCount; index++)
|
||||
{
|
||||
bodyProxies[index] = CreateAgentProxyPipelineState(paths.BodyShaders[index]);
|
||||
bodyProxies[index].Name = $"Aquarium D3D12 Body Proxy Pipeline {index}";
|
||||
}
|
||||
|
||||
var bloomPrefilter = CreateBloomPrefilterPipelineState(paths.Post);
|
||||
bloomPrefilter.Name = "Aquarium D3D12 Bloom Prefilter Pipeline";
|
||||
var bloomDownsample = CreateBloomDownsamplePipelineState(paths.Post);
|
||||
|
|
@ -619,7 +636,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightBase,
|
||||
gridHeightBrush,
|
||||
scene,
|
||||
agentProxy,
|
||||
bodyProxies,
|
||||
bloomPrefilter,
|
||||
bloomDownsample,
|
||||
bloomBlurHorizontal,
|
||||
|
|
@ -895,8 +912,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
context.CommandList.IASetPrimitiveTopology(PrimitiveTopology.TriangleList);
|
||||
context.CommandList.DrawInstanced(3, 1, 0, 0);
|
||||
|
||||
context.CommandList.SetPipelineState(agentProxyPipelineState!);
|
||||
context.CommandList.DrawInstanced(6, AgentVisualCount, 0, 0);
|
||||
for (var bodyIndex = 0; bodyIndex < AgentVisualCount; bodyIndex++)
|
||||
{
|
||||
context.CommandList.SetPipelineState(bodyProxyPipelineStates[bodyIndex]!);
|
||||
context.CommandList.DrawInstanced(6, 1, 0, (uint)bodyIndex);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -1422,7 +1442,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightBasePipelineState!,
|
||||
gridHeightBrushPipelineState!,
|
||||
scenePipelineState!,
|
||||
agentProxyPipelineState!,
|
||||
bodyProxyPipelineStates.Select(pipeline => pipeline!).ToArray(),
|
||||
bloomPrefilterPipelineState!,
|
||||
bloomDownsamplePipelineState!,
|
||||
bloomBlurHorizontalPipelineState!,
|
||||
|
|
@ -1436,7 +1456,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightBasePipelineState = pipelines.GridHeightBase;
|
||||
gridHeightBrushPipelineState = pipelines.GridHeightBrush;
|
||||
scenePipelineState = pipelines.Scene;
|
||||
agentProxyPipelineState = pipelines.AgentProxy;
|
||||
for (var index = 0; index < AgentVisualCount; index++)
|
||||
{
|
||||
bodyProxyPipelineStates[index] = pipelines.BodyProxies[index];
|
||||
}
|
||||
bloomPrefilterPipelineState = pipelines.BloomPrefilter;
|
||||
bloomDownsamplePipelineState = pipelines.BloomDownsample;
|
||||
bloomBlurHorizontalPipelineState = pipelines.BloomBlurHorizontal;
|
||||
|
|
@ -1450,7 +1473,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
gridHeightBasePipelineState = null;
|
||||
gridHeightBrushPipelineState = null;
|
||||
scenePipelineState = null;
|
||||
agentProxyPipelineState = null;
|
||||
Array.Clear(bodyProxyPipelineStates);
|
||||
bloomPrefilterPipelineState = null;
|
||||
bloomDownsamplePipelineState = null;
|
||||
bloomBlurHorizontalPipelineState = null;
|
||||
|
|
@ -1681,7 +1704,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
private ID3D12PipelineState CreateAgentProxyPipelineState(string path)
|
||||
{
|
||||
return CreateFullscreenPipelineState(path, "D3D12AgentProxyVS", "D3D12AgentProxyPS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat], enableDepth: true);
|
||||
return CreateFullscreenPipelineState(path, "D3D12AgentProxyVS", "D3D12BodyProxyPS", [SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat, SceneHdrFormat], enableDepth: true);
|
||||
}
|
||||
|
||||
private ID3D12PipelineState CreateBloomPrefilterPipelineState(string path)
|
||||
|
|
@ -1853,7 +1876,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
|
||||
private static float AgentRoleId(int index)
|
||||
{
|
||||
ReadOnlySpan<float> roleIds = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f];
|
||||
ReadOnlySpan<float> roleIds = [1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f];
|
||||
return roleIds[Math.Clamp(index, 0, roleIds.Length - 1)];
|
||||
}
|
||||
|
||||
|
|
@ -1960,18 +1983,24 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
Vector4 CenterRadius3,
|
||||
Vector4 CenterRadius4,
|
||||
Vector4 CenterRadius5,
|
||||
Vector4 CenterRadius6,
|
||||
Vector4 CenterRadius7,
|
||||
Vector4 Shape0,
|
||||
Vector4 Shape1,
|
||||
Vector4 Shape2,
|
||||
Vector4 Shape3,
|
||||
Vector4 Shape4,
|
||||
Vector4 Shape5,
|
||||
Vector4 Shape6,
|
||||
Vector4 Shape7,
|
||||
Vector4 Wave0,
|
||||
Vector4 Wave1,
|
||||
Vector4 Wave2,
|
||||
Vector4 Wave3,
|
||||
Vector4 Wave4,
|
||||
Vector4 Wave5)
|
||||
Vector4 Wave5,
|
||||
Vector4 Wave6,
|
||||
Vector4 Wave7)
|
||||
{
|
||||
public void Set(int index, Vector4 centerRadius, Vector4 shape, Vector4 wave)
|
||||
{
|
||||
|
|
@ -2007,6 +2036,16 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
Shape5 = shape;
|
||||
Wave5 = wave;
|
||||
break;
|
||||
case 6:
|
||||
CenterRadius6 = centerRadius;
|
||||
Shape6 = shape;
|
||||
Wave6 = wave;
|
||||
break;
|
||||
case 7:
|
||||
CenterRadius7 = centerRadius;
|
||||
Shape7 = shape;
|
||||
Wave7 = wave;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(index), index, "Grid height brush index is outside the fixed brush table.");
|
||||
}
|
||||
|
|
@ -2038,22 +2077,37 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
private sealed record D3D12ShaderPaths(
|
||||
string Grid,
|
||||
string Scene,
|
||||
string Bodies,
|
||||
string BodyCommon,
|
||||
string BodyProxy,
|
||||
IReadOnlyList<string> BodyShaders,
|
||||
string SdfMath,
|
||||
string AgentCharacters,
|
||||
string Post)
|
||||
{
|
||||
public IReadOnlyList<string> All { get; } = [Grid, Scene, Bodies, SdfMath, AgentCharacters, Post];
|
||||
public IReadOnlyList<string> All { get; } = [Grid, Scene, BodyCommon, BodyProxy, ..BodyShaders, SdfMath, AgentCharacters, Post];
|
||||
|
||||
public static D3D12ShaderPaths FromRoot(string root)
|
||||
{
|
||||
string shaderPath(string relativePath) => Path.Combine(root, Path.GetFileName(relativePath));
|
||||
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)));
|
||||
shaderPath(GridShaderRelativePath),
|
||||
shaderPath(SceneShaderRelativePath),
|
||||
shaderPath(BodyCommonShaderRelativePath),
|
||||
shaderPath(BodyProxyShaderRelativePath),
|
||||
[
|
||||
shaderPath(FaceAgentShaderRelativePath),
|
||||
shaderPath(ImaginationAgentShaderRelativePath),
|
||||
shaderPath(EyesAgentShaderRelativePath),
|
||||
shaderPath(BodyAgentShaderRelativePath),
|
||||
shaderPath(HandsAgentShaderRelativePath),
|
||||
shaderPath(SoulAgentShaderRelativePath),
|
||||
shaderPath(LifeAgentShaderRelativePath),
|
||||
shaderPath(SelfBodyShaderRelativePath),
|
||||
shaderPath(CursorBodyShaderRelativePath),
|
||||
],
|
||||
shaderPath(SdfMathShaderRelativePath),
|
||||
shaderPath(AgentCharactersShaderRelativePath),
|
||||
shaderPath(PostShaderRelativePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2061,7 +2115,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
ID3D12PipelineState GridHeightBase,
|
||||
ID3D12PipelineState GridHeightBrush,
|
||||
ID3D12PipelineState Scene,
|
||||
ID3D12PipelineState AgentProxy,
|
||||
IReadOnlyList<ID3D12PipelineState> BodyProxies,
|
||||
ID3D12PipelineState BloomPrefilter,
|
||||
ID3D12PipelineState BloomDownsample,
|
||||
ID3D12PipelineState BloomBlurHorizontal,
|
||||
|
|
@ -2075,7 +2129,11 @@ public sealed class D3D12Renderer : IAquariumRenderer
|
|||
BloomBlurHorizontal.Dispose();
|
||||
BloomDownsample.Dispose();
|
||||
BloomPrefilter.Dispose();
|
||||
AgentProxy.Dispose();
|
||||
foreach (var bodyProxy in BodyProxies)
|
||||
{
|
||||
bodyProxy.Dispose();
|
||||
}
|
||||
|
||||
Scene.Dispose();
|
||||
GridHeightBrush.Dispose();
|
||||
GridHeightBase.Dispose();
|
||||
|
|
|
|||
|
|
@ -1,576 +0,0 @@
|
|||
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;
|
||||
}
|
||||
27
src/Aquarium.Engine/Render/Shaders/D3D12BodyAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12BodyAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentBodySdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
265
src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli
Normal file
265
src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
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);
|
||||
|
||||
static const int ROLE_AGENT_COUNT = 7;
|
||||
static const int AGENT_VISUAL_COUNT = ROLE_AGENT_COUNT + 2;
|
||||
static const int SELF_OBJECT_INDEX = ROLE_AGENT_COUNT;
|
||||
static const int CURSOR_OBJECT_INDEX = AGENT_VISUAL_COUNT - 1;
|
||||
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 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 BodySurface
|
||||
{
|
||||
float distanceValue;
|
||||
float materialId;
|
||||
float fieldId;
|
||||
float roleId;
|
||||
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;
|
||||
}
|
||||
|
||||
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 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 shadeRoleAgentBody(float3 p, float3 normal, int agentIndex)
|
||||
{
|
||||
float roleId = agentVisuals[agentIndex].previousCenterRole.w;
|
||||
float materialPulse = agentVisuals[agentIndex].state.y;
|
||||
float3 emission = primitiveEmissionRadiance(FIELD_ID_AGENT_BASE + (float)agentIndex);
|
||||
float3 albedo = lerp(float3(0.34, 0.42, 0.18), float3(0.70, 0.76, 0.42), hash21(float2(agentIndex, 6.3)));
|
||||
float roughness = lerp(0.46, 0.72, hash21(float2(agentIndex, 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;
|
||||
}
|
||||
80
src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli
Normal file
80
src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
float3 bodyNormal(float3 p, int agentIndex)
|
||||
{
|
||||
float epsilon = 0.006;
|
||||
float dx = bodySurface(p + float3(epsilon, 0.0, 0.0), agentIndex).distanceValue - bodySurface(p - float3(epsilon, 0.0, 0.0), agentIndex).distanceValue;
|
||||
float dy = bodySurface(p + float3(0.0, epsilon, 0.0), agentIndex).distanceValue - bodySurface(p - float3(0.0, epsilon, 0.0), agentIndex).distanceValue;
|
||||
float dz = bodySurface(p + float3(0.0, 0.0, epsilon), agentIndex).distanceValue - bodySurface(p - float3(0.0, 0.0, epsilon), agentIndex).distanceValue;
|
||||
return normalize(float3(dx, dy, dz));
|
||||
}
|
||||
|
||||
bool traceBody(float3 origin, float3 direction, int agentIndex, out float travel, out float3 normal, out BodySurface surface, out float stepCount)
|
||||
{
|
||||
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;
|
||||
stepCount = 0.0;
|
||||
surface = bodySurface(agent.centerRadius.xyz, agentIndex);
|
||||
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 endTravel = min(-b + h, farDistance);
|
||||
travel = max(-b - h, 0.0);
|
||||
normal = 0.0;
|
||||
stepCount = 0.0;
|
||||
surface = bodySurface(origin + direction * travel, agentIndex);
|
||||
|
||||
[loop]
|
||||
for (int stepIndex = 0; stepIndex < 72; stepIndex++)
|
||||
{
|
||||
if (travel > endTravel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float3 p = origin + direction * travel;
|
||||
surface = bodySurface(p, agentIndex);
|
||||
stepCount = (float)(stepIndex + 1);
|
||||
if (abs(surface.distanceValue) < max(0.0016, travel * 0.00018))
|
||||
{
|
||||
normal = bodyNormal(p, agentIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
travel += max(abs(surface.distanceValue) * 0.12, 0.0016);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
SceneOut D3D12BodyProxyPS(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);
|
||||
int agentIndex = clamp((int)round(input.agentIndex), 0, AGENT_VISUAL_COUNT - 1);
|
||||
|
||||
float travel;
|
||||
float3 normal;
|
||||
BodySurface surface;
|
||||
float stepCount;
|
||||
if (!traceBody(cameraPosition, rayDirection, agentIndex, travel, normal, surface, stepCount))
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float3 p = cameraPosition + rayDirection * travel;
|
||||
SceneOut output;
|
||||
output.colorTravel = float4(shadeBody(uv, travel, p, normal, agentIndex, surface), min(travel, farDistance + 1.0));
|
||||
output.metadata = float4(surface.fieldId, normal);
|
||||
output.control = float4(surface.materialId, 1.0, stepCount / 72.0, surface.lodTier + surface.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(travel / max(farDistance, 0.001));
|
||||
return output;
|
||||
}
|
||||
92
src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl
Normal file
92
src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
|
||||
static const float CURSOR_RADIUS = 0.56;
|
||||
|
||||
float cursorHibiscusSdf(float3 p)
|
||||
{
|
||||
AgentVisual cursor = agentVisuals[CURSOR_OBJECT_INDEX];
|
||||
float3 local = (p - cursor.centerRadius.xyz) / CURSOR_RADIUS;
|
||||
return sdHibiscusCursor(local, timeSeconds) * CURSOR_RADIUS;
|
||||
}
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
BodySurface surface;
|
||||
surface.distanceValue = cursorHibiscusSdf(p);
|
||||
surface.materialId = 5.0;
|
||||
surface.fieldId = FIELD_ID_CURSOR;
|
||||
surface.roleId = 0.0;
|
||||
surface.lodTier = 0.0;
|
||||
surface.costTier = 1.0;
|
||||
return surface;
|
||||
}
|
||||
|
||||
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 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 agentIndex, BodySurface surface)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
27
src/Aquarium.Engine/Render/Shaders/D3D12EyesAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12EyesAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentFallbackSdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
27
src/Aquarium.Engine/Render/Shaders/D3D12FaceAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12FaceAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentFallbackSdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
|
|
@ -22,9 +22,9 @@ cbuffer AquariumFrame : register(b0)
|
|||
|
||||
cbuffer GridHeightBrushes : register(b1)
|
||||
{
|
||||
float4 brushCenterRadius[6];
|
||||
float4 brushShape[6];
|
||||
float4 brushWave[6];
|
||||
float4 brushCenterRadius[8];
|
||||
float4 brushShape[8];
|
||||
float4 brushWave[8];
|
||||
};
|
||||
|
||||
struct VertexOut
|
||||
|
|
|
|||
27
src/Aquarium.Engine/Render/Shaders/D3D12HandsAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12HandsAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentFallbackSdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentImaginationSdf(local, agent, timeSeconds);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
27
src/Aquarium.Engine/Render/Shaders/D3D12LifeAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12LifeAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentFallbackSdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
|
|
@ -62,7 +62,7 @@ struct ResolveOut
|
|||
};
|
||||
|
||||
static const float SUN_RADIUS = 1.12;
|
||||
static const int AGENT_VISUAL_COUNT = 5;
|
||||
static const int AGENT_VISUAL_COUNT = 7;
|
||||
static const float FIELD_ID_SELF = 2.0;
|
||||
static const float FIELD_ID_GRID = 4.0;
|
||||
static const float FIELD_ID_CURSOR = 5.0;
|
||||
|
|
|
|||
25
src/Aquarium.Engine/Render/Shaders/D3D12SelfBody.hlsl
Normal file
25
src/Aquarium.Engine/Render/Shaders/D3D12SelfBody.hlsl
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = sdSphere(local, 1.0) * radius;
|
||||
surface.materialId = 0.0;
|
||||
surface.fieldId = FIELD_ID_SELF;
|
||||
surface.roleId = 0.0;
|
||||
surface.lodTier = 0.0;
|
||||
surface.costTier = 0.0;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return primitiveEmissionRadiance(FIELD_ID_SELF);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
27
src/Aquarium.Engine/Render/Shaders/D3D12SoulAgent.hlsl
Normal file
27
src/Aquarium.Engine/Render/Shaders/D3D12SoulAgent.hlsl
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include "D3D12BodyCommon.hlsli"
|
||||
#include "D3D12SdfMath.hlsli"
|
||||
#include "D3D12AgentCharacters.hlsli"
|
||||
|
||||
BodySurface bodySurface(float3 p, int agentIndex)
|
||||
{
|
||||
AgentVisual agent = agentVisuals[agentIndex];
|
||||
float radius = max(agent.centerRadius.w, 0.001);
|
||||
float3 local = (p - agent.centerRadius.xyz) / radius;
|
||||
AgentSurface agentSurface = agentFallbackSdf(local, agent);
|
||||
|
||||
BodySurface surface;
|
||||
surface.distanceValue = agentSurface.distanceValue * radius;
|
||||
surface.materialId = agentSurface.materialId;
|
||||
surface.fieldId = FIELD_ID_AGENT_BASE + (float)agentIndex;
|
||||
surface.roleId = agent.previousCenterRole.w;
|
||||
surface.lodTier = agent.lodIndexFlags.x;
|
||||
surface.costTier = agentSurface.costTier;
|
||||
return surface;
|
||||
}
|
||||
|
||||
float3 shadeBody(float2 uv, float travel, float3 p, float3 normal, int agentIndex, BodySurface surface)
|
||||
{
|
||||
return shadeRoleAgentBody(p, normal, agentIndex);
|
||||
}
|
||||
|
||||
#include "D3D12BodyProxy.hlsli"
|
||||
|
|
@ -28,3 +28,5 @@
|
|||
{"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"}
|
||||
{"timestamp":"2026-05-11T22:17:28+01:00","topic":"per-body-shader-boundary","lesson":"Body proxy rendering now uses one shader file and one proxy pipeline per visible body slot: Face, Imagination, Eyes, Body, Hands, Self, and Cursor. Shared proxy plumbing lives in D3D12BodyCommon.hlsli and D3D12BodyProxy.hlsli, but body identity SDF and material code should stay split by body rather than collapsing into a single role or Self bucket.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli","src/Aquarium.Engine/Render/Shaders/D3D12FaceAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12ImaginationAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12EyesAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12BodyAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12HandsAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SelfBody.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.hlsl","docs/hlsl-renderer.md","state/map.yaml","state/memory.json"],"source":"user architecture correction"}
|
||||
{"timestamp":"2026-05-11T22:18:54+01:00","topic":"eight-agent-body-table","lesson":"The visible Epiphany agent body table is Self, Face, Imagination, Eyes, Body, Hands, Soul, and Life. Cursor remains a separate non-agent body. Renderer constants, body shader paths, proxy pipelines, and post reprojection counts should track seven role agents plus Self plus cursor, not the older five-role provisional slice.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/Shaders/D3D12Post.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12SoulAgent.hlsl","src/Aquarium.Engine/Render/Shaders/D3D12LifeAgent.hlsl","docs/hlsl-renderer.md","state/map.yaml","state/memory.json"],"source":"user role table correction"}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,17 @@ 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
|
||||
body_common_include: src/Aquarium.Engine/Render/Shaders/D3D12BodyCommon.hlsli
|
||||
body_proxy_include: src/Aquarium.Engine/Render/Shaders/D3D12BodyProxy.hlsli
|
||||
face_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12FaceAgent.hlsl
|
||||
imagination_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12ImaginationAgent.hlsl
|
||||
eyes_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12EyesAgent.hlsl
|
||||
body_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12BodyAgent.hlsl
|
||||
hands_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12HandsAgent.hlsl
|
||||
soul_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12SoulAgent.hlsl
|
||||
life_agent_shader: src/Aquarium.Engine/Render/Shaders/D3D12LifeAgent.hlsl
|
||||
self_body_shader: src/Aquarium.Engine/Render/Shaders/D3D12SelfBody.hlsl
|
||||
cursor_body_shader: src/Aquarium.Engine/Render/Shaders/D3D12CursorBody.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
|
||||
|
|
@ -60,10 +70,10 @@ 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; D3D12Bodies owns bounded instanced proxy draws, body SDF tracing, body lighting, and travel-derived depth.
|
||||
- Fullscreen scene pass owns background and Grid only; each visible body owns a separate proxy pipeline and shader file, with shared proxy plumbing factored into HLSL includes.
|
||||
- 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.
|
||||
- SDF/analytic bodies for Self, Face, Imagination, Eyes, Body, Hands, Soul, Life, 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.
|
||||
- Studio2 PMREM and irradiance DDS cubemaps are loaded as D3D12 TextureCubes; PMREM serves roughness-mip specular, irradiance serves Lambertian diffuse IBL for non-metal bodies.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
"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 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.",
|
||||
"The fullscreen scene pass owns background and Grid only. Self, Face, Imagination, Eyes, Body, Hands, Soul, Life, and cursor each render through their own shader file and proxy pipeline using AgentVisualGpu, conservative screen rectangles from center plus bound radius, and travel-derived depth writes for Grid/body occlusion. Shared body proxy mechanics may live in includes; body identity SDF and material code should not collapse back into a single body shader.",
|
||||
"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.",
|
||||
|
|
|
|||
Loading…
Reference in a new issue