Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,261 @@
using System;
using System.Collections.Generic;
using Unity.Jobs;
using Unity.Collections;
using Unity.Mathematics;
namespace UnityEngine.PathTracing.Lightmapping
{
internal static class ChartIdentification
{
private static UInt32 FindRepWithPathCompression(Span<UInt32> reps, UInt32 vertexIdx)
{
UInt32 rep = reps[(int)vertexIdx];
if (rep == vertexIdx)
return vertexIdx;
rep = FindRepWithPathCompression(reps, rep);
reps[(int)vertexIdx] = rep;
return rep;
}
private static UInt32 FindRepresentative(Span<UInt32> reps, UInt32 vertexIdx)
{
UInt32 rep = reps[(int)vertexIdx];
return (rep == vertexIdx ? vertexIdx : FindRepresentative(reps, rep));
}
private static void Union(Span<UInt32> reps, UInt32 vertexIdx0, UInt32 vertexIdx1)
{
var rep0 = FindRepWithPathCompression(reps, vertexIdx0);
var rep1 = FindRepWithPathCompression(reps, vertexIdx1);
reps[(int)rep1] = rep0;
}
public static void UnionTriangleEdges(ReadOnlySpan<UInt32> triangleIndices, Span<UInt32> vertexChartIds)
{
Span<UInt32> reps = vertexChartIds;
Debug.Assert(triangleIndices.Length % 3 == 0);
int triangleCount = triangleIndices.Length / 3;
for (int triIdx = 0; triIdx < triangleCount; ++triIdx)
{
int offset = triIdx * 3;
UInt32 vertexIdx0 = triangleIndices[offset];
UInt32 vertexIdx1 = triangleIndices[offset + 1];
UInt32 vertexIdx2 = triangleIndices[offset + 2];
Union(reps, vertexIdx0, vertexIdx1);
Union(reps, vertexIdx1, vertexIdx2);
}
}
public static void UnionDuplicateVertices(ReadOnlySpan<float2> vertexUvs, ReadOnlySpan<float3> vertexPositions, ReadOnlySpan<float3> vertexNormals, Span<UInt32> vertexChartIds, bool respectNormals)
{
var map = new Dictionary<(float2, float3, float3), uint>();
for (uint i = 0; i < vertexChartIds.Length; ++i)
{
var tuple = (
vertexUvs[(int)i],
vertexPositions[(int)i],
respectNormals ? vertexNormals[(int)i] : float3.zero);
if (map.TryGetValue(tuple, out uint deduplicatedIndex))
{
Union(vertexChartIds, i, deduplicatedIndex);
}
else
{
map.Add(tuple, i);
}
}
}
public static void FindRepresentatives(Span<UInt32> vertexChartIds)
{
for (uint i = 0; i < vertexChartIds.Length; ++i)
{
vertexChartIds[(int)i] = FindRepresentative(vertexChartIds, i);
}
}
public static void InitializeRepresentatives(Span<UInt32> vertexChartIds)
{
for (UInt32 i = 0; i < vertexChartIds.Length; ++i)
vertexChartIds[(int)i] = i;
}
public static void Compact(Span<UInt32> vertexChartIds, out uint chartCount)
{
var map = new Dictionary<UInt32, UInt32>();
for (int vertexIdx = 0; vertexIdx < vertexChartIds.Length; ++vertexIdx)
{
var chartId = vertexChartIds[vertexIdx];
UInt32 newChartId;
if (map.TryGetValue(chartId, out UInt32 compactedId))
{
newChartId = compactedId;
}
else
{
newChartId = (UInt32)map.Count;
map.Add(chartId, newChartId);
}
vertexChartIds[vertexIdx] = newChartId;
}
chartCount = (uint)map.Count;
}
}
internal class ParallelChartIdentification : IDisposable
{
private readonly MeshChartIdentificationJob[] _jobs;
private readonly JobHandle[] _jobHandles;
private readonly NativeArray<UInt32>[] _outputVertexChartIndices;
private readonly NativeArray<UInt32>[] _outputVertexChartIndicesIgnoringNormals;
private readonly NativeArray<UInt32>[] _outputChartCounts;
private readonly Dictionary<Mesh, uint> _meshToJobIdx;
public struct MeshResult
{
// Vertex -> Chart index mapping taking normals into account.
// Triangles are considered belonging to different charts if
// only connected by overlapping vertices which have different normals.
// Used for the 'baked UV charts' output, which is used to
// prevent filtering over hard edges during postprocessing.
public NativeArray<UInt32> VertexChartIndices;
public uint ChartCount;
// Vertex -> Chart index mapping NOT taking normals into account.
// Triangles are considered belonging to the SAME chart if
// only connected by overlapping vertices which have different normals.
// Used for the 'baked UV overlap', since bilinear bleeding across hard edges
// within a single UV island is considered acceptable.
public NativeArray<UInt32> VertexChartIndicesIgnoringNormals;
public uint ChartCountIgnoringNormals;
};
private struct MeshChartIdentificationJob : IJob
{
[ReadOnly, DeallocateOnJobCompletion]
public NativeArray<UInt32> InputVertexIndexBuffer;
[ReadOnly, DeallocateOnJobCompletion]
public NativeArray<float2> InputVertexUvBuffer;
[ReadOnly, DeallocateOnJobCompletion]
public NativeArray<float3> InputVertexPositionBuffer;
[ReadOnly, DeallocateOnJobCompletion]
public NativeArray<float3> InputVertexNormalBuffer;
public NativeArray<UInt32> OutputVertexChartIndicesBuffer;
public NativeArray<UInt32> OutputVertexChartIndicesIgnoringNormalsBuffer;
// Always 2 elements. Job system doesn't support scalar outputs.
public NativeArray<UInt32> OutputChartCount;
public void Execute()
{
ChartIdentification.InitializeRepresentatives(OutputVertexChartIndicesBuffer);
ChartIdentification.UnionTriangleEdges(InputVertexIndexBuffer, OutputVertexChartIndicesBuffer);
// Union duplicate verts taking normal into account
ChartIdentification.UnionDuplicateVertices(InputVertexUvBuffer, InputVertexPositionBuffer, InputVertexNormalBuffer, OutputVertexChartIndicesBuffer, respectNormals: true);
ChartIdentification.FindRepresentatives(OutputVertexChartIndicesBuffer);
// Union duplicate verts NOT taking normal into account
OutputVertexChartIndicesBuffer.CopyTo(OutputVertexChartIndicesIgnoringNormalsBuffer);
ChartIdentification.UnionDuplicateVertices(InputVertexUvBuffer, InputVertexPositionBuffer, InputVertexNormalBuffer, OutputVertexChartIndicesIgnoringNormalsBuffer, respectNormals: false);
ChartIdentification.FindRepresentatives(OutputVertexChartIndicesIgnoringNormalsBuffer);
// Compact and output both mappings
ChartIdentification.Compact(OutputVertexChartIndicesBuffer, out uint outputChartCount);
ChartIdentification.Compact(OutputVertexChartIndicesIgnoringNormalsBuffer, out uint outputChartIgnoringNormalsCount);
OutputChartCount[0] = outputChartCount;
OutputChartCount[1] = outputChartIgnoringNormalsCount;
}
}
public ParallelChartIdentification(IList<Mesh> meshes)
{
_outputVertexChartIndices = new NativeArray<UInt32>[meshes.Count];
_outputVertexChartIndicesIgnoringNormals = new NativeArray<UInt32>[meshes.Count];
_outputChartCounts = new NativeArray<UInt32>[meshes.Count];
_jobs = new MeshChartIdentificationJob[meshes.Count];
_jobHandles = new JobHandle[meshes.Count];
_meshToJobIdx = new Dictionary<Mesh, uint>();
for (uint meshIdx = 0; meshIdx < meshes.Count; ++meshIdx)
{
var mesh = meshes[(int)meshIdx];
// Select uv buffer, prefer uv2
var uvBuffer = mesh.uv2;
if (uvBuffer == null || uvBuffer.Length == 0)
uvBuffer = mesh.uv;
var inputVertexIndices = new NativeArray<Int32>(mesh.triangles, Allocator.TempJob).Reinterpret<UInt32>(sizeof(Int32));
var inputVertexUvs = new NativeArray<Vector2>(uvBuffer, Allocator.TempJob).Reinterpret<float2>(sizeof(float) * 2);
var inputVertexPositions = new NativeArray<Vector3>(mesh.vertices, Allocator.TempJob).Reinterpret<float3>(sizeof(float) * 3);
var inputVertexNormals = new NativeArray<Vector3>(mesh.normals, Allocator.TempJob).Reinterpret<float3>(sizeof(float) * 3);
var outputChartIndices = new NativeArray<UInt32>(mesh.vertexCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var outputChartIndicesIgnoringNormals = new NativeArray<UInt32>(mesh.vertexCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
var outputChartCount = new NativeArray<UInt32>(2, Allocator.TempJob);
var job = new MeshChartIdentificationJob
{
InputVertexIndexBuffer = inputVertexIndices,
InputVertexUvBuffer = inputVertexUvs,
InputVertexPositionBuffer = inputVertexPositions,
InputVertexNormalBuffer = inputVertexNormals,
OutputVertexChartIndicesBuffer = outputChartIndices,
OutputVertexChartIndicesIgnoringNormalsBuffer = outputChartIndicesIgnoringNormals,
OutputChartCount = outputChartCount,
};
_outputVertexChartIndices[meshIdx] = outputChartIndices;
_outputVertexChartIndicesIgnoringNormals[meshIdx] = outputChartIndicesIgnoringNormals;
_outputChartCounts[meshIdx] = outputChartCount;
_jobs[meshIdx] = job;
_meshToJobIdx[mesh] = meshIdx;
}
}
public void Start()
{
for (uint meshIdx = 0; meshIdx < _jobs.Length; ++meshIdx)
{
_jobHandles[meshIdx] = _jobs[meshIdx].ScheduleByRef();
}
}
public MeshResult CompleteAndGetResult(Mesh mesh)
{
uint meshIdx = _meshToJobIdx[mesh];
_jobHandles[meshIdx].Complete();
var meshResult = new MeshResult
{
VertexChartIndices = _outputVertexChartIndices[meshIdx],
ChartCount = _outputChartCounts[meshIdx][0],
VertexChartIndicesIgnoringNormals = _outputVertexChartIndicesIgnoringNormals[meshIdx],
ChartCountIgnoringNormals = _outputChartCounts[meshIdx][1],
};
return meshResult;
}
public void Dispose()
{
for (uint meshIdx = 0; meshIdx < _jobs.Length; ++meshIdx)
_jobHandles[meshIdx].Complete();
foreach (var chartIndexList in _outputVertexChartIndices)
chartIndexList.Dispose();
foreach (var chartIndexList in _outputVertexChartIndicesIgnoringNormals)
chartIndexList.Dispose();
foreach (var chartCountList in _outputChartCounts)
chartCountList.Dispose();
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7a907a631dd46324681dd9b152a939c5
@@ -0,0 +1,110 @@
using System;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine.Rendering;
namespace UnityEngine.PathTracing.Lightmapping
{
internal class ChartRasterizer : IDisposable
{
// Buffers required to execute chart rasterization
public struct Buffers
{
public GraphicsBuffer vertex; // Only used in software path
public GraphicsBuffer vertexToOriginalVertex; // Only used in software path
public GraphicsBuffer vertexToChartID;
}
private readonly Material _softwareRasterizationMaterial;
private readonly Material _hardwareRasterizationMaterial;
private static class ShaderProperties
{
public static readonly int VertexBuffer = Shader.PropertyToID("g_VertexBuffer");
public static readonly int VertexToOriginalVertex = Shader.PropertyToID("g_VertexToOriginalVertex");
public static readonly int VertexToChartID = Shader.PropertyToID("g_VertexToChartID");
public static readonly int ScaleAndOffset = Shader.PropertyToID("g_ScaleAndOffset");
public static readonly int ChartIndexOffset = Shader.PropertyToID("g_ChartIndexOffset");
public static readonly int Width = Shader.PropertyToID("g_Width");
public static readonly int Height = Shader.PropertyToID("g_Height");
}
public ChartRasterizer(Shader softwareRasterizationShader, Shader hardwareRasterizationShader)
{
_softwareRasterizationMaterial = new Material(softwareRasterizationShader);
_hardwareRasterizationMaterial = new Material(hardwareRasterizationShader);
}
public void Dispose()
{
CoreUtils.Destroy(_softwareRasterizationMaterial);
CoreUtils.Destroy(_hardwareRasterizationMaterial);
}
#if UNITY_EDITOR
public static void LoadShaders(out Shader softwareRasterizationShader, out Shader hardwareRasterizationShader)
{
softwareRasterizationShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(
"Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/ChartRasterizerSoftware.shader");
hardwareRasterizationShader = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(
"Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/ChartRasterizerHardware.shader");
}
#endif
private static Vector2[] SelectUVBuffer(Mesh from)
{
var uv2 = from.uv2;
if (uv2 != null && uv2.Length > 0)
return uv2;
else
return from.uv;
}
public static void PrepareRasterizeSoftware(CommandBuffer cmd, Mesh from, GraphicsBuffer vertexBuffer, GraphicsBuffer vertexToOriginalVertexBuffer)
{
var originalUVs = from.vertices;
var originalIndices = from.triangles;
var uvs = new Vector2[originalIndices.Length];
var vertexIds = new uint[originalIndices.Length];
for (int i = 0; i < originalIndices.Length; i++)
{
uint originalVertexIdx = (uint)originalIndices[i];
uvs[i] = originalUVs[originalVertexIdx];
vertexIds[i] = originalVertexIdx;
}
cmd.SetBufferData(vertexBuffer, uvs);
cmd.SetBufferData(vertexToOriginalVertexBuffer, vertexIds);
}
public void RasterizeSoftware(CommandBuffer cmd, GraphicsBuffer vertexBuffer, GraphicsBuffer vertexToOriginalVertexBuffer, GraphicsBuffer vertexToChartIdBuffer, uint indexCount, Vector4 scaleAndOffset, uint chartIndexOffset, RenderTexture destination)
{
cmd.SetGlobalBuffer(ShaderProperties.VertexBuffer, vertexBuffer);
cmd.SetGlobalBuffer(ShaderProperties.VertexToOriginalVertex, vertexToOriginalVertexBuffer);
cmd.SetGlobalBuffer(ShaderProperties.VertexToChartID, vertexToChartIdBuffer);
cmd.SetGlobalVector(ShaderProperties.ScaleAndOffset, scaleAndOffset);
cmd.SetGlobalInt(ShaderProperties.ChartIndexOffset, (int)chartIndexOffset);
cmd.SetGlobalInteger(ShaderProperties.Width, destination.width);
cmd.SetGlobalInteger(ShaderProperties.Height, destination.height);
cmd.SetRenderTarget(destination);
cmd.DrawProcedural(Matrix4x4.identity, _softwareRasterizationMaterial, 0, MeshTopology.Triangles, (int)indexCount);
}
public void RasterizeHardware(CommandBuffer cmd, Mesh mesh, GraphicsBuffer vertexToChartIdBuffer, Vector4 scaleAndOffset, uint chartIndexOffset, RenderTexture destination)
{
Debug.Assert(SystemInfo.supportsConservativeRaster, "Conservative rasterization is not supported on the current platform.");
cmd.SetGlobalBuffer(ShaderProperties.VertexToChartID, vertexToChartIdBuffer);
cmd.SetGlobalVector(ShaderProperties.ScaleAndOffset, scaleAndOffset);
cmd.SetGlobalInt(ShaderProperties.ChartIndexOffset, (int)chartIndexOffset);
cmd.SetRenderTarget(destination);
for (int i = 0; i < mesh.subMeshCount; i++)
{
cmd.DrawMesh(mesh, Matrix4x4.identity, _hardwareRasterizationMaterial, i, 0);
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 54a5cb4c515d9304ba7e7c9cab9ed90e
@@ -0,0 +1,194 @@
using System;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.UnifiedRayTracing;
namespace UnityEngine.PathTracing.Lightmapping
{
// Detects pixels where multiple UV charts have overlapping bilinear neighborhoods.
internal class UVOverlapDetection : IDisposable
{
private static class ShaderProperties
{
public static readonly int TextureSize = Shader.PropertyToID("_TextureSize");
public static readonly int PerPixelChart = Shader.PropertyToID("_PerPixelChart");
public static readonly int InstanceIndex = Shader.PropertyToID("_InstanceIndex");
public static readonly int EdgeCount = Shader.PropertyToID("_EdgeCount");
public static readonly int TriangleEdges = Shader.PropertyToID("_TriangleEdges");
public static readonly int ChartIndices = Shader.PropertyToID("_ChartIndices");
public static readonly int OverlapPixels = Shader.PropertyToID("_OverlapPixels");
public static readonly int OverlapInstances = Shader.PropertyToID("_OverlapInstances");
public static readonly int TileX = Shader.PropertyToID("_TileX");
public static readonly int TileY = Shader.PropertyToID("_TileY");
public static readonly int TileSize = Shader.PropertyToID("_TileSize");
}
private int _lightmapResolution;
private ComputeShader _shader;
private NativeArray<float4> _triangleEdges;
private NativeArray<uint> _chartIndices;
private GraphicsBuffer _triangleEdgesBuffer;
private GraphicsBuffer _chartIndicesBuffer;
private GraphicsBuffer _perPixelChart;
private GraphicsBuffer _overlapPixelsBuffer;
private GraphicsBuffer _overlapInstancesBuffer;
private int _overlapKernel;
private uint _overlapKernelSize;
public void Initialize(ComputeShader shader, uint lightmapResolution, uint maxEdgeCount, uint instanceCount)
{
_lightmapResolution = (int)lightmapResolution;
_shader = shader;
_triangleEdges = new NativeArray<float4>((int)maxEdgeCount,Allocator.Persistent);
_chartIndices = new NativeArray<uint>((int)maxEdgeCount, Allocator.Persistent);
_triangleEdgesBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, _triangleEdges.Length, UnsafeUtility.SizeOf<float4>());
_chartIndicesBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, _chartIndices.Length, sizeof(uint));
_perPixelChart = new GraphicsBuffer(GraphicsBuffer.Target.Structured, _lightmapResolution*_lightmapResolution, sizeof(uint));
_overlapPixelsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, _lightmapResolution*_lightmapResolution, sizeof(uint));
_overlapInstancesBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, (int)instanceCount, sizeof(uint));
_overlapKernel = shader.FindKernel("MarkBilinearOverlaps");
shader.GetKernelThreadGroupSizes(_overlapKernel, out _overlapKernelSize, out _, out _);
// Initialize buffers
_overlapPixelsBuffer.SetData(new uint[_lightmapResolution*_lightmapResolution]);
_overlapInstancesBuffer.SetData(new uint[instanceCount]);
var initPerPixelChart = new uint[_lightmapResolution * _lightmapResolution];
Array.Fill(initPerPixelChart, uint.MaxValue);
_perPixelChart.SetData(initPerPixelChart);
}
public void MarkOverlapsInInstance(
CommandBuffer cmd,
Mesh uvMesh,
NativeArray<UInt32> vertexToChartIndex,
float4 occupiedST,
uint instanceIndex,
uint chartIndexOffset)
{
// Get the start and end pos of every edge, and the chart index for each edge.
var indices = uvMesh.triangles;
var vertices = uvMesh.vertices;
for (uint triangleIdx = 0; triangleIdx < indices.Length / 3; triangleIdx++)
{
for (uint edgeOffset = 0; edgeOffset < 3; edgeOffset++)
{
uint baseTriangleIdx = triangleIdx * 3;
int startVertexIdx = indices[baseTriangleIdx + edgeOffset];
int endVertexIdx = indices[baseTriangleIdx + ((edgeOffset + 1) % 3)];
float3 start = vertices[startVertexIdx];
float3 end = vertices[endVertexIdx];
start.xy = (start.xy * occupiedST.xy + occupiedST.zw) * _lightmapResolution;
end.xy = (end.xy * occupiedST.xy + occupiedST.zw) * _lightmapResolution;
_triangleEdges[(int)(baseTriangleIdx + edgeOffset)] = new float4(start.x, start.y, end.x, end.y);
uint chartIdx = chartIndexOffset + vertexToChartIndex[startVertexIdx];
_chartIndices[(int)(baseTriangleIdx + edgeOffset)] = chartIdx;
}
}
cmd.SetBufferData(_triangleEdgesBuffer, _triangleEdges);
cmd.SetBufferData(_chartIndicesBuffer, _chartIndices);
// If the lightmap resolution is over this constant, we split the dispatch into multiple
// smaller dispatches over tiles, to prevent dispatches that are too large. Otherwise in
// the worst case, every lightmap texel can be checked in one dispatch.
const uint tileSize = 1024;
// Mark overlaps
int edgeCount = indices.Length;
cmd.SetComputeIntParam(_shader, ShaderProperties.InstanceIndex, (int)instanceIndex);
cmd.SetComputeIntParam(_shader, ShaderProperties.EdgeCount, edgeCount);
cmd.SetComputeIntParam(_shader, ShaderProperties.TextureSize, _lightmapResolution);
cmd.SetComputeIntParam(_shader, ShaderProperties.TileSize, (int)tileSize);
cmd.SetComputeBufferParam(_shader, _overlapKernel, ShaderProperties.TriangleEdges, _triangleEdgesBuffer);
cmd.SetComputeBufferParam(_shader, _overlapKernel, ShaderProperties.ChartIndices, _chartIndicesBuffer);
cmd.SetComputeBufferParam(_shader, _overlapKernel, ShaderProperties.PerPixelChart, _perPixelChart);
cmd.SetComputeBufferParam(_shader, _overlapKernel, ShaderProperties.OverlapPixels, _overlapPixelsBuffer);
cmd.SetComputeBufferParam(_shader, _overlapKernel, ShaderProperties.OverlapInstances, _overlapInstancesBuffer);
int dispatchSize = GraphicsHelpers.DivUp(edgeCount, _overlapKernelSize);
uint tileCountOnEachDim = GraphicsHelpers.DivUp((uint)_lightmapResolution, tileSize);
for (uint tileY = 0; tileY < tileCountOnEachDim; tileY++)
{
for (uint tileX = 0; tileX < tileCountOnEachDim; tileX++)
{
cmd.SetComputeIntParam(_shader, ShaderProperties.TileX, (int)tileX);
cmd.SetComputeIntParam(_shader, ShaderProperties.TileY, (int)tileY);
cmd.DispatchCompute(_shader, _overlapKernel, dispatchSize, 1, 1);
}
}
}
public void CompactAndReadbackOverlaps(
CommandBuffer cmd,
out uint[] uniqueOverlapPixelIndices,
out ulong[] uniqueOverlapInstanceIndices)
{
// Make sure all kernels are finished
GraphicsHelpers.Flush(cmd);
// Readback overlap buffers
uint[] overlapPixels = new uint[_overlapPixelsBuffer.count];
_overlapPixelsBuffer.GetData(overlapPixels);
uint[] overlapInstances = new uint[_overlapInstancesBuffer.count];
_overlapInstancesBuffer.GetData(overlapInstances);
// Deduplicate overlaps
List<uint> uniqueOverlapPixelIndicesSet = new List<uint>();
List<ulong> uniqueOverlapInstanceIndicesSet = new List<ulong>();
for (uint pixelIndex = 0; pixelIndex < _overlapPixelsBuffer.count; pixelIndex++)
{
if (overlapPixels[pixelIndex] != 0)
uniqueOverlapPixelIndicesSet.Add(pixelIndex);
}
for (uint instanceIndex = 0; instanceIndex < _overlapInstancesBuffer.count; instanceIndex++)
{
if (overlapInstances[instanceIndex] != 0)
uniqueOverlapInstanceIndicesSet.Add(instanceIndex);
}
uniqueOverlapPixelIndices = new uint[uniqueOverlapPixelIndicesSet.Count];
uniqueOverlapPixelIndicesSet.CopyTo(uniqueOverlapPixelIndices);
uniqueOverlapInstanceIndices = new ulong[uniqueOverlapInstanceIndicesSet.Count];
uniqueOverlapInstanceIndicesSet.CopyTo(uniqueOverlapInstanceIndices);
// Sort to keep the order deterministic
Array.Sort(uniqueOverlapPixelIndices);
Array.Sort(uniqueOverlapInstanceIndices);
}
public void Dispose()
{
if (_triangleEdges.IsCreated)
_triangleEdges.Dispose();
if (_chartIndices.IsCreated)
_chartIndices.Dispose();
if (_triangleEdgesBuffer != null && _triangleEdgesBuffer.IsValid())
_triangleEdgesBuffer.Dispose();
if (_chartIndicesBuffer != null && _chartIndicesBuffer.IsValid())
_chartIndicesBuffer.Dispose();
if (_perPixelChart != null && _perPixelChart.IsValid())
_perPixelChart.Dispose();
if (_overlapPixelsBuffer != null && _overlapPixelsBuffer.IsValid())
_overlapPixelsBuffer.Dispose();
if (_overlapInstancesBuffer != null && _overlapInstancesBuffer.IsValid())
_overlapInstancesBuffer.Dispose();
}
#if UNITY_EDITOR
public static ComputeShader LoadShader()
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(
"Packages/com.unity.render-pipelines.core/Runtime/PathTracing/Shaders/Lightmapping/BilinearOverlaps.compute");
}
#endif
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e4ea9631f1f5a904d97ac50debf8006b