fix(render): correct foliage-wind classification, receiver/caster desync, and frame binding (Campaign VM VM6 review)
Opus dual-lens review of the three VM6 commits (0930c35d,39e8408c,6cc5e183) found two blockers and two should-fix issues; all landed here along with the review's nits and documentation corrections. Blockers: - A1: the procedural-scenery classifier tested bit 31 alone instead of the full top nibble (0xF000_0000 == 0x8000_0000), so it also matched LandblockStaticEntityIdAllocator's 0xC... namespace (fences/gates/ building shells with a cutout subset), the 0xDA11_D0xx paperdoll id, and the 0xFFFF_FF01 portal-tunnel id as procedural scenery — all three would have swayed. ProceduralSceneryIdAllocator.IsInNamespace now does the exact top-nibble test; FoliageWindClassification delegates to it. - A2: GroupKey (the receiver's instance-batching key) did not carry FoliageFlags while the caster's dedup key already did, so a scenery instance and a non-scenery instance sharing a mesh subset coalesced into one receiver InstanceGroup whose flags were last-writer-wins — disagreeing with the correctly-keyed caster. GroupKey now carries FoliageFlags, computed before key construction and set exactly once at group creation; the imperative re-stamp is gone, and CachedBatch's now-redundant FoliageFlags field is removed. Should-fix: - A3: the world receiver pass bound UniformAtmosphericFrame only by accident (leftover from the caster pass, which runs first each frame, since Vulkan binding state isn't reset between passes). DirectionalShadowFrameBinding now carries the caster's exact AtmosphericFrameBufferBinding and BindDirectionalShadowReceiver binds it explicitly. - A4: a Setup-composed tree's opaque trunk part never got the trunk flag because HasCutoutSubset is cached per GfxObj part, not per entity. FoliageWindClassification.ComputeEntityHasCutoutSubset now ORs HasCutoutSubset across an entity's resolved sibling parts once per entity, threaded into ClassifyBatches/AddDirectionalShadowBatches via a new optional override parameter. Nits: A5 hashes the per-vertex flutter seed relative to the instance origin instead of absolute world XY (fp32 sin() precision loss at far landblock corners), mirrored in both foliage_wind.glsl and FoliageWindModel; A7 documents the max(maxHeight, 0.5) divide-guard as a deliberate pseudocode divergence; A8 switches FoliageWindExclusions' construction to ToFrozenSet() and softens the "never stale" doc comment to "no slower than one frame behind." Tests added: top-nibble classification (0xFFFFFFFFu now correctly false), GroupKey inequality across entity-driven scenery/landblock- static classification, a caster-batch test proving the same pairing never coalesces, ComputeEntityHasCutoutSubset unit + end-to-end two-part-Setup tests, the caster→receiver AtmosphericFrame binding carry-through, flutter-hash translation invariance relative to instance origin, and a Storm-wind mid-height displacement floor guarding against a "no motion" regression. Docs: plan VM6 body corrected to the five-row WeatherKind table, "bits 1 and 2", "all four" caster shaders, and top-nibble wording throughout; the owner gate checklist's Rain/Storm step; the stale v1-only shader- interface compatibility entry; semantic-bindings-v1.md's v2 members folded into the main 192-byte block; the IA-25 register row's top- nibble wording; AtmosphericFrameInputs.cs's ABI size reference. foliage_wind.glsl's A5 change recompiled exactly the five shaders that include it (mesh_atmospheric.vert, the four directional_shadow_world_* casters) plus the manifest; no other .spv changed. Verify: Release build 0 warnings/0 errors. App hermetic-lane filter 6,041/0 failed (no environment-specific failures this run). RenderPackValidator 30/30. Full hermetic-filtered solution: 15,269/0 failed across 15 projects. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
27a446f05c
commit
43e3abed4d
28 changed files with 724 additions and 123 deletions
|
|
@ -390,6 +390,83 @@ public sealed class DirectionalShadowGpuTests
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round (A3): the receiver pass must not
|
||||
/// depend on the caster pass's own AtmosphericFrame bind surviving
|
||||
/// un-reset until the receiver pass runs later in the frame — it must
|
||||
/// bind set 3/binding 5 itself, from the EXACT buffer/offset/size the
|
||||
/// caster bound. This asserts the seam that makes that possible:
|
||||
/// TryGetCurrentFrameBinding's DirectionalShadowFrameBinding.AtmosphericFrame
|
||||
/// carries the identical buffer identity, offset, and size the caster's
|
||||
/// own recorded GpuRecordedUniformBind calls used — the value
|
||||
/// WbDrawDispatcher.BindDirectionalShadowReceiver reads to issue its own
|
||||
/// bind.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void CasterFrameBindingCarriesTheExactAtmosphericFrameBufferForTheReceiverSeam()
|
||||
{
|
||||
using var device = new RecordingGpuDevice();
|
||||
using var renderer = new DirectionalSunShadowRenderer(device, DirectionalShadowPreset.Medium);
|
||||
DirectionalShadowPreparedDraws world = CreateWorldDraws(device.DefaultTextureSlot);
|
||||
DirectionalShadowTerrainPreparedDraws terrain = CreateTerrainDraws();
|
||||
using IGpuBuffer worldVertices = Buffer(device, "world-v", GpuBufferUsage.Vertex);
|
||||
using IGpuBuffer worldIndices = Buffer(device, "world-i", GpuBufferUsage.Index);
|
||||
using IGpuBuffer terrainVertices = Buffer(device, "terrain-v", GpuBufferUsage.Vertex);
|
||||
using IGpuBuffer terrainIndices = Buffer(device, "terrain-i", GpuBufferUsage.Index);
|
||||
var worldGeometry = new DirectionalShadowMeshGeometry(worldVertices, worldIndices);
|
||||
var terrainGeometry = new DirectionalShadowTerrainGeometry(terrainVertices, terrainIndices);
|
||||
var environment = new DirectionalShadowEnvironmentState(
|
||||
DirectionalShadowGateReason.Enabled,
|
||||
Vector3.Normalize(new Vector3(0.1f, 0.2f, 1f)),
|
||||
0.9f,
|
||||
0.75f,
|
||||
1.1f,
|
||||
AuthoredCelestialShadowSourceKind.Sun,
|
||||
SourceObjectIndex: -1,
|
||||
SourceGfxObjId: 0);
|
||||
using IGpuBuffer atmosphericBuffer = Buffer(device, "test-atmospheric-frame", GpuBufferUsage.Uniform);
|
||||
var atmosphericFrame = new AtmosphericFrameBufferBinding(
|
||||
atmosphericBuffer,
|
||||
OffsetBytes: 64u,
|
||||
SizeBytes: 192u);
|
||||
|
||||
device.Clear();
|
||||
using IGpuFrame frame = device.BeginFrame();
|
||||
WorldTransformFrameSlice sharedTransforms = PublishSharedTransforms(frame, world.Transforms);
|
||||
renderer.RenderPrepared(
|
||||
frame,
|
||||
environment,
|
||||
Matrix4x4.Identity,
|
||||
Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 3f, 16f / 9f, 0.1f, 500f),
|
||||
cameraNearMeters: 0.1f,
|
||||
casterDepthPaddingMeters: 48f,
|
||||
world,
|
||||
terrain,
|
||||
worldGeometry,
|
||||
terrainGeometry,
|
||||
sharedTransforms,
|
||||
atmosphericFrame: atmosphericFrame);
|
||||
|
||||
// The caster pass's OWN recorded bind used exactly this buffer/offset/size.
|
||||
GpuRecordedUniformBind casterAtmosphericBind = Assert.Single(
|
||||
device.OfKind<GpuRecordedUniformBind>()
|
||||
.DistinctBy(call => (call.BufferName, call.OffsetBytes, call.SizeBytes)),
|
||||
call => call.Binding == GpuBindingModel.UniformAtmosphericFrame);
|
||||
Assert.Equal("test-atmospheric-frame", casterAtmosphericBind.BufferName);
|
||||
Assert.Equal(64u, casterAtmosphericBind.OffsetBytes);
|
||||
Assert.Equal(192u, casterAtmosphericBind.SizeBytes);
|
||||
|
||||
// The receiver seam carries forward the IDENTICAL binding — this is
|
||||
// what BindDirectionalShadowReceiver reads to bind set 3/binding 5
|
||||
// itself, rather than depending on the caster's bind surviving
|
||||
// un-reset until the receiver pass runs.
|
||||
Assert.True(renderer.TryGetCurrentFrameBinding(frame, out DirectionalShadowFrameBinding binding));
|
||||
Assert.True(binding.AtmosphericFrame.IsBound);
|
||||
Assert.Same(atmosphericBuffer, binding.AtmosphericFrame.Buffer);
|
||||
Assert.Equal(atmosphericFrame.OffsetBytes, binding.AtmosphericFrame.OffsetBytes);
|
||||
Assert.Equal(atmosphericFrame.SizeBytes, binding.AtmosphericFrame.SizeBytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StableTopology_ReusesRetainedCommandBuffersWithoutFrameRingCopies()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -203,6 +203,89 @@ public sealed class FoliageWindModelTests
|
|||
Assert.NotEqual(reference, farAway);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FlutterHashIsRelativeToInstanceOriginSoTranslatingTheWholeTreeDoesNotChangeIt()
|
||||
{
|
||||
// Review fix round A5: the per-vertex flutter hash is computed from
|
||||
// worldPos.xy - instanceOrigin.xy (relative to the tree's own base),
|
||||
// not absolute world XY. A tree near the world origin and the exact
|
||||
// same tree translated tens of thousands of metres away (a far
|
||||
// landblock corner, where fp32 sin() of a large ABSOLUTE coordinate
|
||||
// loses precision and produced visibly patterned flutter pre-fix)
|
||||
// must produce identical displacement for the identical local leaf
|
||||
// offset.
|
||||
//
|
||||
// ph = dot(instanceOrigin.xy, (0.137, 0.291)) is intentionally
|
||||
// instanceOrigin-dependent (it decorrelates neighbouring trees), so
|
||||
// this test holds it constant by translating along the direction
|
||||
// orthogonal to (0.137, 0.291) — (0.291, -0.137) — which leaves the
|
||||
// dot product, and therefore every ph-driven term (lean, branch,
|
||||
// gust envelope), unchanged while moving the absolute coordinates
|
||||
// by 50,000 units. Only the flutter hash's input changes shape
|
||||
// between the old (absolute) and new (relative) implementation, so
|
||||
// this test would have failed under the pre-fix code.
|
||||
var localOffset = new Vector3(3.7f, -2.1f, 4f); // fixed offset from trunk base to this leaf
|
||||
var nearOrigin = InstanceOrigin;
|
||||
var translation = new Vector3(0.291f, -0.137f, 0f) * 50_000f;
|
||||
var farOrigin = nearOrigin + translation;
|
||||
var clockWind = new Vector4(19.5f, 0.8f, 0.6f, 2.3f);
|
||||
|
||||
Vector3 nearVertex = nearOrigin + localOffset;
|
||||
Vector3 farVertex = farOrigin + localOffset;
|
||||
|
||||
Vector3 nearResult = FoliageWindModel.Displace(
|
||||
nearVertex,
|
||||
nearOrigin,
|
||||
FoliageWindClassification.CutoutFoliageFlag,
|
||||
clockWind,
|
||||
Amplitude);
|
||||
Vector3 farResult = FoliageWindModel.Displace(
|
||||
farVertex,
|
||||
farOrigin,
|
||||
FoliageWindClassification.CutoutFoliageFlag,
|
||||
clockWind,
|
||||
Amplitude);
|
||||
|
||||
Vector3 nearDisplacement = nearResult - nearVertex;
|
||||
Vector3 farDisplacement = farResult - farVertex;
|
||||
|
||||
AssertApproximatelyEqual(nearDisplacement, farDisplacement, tolerance: 1e-3f);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MidHeightCutoutDisplacementHasAPositiveFloorUnderStormWind()
|
||||
{
|
||||
// Review fix round: pin that a cutout leaf at mid-canopy height
|
||||
// (h = 0.5) actually moves under Storm-strength wind (mean 1.00,
|
||||
// gust 0.75 — FoliageWindByWeather's Storm row). Guards against a
|
||||
// regression that silently zeroes the whole displacement formula
|
||||
// (e.g. an accidental "no motion" early-out, a broken sign, or the
|
||||
// A5 relative-XY change degenerating to a constant hash).
|
||||
const float floorMetres = 0.01f;
|
||||
var stormClockWind = new Vector4(0f, 1.00f, 0.75f, 0f); // mean/gust match Storm
|
||||
Vector3 midHeightVertex = InstanceOrigin with
|
||||
{
|
||||
X = InstanceOrigin.X + 2.4f,
|
||||
Y = InstanceOrigin.Y - 1.1f,
|
||||
Z = InstanceOrigin.Z + (0.5f * Amplitude.W), // h = 0.5
|
||||
};
|
||||
|
||||
for (float t = 0f; t < 30f; t += 2.9f)
|
||||
{
|
||||
Vector3 result = FoliageWindModel.Displace(
|
||||
midHeightVertex,
|
||||
InstanceOrigin,
|
||||
FoliageWindClassification.CutoutFoliageFlag,
|
||||
stormClockWind with { X = t },
|
||||
Amplitude);
|
||||
|
||||
float magnitude = (result - midHeightVertex).Length();
|
||||
Assert.True(
|
||||
magnitude > floorMetres,
|
||||
$"t={t}: displacement magnitude {magnitude} did not clear the {floorMetres} m floor");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AssertApproximatelyEqual(
|
||||
Vector3 expected,
|
||||
Vector3 actual,
|
||||
|
|
|
|||
|
|
@ -129,6 +129,106 @@ public sealed class DirectionalShadowPreparedDrawTests
|
|||
Assert.Equal(1, product.Stats.RejectedFadedParts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round (A2): two instances of the IDENTICAL
|
||||
/// mesh subset (same index range, texture, material, cull mode) — one a
|
||||
/// procedural-scenery entity (top nibble 0x8), one a
|
||||
/// LandblockStaticEntityIdAllocator entity (top nibble 0xC) sharing the
|
||||
/// SAME GfxObj — classify to different FoliageWindClassification flags
|
||||
/// (0x2 cutout vs 0x0) via the identical Classify call the world
|
||||
/// receiver uses, and must land as two SEPARATE prepared caster
|
||||
/// batches/commands rather than coalescing into one. This is the
|
||||
/// caster-side half of "casters and receivers agree by construction":
|
||||
/// DirectionalShadowDrawKey (the caster's sort/group key, unlike the
|
||||
/// pre-fix receiver GroupKey) already includes FoliageFlags, so this
|
||||
/// pins that it stays correct.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SameSubsetDifferentFoliageClassificationNeverCoalescesIntoOneCasterBatch()
|
||||
{
|
||||
const uint sceneryEntityId = 0x80010203u; // ProceduralSceneryIdAllocator
|
||||
const uint landblockStaticEntityId = 0xC0010203u; // LandblockStaticEntityIdAllocator
|
||||
uint sceneryFlags = FoliageWindClassification.Classify(
|
||||
sceneryEntityId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.ClipMap,
|
||||
meshHasCutoutSubset: true);
|
||||
uint landblockStaticFlags = FoliageWindClassification.Classify(
|
||||
landblockStaticEntityId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.ClipMap,
|
||||
meshHasCutoutSubset: true);
|
||||
Assert.Equal(FoliageWindClassification.CutoutFoliageFlag, sceneryFlags);
|
||||
Assert.Equal(0u, landblockStaticFlags);
|
||||
|
||||
var product = new DirectionalShadowPreparedDraws();
|
||||
RenderSceneGeneration generation = RenderSceneGeneration.FromRaw(1);
|
||||
Assert.True(product.TryBegin(generation, 1, estimatedInstances: 2));
|
||||
Matrix4x4 sceneryTransform = Matrix4x4.CreateTranslation(1f, 2f, 3f);
|
||||
Matrix4x4 landblockStaticTransform = Matrix4x4.CreateTranslation(9f, 8f, 7f);
|
||||
GpuTextureSlot sharedTexture = new(42);
|
||||
|
||||
product.Add(
|
||||
firstIndex: 100,
|
||||
baseVertex: 5,
|
||||
indexCount: 12,
|
||||
sharedTexture,
|
||||
textureLayer: 0,
|
||||
CullMode.CounterClockwise,
|
||||
DirectionalShadowCasterMaterial.AlphaCutout,
|
||||
in sceneryTransform,
|
||||
sceneryFlags);
|
||||
product.Add(
|
||||
firstIndex: 100,
|
||||
baseVertex: 5,
|
||||
indexCount: 12,
|
||||
sharedTexture,
|
||||
textureLayer: 0,
|
||||
CullMode.CounterClockwise,
|
||||
DirectionalShadowCasterMaterial.AlphaCutout,
|
||||
in landblockStaticTransform,
|
||||
landblockStaticFlags);
|
||||
product.Complete(
|
||||
generation,
|
||||
1,
|
||||
new DirectionalShadowPreparationStats(
|
||||
SourceCasters: 2,
|
||||
SourceMeshRefs: 2,
|
||||
SourceParts: 2,
|
||||
SourceBatches: 2,
|
||||
PreparedInstances: 0,
|
||||
PreparedOpaqueCommands: 0,
|
||||
PreparedAlphaCutoutCommands: 0,
|
||||
RejectedTransparentBatches: 0,
|
||||
RejectedFadedParts: 0,
|
||||
MissingMeshes: 0,
|
||||
UnresolvedAlphaCutoutTextures: 0));
|
||||
|
||||
// Two distinct commands/batches, NOT one command with InstanceCount=2
|
||||
// — the identical geometry/texture/material would have coalesced
|
||||
// pre-fix, since only entity-level classification (which the caster
|
||||
// key did not carry before A2) tells them apart.
|
||||
Assert.Equal(2, product.Commands.Length);
|
||||
Assert.Equal(2, product.Batches.Length);
|
||||
Assert.All(product.Commands.ToArray(), command => Assert.Equal(1u, command.InstanceCount));
|
||||
|
||||
int sceneryIndex = product.Batches.ToArray()
|
||||
.ToList()
|
||||
.FindIndex(batch => batch.FoliageFlags == FoliageWindClassification.CutoutFoliageFlag);
|
||||
int landblockStaticIndex = product.Batches.ToArray()
|
||||
.ToList()
|
||||
.FindIndex(batch => batch.FoliageFlags == 0u);
|
||||
Assert.True(sceneryIndex >= 0, "expected one prepared batch carrying the cutout foliage flag");
|
||||
Assert.True(landblockStaticIndex >= 0, "expected one prepared batch carrying zero foliage flags");
|
||||
Assert.NotEqual(sceneryIndex, landblockStaticIndex);
|
||||
Assert.Equal(
|
||||
sceneryTransform,
|
||||
product.Transforms[(int)product.Commands[sceneryIndex].BaseInstance]);
|
||||
Assert.Equal(
|
||||
landblockStaticTransform,
|
||||
product.Transforms[(int)product.Commands[landblockStaticIndex].BaseInstance]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SameCasterBuild_ReplaysWithoutReclassificationOrStorageGrowth()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -97,13 +97,150 @@ public sealed class FoliageWindClassificationTests
|
|||
Assert.Equal(0u, flags);
|
||||
}
|
||||
|
||||
// Review fix round: the classifier tests the full top-nibble 0x8000_0000,
|
||||
// NOT bit 31 alone — bit 31 is also set by LandblockStaticEntityIdAllocator's
|
||||
// 0xC... namespace (top nibble 1100) and by the synthetic render ids
|
||||
// 0xDA11_D0xx (paperdoll) and 0xFFFF_FF01 (portal tunnel). The prior
|
||||
// [InlineData(0xFFFFFFFFu, true)] case pinned exactly this bug (0xFFFFFFFFu
|
||||
// has bit 31 set but is NOT a procedural-scenery id under the top-nibble
|
||||
// rule) — it is corrected to false below.
|
||||
[Theory]
|
||||
[InlineData(0x80000000u, true)]
|
||||
[InlineData(0x7FFFFFFFu, false)]
|
||||
[InlineData(0x80000000u, true)] // top nibble 0x8 exactly
|
||||
[InlineData(0x8FFFFFFFu, true)] // top nibble 0x8, every other bit set
|
||||
[InlineData(0x7FFFFFFFu, false)] // top nibble 0x7 — bit 31 clear
|
||||
[InlineData(0x00000000u, false)]
|
||||
[InlineData(0xFFFFFFFFu, true)]
|
||||
public void IsProceduralSceneryDecodesOnlyBit31(uint entityId, bool expected)
|
||||
[InlineData(0xFFFFFFFFu, false)] // top nibble 0xF — bit 31 set, NOT procedural scenery
|
||||
[InlineData(0xC0010203u, false)] // LandblockStaticEntityIdAllocator (top nibble 0xC) — fence/gate/building shell
|
||||
[InlineData(0xDA11D012u, false)] // ChargenPreviewEntityBuilder/CreatureAppraisalPresentation synthetic doll id
|
||||
[InlineData(0xFFFFFF01u, false)] // PortalTunnelPresentation synthetic id
|
||||
public void IsProceduralSceneryDecodesTheFullTopNibbleNotJustBit31(uint entityId, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, FoliageWindClassification.IsProceduralScenery(entityId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round (A2): GroupKey now carries
|
||||
/// FoliageFlags, so two otherwise-identical mesh-subset keys — same
|
||||
/// geometry/texture/translucency/cull mode — with different
|
||||
/// classification results are UNEQUAL keys, which is what makes a
|
||||
/// scenery instance and a non-scenery instance of the same GfxObj land
|
||||
/// in two separate WbDrawDispatcher groups instead of coalescing into
|
||||
/// one group whose flags depended on whichever entity classified it
|
||||
/// last. Flags are derived from real entity ids through
|
||||
/// <see cref="FoliageWindClassification.Classify"/> — a procedural-
|
||||
/// scenery id (0x8…, a tree's cutout leaf subset) versus a landblock-
|
||||
/// static id (0xC…, e.g. a fence with a cutout mesh subset) — matching
|
||||
/// the review's exact pairing and its 0x2/0x0 expected words, and the
|
||||
/// same pairing <c>DirectionalShadowPreparedDrawTests
|
||||
/// .SameSubsetDifferentFoliageClassificationNeverCoalescesIntoOneCasterBatch</c>
|
||||
/// proves the caster keeps separate.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void GroupKeysWithDifferentFoliageFlagsAreNeverEqualEvenWithIdenticalGeometry()
|
||||
{
|
||||
const uint proceduralSceneryTreeId = 0x80010203u; // top nibble 0x8
|
||||
const uint landblockStaticFenceId = 0xC0010203u; // top nibble 0xC
|
||||
|
||||
uint sceneryFlags = FoliageWindClassification.Classify(
|
||||
proceduralSceneryTreeId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.ClipMap,
|
||||
meshHasCutoutSubset: true);
|
||||
uint landblockStaticFlags = FoliageWindClassification.Classify(
|
||||
landblockStaticFenceId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.ClipMap,
|
||||
meshHasCutoutSubset: true);
|
||||
|
||||
Assert.Equal(FoliageWindClassification.CutoutFoliageFlag, sceneryFlags); // 0x2
|
||||
Assert.Equal(0u, landblockStaticFlags); // 0x0
|
||||
|
||||
var sceneryKey = new GroupKey(
|
||||
FirstIndex: 100,
|
||||
BaseVertex: 5,
|
||||
IndexCount: 12,
|
||||
TextureSlot: new AcDream.App.Rendering.Gpu.GpuTextureSlot(42),
|
||||
TextureLayer: 0,
|
||||
Translucency: TranslucencyKind.ClipMap,
|
||||
CullMode: DatReaderWriter.Enums.CullMode.CounterClockwise,
|
||||
FoliageFlags: sceneryFlags);
|
||||
var landblockStaticKey = sceneryKey with { FoliageFlags = landblockStaticFlags };
|
||||
|
||||
// Two otherwise-identical mesh-subset keys, differing only by the
|
||||
// entity-driven classification, are unequal — this is what makes
|
||||
// WbDrawDispatcher.GetOrCreateInstanceGroup place the two instances
|
||||
// in two separate InstanceGroups instead of coalescing them.
|
||||
Assert.NotEqual(sceneryKey, landblockStaticKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round (A4): ComputeEntityHasCutoutSubset
|
||||
/// ORs across every part regardless of WHICH part carries the cutout
|
||||
/// subset — this pins the "two-part Setup, part B has cutout" scenario
|
||||
/// at the algorithm level, decoupled from ObjectRenderData/mesh-adapter
|
||||
/// plumbing.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData(new[] { false, false }, false)]
|
||||
[InlineData(new[] { true, false }, true)]
|
||||
[InlineData(new[] { false, true }, true)] // part B (index 1) has the cutout
|
||||
[InlineData(new[] { true, true }, true)]
|
||||
public void ComputeEntityHasCutoutSubsetOrsAcrossEveryPart(bool[] partHasCutout, bool expected)
|
||||
{
|
||||
bool result = FoliageWindClassification.ComputeEntityHasCutoutSubset(
|
||||
partHasCutout,
|
||||
static value => value);
|
||||
|
||||
Assert.Equal(expected, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ComputeEntityHasCutoutSubsetIsFalseForAnEmptyPartList()
|
||||
{
|
||||
Assert.False(
|
||||
FoliageWindClassification.ComputeEntityHasCutoutSubset(
|
||||
Array.Empty<bool>(),
|
||||
static value => value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Campaign VM VM6 review fix round (A4), end to end at the
|
||||
/// classification level: a two-part Setup — part A is an opaque trunk
|
||||
/// with no cutout batches of its own, part B is the leaves (has a
|
||||
/// cutout subset). Classifying part A's opaque subset from its OWN
|
||||
/// (false) HasCutoutSubset never yields the trunk flag (the pre-fix
|
||||
/// bug); classifying it from the entity-scoped OR that
|
||||
/// ComputeEntityHasCutoutSubset computes across BOTH parts correctly
|
||||
/// yields TrunkFlag. Both WbDrawDispatcher.ClassifyBatches (receiver)
|
||||
/// and AddDirectionalShadowBatches (caster) now pass the entity-scoped
|
||||
/// value here instead of the part's own.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TwoPartSetupGivesTheOpaqueTrunkPartTheTrunkFlagWhenAnotherPartHasCutout()
|
||||
{
|
||||
const uint sceneryEntityId = 0x80010203u;
|
||||
bool[] partAHasCutoutSubset = [false]; // the trunk part's OWN mesh has no cutout batches
|
||||
bool[] setupPartsHasCutoutSubset = [false, true]; // part A (trunk), part B (leaves)
|
||||
|
||||
bool partAOwnHasCutoutSubset = FoliageWindClassification.ComputeEntityHasCutoutSubset(
|
||||
partAHasCutoutSubset,
|
||||
static value => value);
|
||||
bool entityScopedHasCutoutSubset = FoliageWindClassification.ComputeEntityHasCutoutSubset(
|
||||
setupPartsHasCutoutSubset,
|
||||
static value => value);
|
||||
|
||||
uint flagsFromPartOwnValue = FoliageWindClassification.Classify(
|
||||
sceneryEntityId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.Opaque,
|
||||
partAOwnHasCutoutSubset);
|
||||
uint flagsFromEntityScopedValue = FoliageWindClassification.Classify(
|
||||
sceneryEntityId,
|
||||
isExcluded: false,
|
||||
TranslucencyKind.Opaque,
|
||||
entityScopedHasCutoutSubset);
|
||||
|
||||
Assert.Equal(0u, flagsFromPartOwnValue); // the pre-fix bug: no flag at all
|
||||
Assert.Equal(FoliageWindClassification.TrunkFlag, flagsFromEntityScopedValue);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ public sealed class WbDrawDispatcherBucketingTests
|
|||
// at the top of the per-entity loop body in Draw.
|
||||
var groups = new Dictionary<GroupKey, List<Matrix4x4>>();
|
||||
var sortCenters = new List<Vector3>();
|
||||
void AppendInstance(GroupKey k, Matrix4x4 m, Vector3 localSortCenter, uint foliageFlags)
|
||||
void AppendInstance(GroupKey k, Matrix4x4 m, Vector3 localSortCenter)
|
||||
{
|
||||
if (!groups.TryGetValue(k, out var list))
|
||||
{
|
||||
|
|
@ -497,7 +497,6 @@ public sealed class WbDrawDispatcherBucketingTests
|
|||
}
|
||||
list.Add(m);
|
||||
sortCenters.Add(localSortCenter);
|
||||
_ = foliageFlags;
|
||||
}
|
||||
|
||||
Assert.True(cache.TryGet(EntityId, LandblockId, out var entryHit));
|
||||
|
|
@ -545,7 +544,7 @@ public sealed class WbDrawDispatcherBucketingTests
|
|||
WbDrawDispatcher.ApplyCacheHit(
|
||||
entry,
|
||||
Matrix4x4.Identity,
|
||||
(_, _, center, _) => observedCenter = center);
|
||||
(_, _, center) => observedCenter = center);
|
||||
|
||||
Assert.Equal(authoredCenter, observedCenter);
|
||||
}
|
||||
|
|
@ -788,7 +787,7 @@ public sealed class WbDrawDispatcherBucketingTests
|
|||
const uint EntityId = 100;
|
||||
const int MeshRefCount = 3;
|
||||
|
||||
void AppendInstance(GroupKey k, Matrix4x4 m, Vector3 localSortCenter, uint foliageFlags)
|
||||
void AppendInstance(GroupKey k, Matrix4x4 m, Vector3 localSortCenter)
|
||||
{
|
||||
if (!groups.TryGetValue(k, out var list))
|
||||
{
|
||||
|
|
@ -796,7 +795,6 @@ public sealed class WbDrawDispatcherBucketingTests
|
|||
groups[k] = list;
|
||||
}
|
||||
list.Add(m);
|
||||
_ = foliageFlags;
|
||||
}
|
||||
|
||||
for (int partIdx = 0; partIdx < MeshRefCount; partIdx++)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue