sort triangles sup opengl

This commit is contained in:
StarBeats 2026-02-05 20:09:22 +08:00
parent 7084bacb84
commit 965117b271

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
@ -27,6 +28,8 @@ public class SortTrianglesOIT : MonoBehaviour
private int indexStart;
[SerializeField, HideInInspector]
private uint meshIndicesCnt;
[SerializeField, HideInInspector]
private List<SubMeshDescriptor> subMeshDescriptors = new();
private static readonly Vector3[] viewDirections =
{
@ -96,13 +99,38 @@ public class SortTrianglesOIT : MonoBehaviour
var indices = sortedIndes[index].Indices;
//mesh.SetIndexBufferParams((int)meshIndicesCnt, mesh.indexFormat);
//mesh.SetIndexBufferData(indices, 0, indexStart, indices.Length,
//mesh.SetIndexBufferParams((int)meshIndicesCnt, IndexFormat.UInt32);
//var submesh0Indices = mesh.GetIndices(0);
//var allIndices = new int[meshIndicesCnt];
//Buffer.BlockCopy(submesh0Indices, 0, allIndices, 0, submesh0Indices.Length);
//Buffer.BlockCopy(indices, 0, allIndices, submesh0Indices.Length, indices.Length);
//mesh.SetIndexBufferData(allIndices, 0, 0, allIndices.Length,
// MeshUpdateFlags.DontValidateIndices |
// MeshUpdateFlags.DontResetBoneBounds |
// MeshUpdateFlags.DontNotifyMeshUsers |
// MeshUpdateFlags.DontRecalculateBounds
// );
////mesh.SetIndexBufferData(indices, 0, indexStart, indices.Length,
//// MeshUpdateFlags.DontValidateIndices |
//// MeshUpdateFlags.DontResetBoneBounds |
//// MeshUpdateFlags.DontNotifyMeshUsers |
//// MeshUpdateFlags.DontRecalculateBounds
//// );
//mesh.subMeshCount = subMeshDescriptors.Count;
//for (int i = 0; i < subMeshDescriptors.Count; i++)
//{
// mesh.SetSubMesh(i, subMeshDescriptors[i],
// MeshUpdateFlags.DontValidateIndices |
// MeshUpdateFlags.DontResetBoneBounds |
// MeshUpdateFlags.DontNotifyMeshUsers |
// MeshUpdateFlags.DontRecalculateBounds
// );
// mesh.bounds.Encapsulate(subMeshDescriptors[i].bounds);
//}
mesh.SetIndices(indices, MeshTopology.Triangles, SubMeshIndex, false);
lastIndex = index;
}
@ -135,6 +163,11 @@ public class SortTrianglesOIT : MonoBehaviour
public int CompareTo(PrimitiveDepth other)
{
var i = depth - other.depth;
if(!SystemInfo.usesReversedZBuffer)
{
i *= -1;
}
if (i > 0)
{
return 1;
@ -202,8 +235,10 @@ public class SortTrianglesOIT : MonoBehaviour
Bounds bounds = GetComponent<Renderer>().bounds;
float radius = bounds.extents.magnitude;
subMeshDescriptors.Clear();
for (int i = 0; i < mesh.subMeshCount; i++)
{
subMeshDescriptors.Add(mesh.GetSubMesh(i));
meshIndicesCnt += mesh.GetIndexCount(i);
}
if (SubMeshIndex >= mesh.subMeshCount)