sync
This commit is contained in:
parent
db6854d981
commit
501bfad182
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ public class SortTrianglesOIT : MonoBehaviour
|
||||
{
|
||||
public int[] Indices;
|
||||
}
|
||||
[Range(0,4), InspectorName("͸Ã÷ÎïÌå SubMesh Id")]
|
||||
public int SubMeshIndex = 0;
|
||||
// XXX: 根据重叠三角形,计算实际需要的数据,减少序列化大小
|
||||
[SerializeField]
|
||||
@ -30,6 +31,7 @@ public class SortTrianglesOIT : MonoBehaviour
|
||||
private uint meshIndicesCnt;
|
||||
[SerializeField, HideInInspector]
|
||||
private List<SubMeshDescriptor> subMeshDescriptors = new();
|
||||
private const float maxCameraDistance = 200;
|
||||
|
||||
private static readonly Vector3[] viewDirections =
|
||||
{
|
||||
@ -78,7 +80,13 @@ public class SortTrianglesOIT : MonoBehaviour
|
||||
}
|
||||
#endif
|
||||
|
||||
var viewDir = (pos - transform.position).normalized;
|
||||
Vector3 viewVec = pos - transform.position;
|
||||
if (viewVec.sqrMagnitude > maxCameraDistance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var viewDir = viewVec.normalized;
|
||||
for (int i = 0; i < viewDirections.Length; i++)
|
||||
{
|
||||
if (Vector3.Dot(viewDir, viewDirections[i]) > directionalMinCos)
|
||||
@ -156,12 +164,18 @@ public class SortTrianglesOIT : MonoBehaviour
|
||||
struct PrimitiveDepth : IComparable<PrimitiveDepth>
|
||||
{
|
||||
public float depth;
|
||||
public float isfront;
|
||||
public uint a;
|
||||
public uint b;
|
||||
public uint c;
|
||||
|
||||
public int CompareTo(PrimitiveDepth other)
|
||||
{
|
||||
//if (isfront < 0.5f )
|
||||
//{
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
var i = depth - other.depth;
|
||||
if(!SystemInfo.usesReversedZBuffer)
|
||||
{
|
||||
@ -262,5 +276,19 @@ public class SortTrianglesOIT : MonoBehaviour
|
||||
GameObject.DestroyImmediate(renderCamera.gameObject);
|
||||
isSorted = true;
|
||||
}
|
||||
|
||||
|
||||
public void Bake()
|
||||
{
|
||||
SortTriangles();
|
||||
}
|
||||
|
||||
public void ClearBake()
|
||||
{
|
||||
isSorted = false;
|
||||
var path = UnityEditor.AssetDatabase.GetAssetPath(GetComponent<MeshFilter>().sharedMesh);
|
||||
UnityEditor.AssetImporter assetImporter = UnityEditor.AssetImporter.GetAtPath(path);
|
||||
assetImporter.SaveAndReimport();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -17,12 +17,14 @@ Shader "OIT/TrianglesIdDepth"
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct VSOut
|
||||
{
|
||||
float4 position : POSITION;
|
||||
uint index : TEXCOORD;
|
||||
nointerpolation uint index : TEXCOORD0;
|
||||
nointerpolation float vface : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct GSOut
|
||||
@ -33,6 +35,10 @@ Shader "OIT/TrianglesIdDepth"
|
||||
VSOut vert(appdata v, uint index : SV_VertexID)
|
||||
{
|
||||
VSOut o;
|
||||
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
float3 viewDir = normalize(_WorldSpaceCameraPos - worldPos);
|
||||
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
o.vface = (dot(worldNormal, viewDir) > 0 )? 1.0 : -1.0;
|
||||
o.position = UnityObjectToClipPos(v.vertex);
|
||||
o.index = index;
|
||||
return o;
|
||||
@ -41,6 +47,7 @@ Shader "OIT/TrianglesIdDepth"
|
||||
struct PrimitiveDepth
|
||||
{
|
||||
float depth;
|
||||
float isfront;
|
||||
uint a;
|
||||
uint b;
|
||||
uint c;
|
||||
@ -52,30 +59,16 @@ Shader "OIT/TrianglesIdDepth"
|
||||
void geom(triangle VSOut IN[3], uint primID : SV_PrimitiveID, inout TriangleStream<GSOut> triStream)
|
||||
{
|
||||
PrimitiveDepth o;
|
||||
o.depth = (IN[0].position.z + IN[1].position.z + IN[2].position.z) / 3;
|
||||
float3 A = IN[0].position.xyz;
|
||||
float3 B = IN[1].position.xyz;
|
||||
float3 C = IN[2].position.xyz;
|
||||
o.depth = (A.z + B.z + C.z) / 3;
|
||||
o.a = IN[0].index;
|
||||
o.b = IN[1].index;
|
||||
o.c = IN[2].index;
|
||||
// if (o.a > o.b)
|
||||
// {
|
||||
// uint tmp = o.b;
|
||||
// o.b = o.a;
|
||||
// o.a = tmp;
|
||||
// }
|
||||
//
|
||||
// if (o.a > o.c)
|
||||
// {
|
||||
// uint tmp = o.c;
|
||||
// o.c = o.a;
|
||||
// o.a = tmp;
|
||||
// }
|
||||
//
|
||||
// if (o.b > o.c)
|
||||
// {
|
||||
// uint tmp = o.b;
|
||||
// o.b = o.c;
|
||||
// o.c = tmp;
|
||||
// }
|
||||
|
||||
o.isfront = IN[0].vface;
|
||||
|
||||
primitiveBuffer[primID] = o;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user