218 lines
108 KiB
C#
218 lines
108 KiB
C#
|
|
// Unit tests for light clustering code used in Forward+ and Deferred+ rendering
|
||
|
|
// modes.
|
||
|
|
|
||
|
|
using NUnit.Framework;
|
||
|
|
using Unity.Collections;
|
||
|
|
using Unity.Jobs;
|
||
|
|
using Unity.Mathematics;
|
||
|
|
using UnityEngine.Rendering.Universal.Internal;
|
||
|
|
using UnityEngine.TestTools;
|
||
|
|
|
||
|
|
namespace UnityEngine.Rendering.Universal.Tests
|
||
|
|
{
|
||
|
|
class LightClusteringTests
|
||
|
|
{
|
||
|
|
[Description("Test that an orthographic camera tilted down at a 45 degree angle clusters reflection probes properly. This test specifically focuses on making sure that the convex hull logic in the tiling jobs works as intended, because the reflection probe volume forms collinear points. This test was added due to UUM-58983.")]
|
||
|
|
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.WindowsEditor, RuntimePlatform.WindowsPlayer, RuntimePlatform.OSXEditor, RuntimePlatform.OSXPlayer })]
|
||
|
|
[Test]
|
||
|
|
public void LightClustering_WithOrthographicCameraAndCollinearConvexHull_ZBinsAndTileMasksAreCorrect()
|
||
|
|
{
|
||
|
|
NativeArray<VisibleLight> lights = new(0, Allocator.TempJob);
|
||
|
|
NativeArray<VisibleReflectionProbe> probes = new(1, Allocator.TempJob);
|
||
|
|
probes[0] = new VisibleReflectionProbe()
|
||
|
|
{
|
||
|
|
bounds = new Bounds(Vector3.zero, new Vector3(5, 5, 5)),
|
||
|
|
localToWorldMatrix = Matrix4x4.identity,
|
||
|
|
center = Vector3.zero,
|
||
|
|
blendDistance = 0,
|
||
|
|
};
|
||
|
|
NativeArray<uint> zBins = new(UniversalRenderPipeline.maxZBinWords, Allocator.TempJob);
|
||
|
|
NativeArray<uint> tileMasks = new (UniversalRenderPipeline.maxTileWords, Allocator.TempJob);
|
||
|
|
|
||
|
|
float4x4 worldToView = new float4x4(
|
||
|
|
new float4(1, 0, 0, 0),
|
||
|
|
new float4(0, 0.707106709f, 0.707106829f, 0),
|
||
|
|
new float4(0, 0.707106829f, -0.707106709f, 0),
|
||
|
|
new float4(0, 0, -10, 1)
|
||
|
|
);
|
||
|
|
var worldToViews = new Fixed2<float4x4>(worldToView, worldToView);
|
||
|
|
float4x4 viewToClip = new float4x4(
|
||
|
|
new float4(0.0985474288f, 0, 0, 0),
|
||
|
|
new float4(0, 0.200000003f, 0, 0),
|
||
|
|
new float4(0, 0, -0.0200601816f, 0),
|
||
|
|
new float4(0, 0, -1.00601816f, 1)
|
||
|
|
);
|
||
|
|
var viewToClips = new Fixed2<float4x4>(viewToClip, viewToClip);
|
||
|
|
int2 screenResolution = new(128, 128);
|
||
|
|
float nearPlane = 0.3f;
|
||
|
|
float farPlane = 100f;
|
||
|
|
|
||
|
|
JobHandle handle = ForwardLights.ScheduleClusteringJobs(
|
||
|
|
lights,
|
||
|
|
probes,
|
||
|
|
zBins,
|
||
|
|
tileMasks,
|
||
|
|
worldToViews,
|
||
|
|
viewToClips,
|
||
|
|
1,
|
||
|
|
screenResolution,
|
||
|
|
nearPlane,
|
||
|
|
farPlane,
|
||
|
|
true,
|
||
|
|
out int localLightCount,
|
||
|
|
out int directionalLightCount,
|
||
|
|
out int binCount,
|
||
|
|
out float zBinScale,
|
||
|
|
out float zBinOffset,
|
||
|
|
out int2 tileResolution,
|
||
|
|
out int actualTileWidth,
|
||
|
|
out int wordsPerTile
|
||
|
|
);
|
||
|
|
JobHandle.ScheduleBatchedJobs();
|
||
|
|
handle.Complete();
|
||
|
|
|
||
|
|
// Uncomment temporarily if the reference arrays need to be updated.
|
||
|
|
// Debug.Log(string.Join(",", zBins));
|
||
|
|
// Debug.Log(string.Join(",", tileMasks));
|
||
|
|
|
||
|
|
// If the following assertions fail, there isn't currently good
|
||
|
|
// tooling to visualize the difference. A 3D texture slice viewer
|
||
|
|
// can be built that would fix this issue. But the cost-benefit is
|
||
|
|
// not worth it at the moment, since the diff of a PR that fails
|
||
|
|
// this test can be enough to go on.
|
||
|
|
//
|
||
|
|
// Also, these assertions can fail if a change is made includes more
|
||
|
|
// false positives, i.e. lights contributing to _more_ clusters than
|
||
|
|
// expected due to increased conservatism, or lights contributing to
|
||
|
|
// _less_ clusters due increased accuracy. In either of these cases,
|
||
|
|
// it is up to the author of these code changes to update the
|
||
|
|
// expected values.
|
||
|
|
CollectionAssert.AreEqual(expectedZBins0, zBins);
|
||
|
|
CollectionAssert.AreEqual(expectedTileMasks0, tileMasks);
|
||
|
|
|
||
|
|
lights.Dispose();
|
||
|
|
probes.Dispose();
|
||
|
|
zBins.Dispose();
|
||
|
|
tileMasks.Dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
static readonly uint[] expectedZBins0 =
|
||
|
|
{
|
||
|
|
65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,0,1,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,65535,0,65535,655
|
||
|
|
};
|
||
|
|
|
||
|
|
static readonly uint[] expectedTileMasks0 =
|
||
|
|
{
|
||
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||
|
|
};
|
||
|
|
|
||
|
|
[Description("The tiling job calculates an intersection between an XZ plane and the light volume to determine the range of tiles that the light affects. In the cases where this range falls completely outside of the screen, this test ensures that the ranges are clamped correctly to screen boundaries. If not tested, this bug affects the cone section of spot lights, the cap section of spot lights, and also point lights. This test was added due to UUM-84591.")]
|
||
|
|
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.WindowsEditor, RuntimePlatform.WindowsPlayer, RuntimePlatform.OSXEditor, RuntimePlatform.OSXPlayer })]
|
||
|
|
[Test]
|
||
|
|
public void LightClustering_WhenLightVolumeIntersectionWithXZPlaneIsOutsideTheScreen_ZBinsAndTileMasksAreCorrect()
|
||
|
|
{
|
||
|
|
NativeArray<VisibleLight> lights = new(1, Allocator.TempJob);
|
||
|
|
// Light world transform:
|
||
|
|
// UnityEditor.TransformWorldPlacementJSON:{"position":{"x":3.0,"y":3.0,"z":0.0},"rotation":{"x":0.511572539806366,"y":0.3068491518497467,"z":-0.7767189145088196,"w":0.20210090279579163},"scale":{"x":1.0,"y":1.0,"z":1.0}}
|
||
|
|
lights[0] = new VisibleLight()
|
||
|
|
{
|
||
|
|
lightType = LightType.Spot,
|
||
|
|
finalColor = Color.white,
|
||
|
|
screenRect = new Rect(0, 0, 1, 1),
|
||
|
|
localToWorldMatrix = new Matrix4x4(
|
||
|
|
new Vector4(-0.394897342f, 0, -0.918725133f, 0),
|
||
|
|
new Vector4(0.627902389f, -0.729997516f, -0.269892514f, 0),
|
||
|
|
new Vector4(-0.670667171f, -0.683449626f, 0.288274288f, 0),
|
||
|
|
new Vector4(3, 3, 0, 1)
|
||
|
|
),
|
||
|
|
range = 10,
|
||
|
|
spotAngle = 100,
|
||
|
|
intersectsNearPlane = true,
|
||
|
|
intersectsFarPlane = false,
|
||
|
|
};
|
||
|
|
NativeArray<VisibleReflectionProbe> probes = new(0, Allocator.TempJob);
|
||
|
|
NativeArray<uint> zBins = new(UniversalRenderPipeline.maxZBinWords, Allocator.TempJob);
|
||
|
|
NativeArray<uint> tileMasks = new (UniversalRenderPipeline.maxTileWords, Allocator.TempJob);
|
||
|
|
|
||
|
|
// Camera world transform:
|
||
|
|
// UnityEditor.TransformWorldPlacementJSON:{"position":{"x":-4.0,"y":1.0,"z":2.0},"rotation":{"x":0.32139381766319277,"y":0.663413941860199,"z":-0.3830222189426422,"w":0.5566704273223877},"scale":{"x":1.0,"y":1.0,"z":1.0}}
|
||
|
|
float4x4 worldToView = new float4x4(
|
||
|
|
new float4(-0.1736481f, 0.8528686f, -0.4924039f, 0f),
|
||
|
|
new float4(0f, 0.5f, 0.8660254f, 0f),
|
||
|
|
new float4(-0.9848078f, -0.1503837f, 0.08682406f, 0f),
|
||
|
|
new float4(1.275023f, 3.212242f, -3.009289f, 1f)
|
||
|
|
);
|
||
|
|
var worldToViews = new Fixed2<float4x4>(worldToView, worldToView);
|
||
|
|
float4x4 viewToClip = new float4x4(
|
||
|
|
new float4(0.7968904f, 0f, 0f, 0f),
|
||
|
|
new float4(0f, 1.732051f, 0f, 0f),
|
||
|
|
new float4(0f, 0f, -1.0006f, -1f),
|
||
|
|
new float4(0f, 0f, -0.60018f, 0f)
|
||
|
|
);
|
||
|
|
var viewToClips = new Fixed2<float4x4>(viewToClip, viewToClip);
|
||
|
|
int2 screenResolution = new(128, 128);
|
||
|
|
float nearPlane = 0.3f;
|
||
|
|
float farPlane = 1000f;
|
||
|
|
|
||
|
|
JobHandle handle = ForwardLights.ScheduleClusteringJobs(
|
||
|
|
lights,
|
||
|
|
probes,
|
||
|
|
zBins,
|
||
|
|
tileMasks,
|
||
|
|
worldToViews,
|
||
|
|
viewToClips,
|
||
|
|
1,
|
||
|
|
screenResolution,
|
||
|
|
nearPlane,
|
||
|
|
farPlane,
|
||
|
|
false,
|
||
|
|
out int localLightCount,
|
||
|
|
out int directionalLightCount,
|
||
|
|
out int binCount,
|
||
|
|
out float zBinScale,
|
||
|
|
out float zBinOffset,
|
||
|
|
out int2 tileResolution,
|
||
|
|
out int actualTileWidth,
|
||
|
|
out int wordsPerTile
|
||
|
|
);
|
||
|
|
JobHandle.ScheduleBatchedJobs();
|
||
|
|
handle.Complete();
|
||
|
|
|
||
|
|
// Uncomment temporarily if the reference arrays need to be updated.
|
||
|
|
// Debug.Log(string.Join(",", zBins));
|
||
|
|
// Debug.Log(string.Join(",", tileMasks));
|
||
|
|
|
||
|
|
// If the following assertions fail, there isn't currently good
|
||
|
|
// tooling to visualize the difference. A 3D texture slice viewer
|
||
|
|
// can be built that would fix this issue. But the cost-benefit is
|
||
|
|
// not worth it at the moment, since the diff of a PR that fails
|
||
|
|
// this test can be enough to go on.
|
||
|
|
//
|
||
|
|
// Also, these assertions can fail if a change is made includes more
|
||
|
|
// false positives, i.e. lights contributing to _more_ clusters than
|
||
|
|
// expected due to increased conservatism, or lights contributing to
|
||
|
|
// _less_ clusters due increased accuracy. In either of these cases,
|
||
|
|
// it is up to the author of these code changes to update the
|
||
|
|
// expected values.
|
||
|
|
CollectionAssert.AreEqual(expectedZBins1, zBins);
|
||
|
|
CollectionAssert.AreEqual(expectedTileMasks1, tileMasks);
|
||
|
|
|
||
|
|
lights.Dispose();
|
||
|
|
probes.Dispose();
|
||
|
|
zBins.Dispose();
|
||
|
|
tileMasks.Dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
static readonly uint[] expectedZBins1 =
|
||
|
|
{
|
||
|
|
0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,65535,1,0,6
|
||
|
|
};
|
||
|
|
|
||
|
|
static readonly uint[] expectedTileMasks1 =
|
||
|
|
{
|
||
|
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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