Fix per-body proxy indexing

This commit is contained in:
Meta Vens 2026-05-11 22:29:22 +01:00
commit da8ee10a2a
13 changed files with 46 additions and 23 deletions

View file

@ -27,9 +27,10 @@ public sealed class D3D12Renderer : IAquariumRenderer
private const Format SceneDepthFormat = Format.D32_Float;
private const int RoleAgentCount = 7;
private const int AgentVisualCount = RoleAgentCount + 2;
private const int SelfObjectIndex = RoleAgentCount;
private const int SelfObjectIndex = 0;
private const int RoleAgentBaseIndex = 1;
private const int CursorObjectIndex = AgentVisualCount - 1;
private const int GridHeightBrushCount = AgentVisualCount - 1;
private const int GridHeightBrushCount = RoleAgentCount + 1;
private const int BodyLightCount = 8;
private const float GridTransparentMinZ = -1.85f;
private const float GridTransparentMaxZ = 0.45f;
@ -915,7 +916,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
for (var bodyIndex = 0; bodyIndex < AgentVisualCount; bodyIndex++)
{
context.CommandList.SetPipelineState(bodyProxyPipelineStates[bodyIndex]!);
context.CommandList.DrawInstanced(6, 1, 0, (uint)bodyIndex);
context.CommandList.DrawInstanced(6, 1, 0, 0);
}
}
finally
@ -1117,7 +1118,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
0.82f,
1.25f);
for (var index = 0; index < SelfObjectIndex; index++)
for (var index = 0; index < RoleAgentCount; index++)
{
var radius = AgentRadius(index);
var center = AgentAnchor(index, frame.TimeSeconds);
@ -1137,8 +1138,16 @@ public sealed class D3D12Renderer : IAquariumRenderer
private void BuildAgentVisualTable(AquariumFrame frame)
{
Array.Clear(agentVisuals);
for (var index = 0; index < SelfObjectIndex; index++)
var selfCenter = BodyCenterAtGridHeight(frame, Vector2.Zero, SunRadius);
agentVisuals[SelfObjectIndex] = new AgentVisualGpu(
new Vector4(selfCenter, SunRadius),
new Vector4(selfCenter, 0.0f),
new Vector4(1.0f, 1.0f, 0.0f, 0.0f),
new Vector4(0.0f, SelfObjectIndex, 1.0f, 0.0f));
for (var index = 0; index < RoleAgentCount; index++)
{
var visualIndex = RoleAgentBaseIndex + index;
var radius = AgentRadius(index);
var center = AgentCenterAtGridHeight(index, frame.TimeSeconds);
var previousCenter = AgentCenterAtGridHeight(index, previousTimeSeconds);
@ -1149,20 +1158,13 @@ public sealed class D3D12Renderer : IAquariumRenderer
var expression = Math.Abs(roleId - 2.0f) < 0.01f || Math.Abs(roleId - 4.0f) < 0.01f ? 0.72f : 0.38f;
var lod = 1.0f;
agentVisuals[index] = new AgentVisualGpu(
agentVisuals[visualIndex] = new AgentVisualGpu(
new Vector4(center, radius),
new Vector4(previousCenter, roleId),
new Vector4(activity, heartbeat, pressure, expression),
new Vector4(lod, index, 0.0f, 0.0f));
new Vector4(lod, visualIndex, 0.0f, 0.0f));
}
var selfCenter = BodyCenterAtGridHeight(frame, Vector2.Zero, SunRadius);
agentVisuals[SelfObjectIndex] = new AgentVisualGpu(
new Vector4(selfCenter, SunRadius),
new Vector4(selfCenter, 0.0f),
new Vector4(1.0f, 1.0f, 0.0f, 0.0f),
new Vector4(0.0f, SelfObjectIndex, 1.0f, 0.0f));
var cursorCenter = new Vector3(frame.CursorWorld, CursorBodyRadius);
var previousCursorCenter = new Vector3(previousCursorWorld, CursorBodyRadius);
agentVisuals[CursorObjectIndex] = new AgentVisualGpu(
@ -1893,7 +1895,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
* MathF.Sin((world.X * -0.04f + world.Y * 0.07f) - timeSeconds * 0.19f)
* 0.035f;
height += GridBrushHeight(world, Vector2.Zero, SelfGravityRadius, 2.85f, -1.34f, 0.18f, MathF.Tau, 0.82f, 1.25f, timeSeconds);
for (var index = 0; index < SelfObjectIndex; index++)
for (var index = 0; index < RoleAgentCount; index++)
{
var radius = AgentRadius(index);
height += GridBrushHeight(world, AgentAnchor(index, timeSeconds), 3.8f + radius * 2.5f, 2.1f, -0.42f, 0.022f, 2.4f, 1.35f, 0.0f, timeSeconds);
@ -2095,6 +2097,7 @@ public sealed class D3D12Renderer : IAquariumRenderer
shaderPath(BodyCommonShaderRelativePath),
shaderPath(BodyProxyShaderRelativePath),
[
shaderPath(SelfBodyShaderRelativePath),
shaderPath(FaceAgentShaderRelativePath),
shaderPath(ImaginationAgentShaderRelativePath),
shaderPath(EyesAgentShaderRelativePath),
@ -2102,7 +2105,6 @@ public sealed class D3D12Renderer : IAquariumRenderer
shaderPath(HandsAgentShaderRelativePath),
shaderPath(SoulAgentShaderRelativePath),
shaderPath(LifeAgentShaderRelativePath),
shaderPath(SelfBodyShaderRelativePath),
shaderPath(CursorBodyShaderRelativePath),
],
shaderPath(SdfMathShaderRelativePath),

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 4;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -44,7 +44,7 @@ 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 SELF_OBJECT_INDEX = 0;
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;
@ -244,7 +244,7 @@ AgentProxyVertexOut D3D12AgentProxyVS(uint vertexId : SV_VertexID, uint instance
float2(-1.0, 1.0),
};
AgentVisual agent = agentVisuals[instanceId];
AgentVisual agent = agentVisuals[BODY_INDEX];
float3 forward;
float3 right;
float3 up;
@ -260,6 +260,6 @@ AgentProxyVertexOut D3D12AgentProxyVS(uint vertexId : SV_VertexID, uint instance
AgentProxyVertexOut output;
output.position = float4(clipCenter + corners[vertexId] * clipRadius, 0.0, 1.0);
output.agentIndex = (float)instanceId;
output.agentIndex = (float)BODY_INDEX;
return output;
}

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 8;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 3;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 1;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 5;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 2;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 7;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"

View file

@ -62,7 +62,8 @@ struct ResolveOut
};
static const float SUN_RADIUS = 1.12;
static const int AGENT_VISUAL_COUNT = 7;
static const int ROLE_AGENT_COUNT = 7;
static const int AGENT_VISUAL_COUNT = ROLE_AGENT_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;
@ -178,7 +179,7 @@ float gridHeightAt(float2 world, float sampleTime)
height += gridBrushHeight(world, 0.0, SELF_GRAVITY_RADIUS, 2.85, -1.34, 0.18, 6.28318530718, 0.82, 1.25, sampleTime);
[unroll]
for (int index = 0; index < AGENT_VISUAL_COUNT; index++)
for (int index = 0; index < ROLE_AGENT_COUNT; index++)
{
float radius = planetRadius(index);
height += gridBrushHeight(world, planetAnchorAt(index, sampleTime), 3.8 + radius * 2.5, 2.1, -0.42, 0.022, 2.4, 1.35, 0.0, sampleTime);
@ -227,8 +228,8 @@ float3 temporalPreviousWorldPosition(float3 worldPosition, float fieldId)
if (abs(fieldId - FIELD_ID_CURSOR) < 0.25)
{
float3 currentCenter = bodyCenterAtGridHeight(cursorWorlds.xy, 0.56, timeSeconds);
float3 previousCenter = bodyCenterAtGridHeight(cursorWorlds.zw, 0.56, previousTimeSeconds);
float3 currentCenter = float3(cursorWorlds.xy, 0.56);
float3 previousCenter = float3(cursorWorlds.zw, 0.56);
return previousCenter + (worldPosition - currentCenter);
}

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 0;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"

View file

@ -1,3 +1,5 @@
static const int BODY_INDEX = 6;
#include "D3D12BodyCommon.hlsli"
#include "D3D12SdfMath.hlsli"
#include "D3D12AgentCharacters.hlsli"