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;
|
public int[] Indices;
|
||||||
}
|
}
|
||||||
|
[Range(0,4), InspectorName("͸Ã÷ÎïÌå SubMesh Id")]
|
||||||
public int SubMeshIndex = 0;
|
public int SubMeshIndex = 0;
|
||||||
// XXX: 根据重叠三角形,计算实际需要的数据,减少序列化大小
|
// XXX: 根据重叠三角形,计算实际需要的数据,减少序列化大小
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -30,6 +31,7 @@ public class SortTrianglesOIT : MonoBehaviour
|
|||||||
private uint meshIndicesCnt;
|
private uint meshIndicesCnt;
|
||||||
[SerializeField, HideInInspector]
|
[SerializeField, HideInInspector]
|
||||||
private List<SubMeshDescriptor> subMeshDescriptors = new();
|
private List<SubMeshDescriptor> subMeshDescriptors = new();
|
||||||
|
private const float maxCameraDistance = 200;
|
||||||
|
|
||||||
private static readonly Vector3[] viewDirections =
|
private static readonly Vector3[] viewDirections =
|
||||||
{
|
{
|
||||||
@ -78,7 +80,13 @@ public class SortTrianglesOIT : MonoBehaviour
|
|||||||
}
|
}
|
||||||
#endif
|
#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++)
|
for (int i = 0; i < viewDirections.Length; i++)
|
||||||
{
|
{
|
||||||
if (Vector3.Dot(viewDir, viewDirections[i]) > directionalMinCos)
|
if (Vector3.Dot(viewDir, viewDirections[i]) > directionalMinCos)
|
||||||
@ -156,12 +164,18 @@ public class SortTrianglesOIT : MonoBehaviour
|
|||||||
struct PrimitiveDepth : IComparable<PrimitiveDepth>
|
struct PrimitiveDepth : IComparable<PrimitiveDepth>
|
||||||
{
|
{
|
||||||
public float depth;
|
public float depth;
|
||||||
|
public float isfront;
|
||||||
public uint a;
|
public uint a;
|
||||||
public uint b;
|
public uint b;
|
||||||
public uint c;
|
public uint c;
|
||||||
|
|
||||||
public int CompareTo(PrimitiveDepth other)
|
public int CompareTo(PrimitiveDepth other)
|
||||||
{
|
{
|
||||||
|
//if (isfront < 0.5f )
|
||||||
|
//{
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
var i = depth - other.depth;
|
var i = depth - other.depth;
|
||||||
if(!SystemInfo.usesReversedZBuffer)
|
if(!SystemInfo.usesReversedZBuffer)
|
||||||
{
|
{
|
||||||
@ -262,5 +276,19 @@ public class SortTrianglesOIT : MonoBehaviour
|
|||||||
GameObject.DestroyImmediate(renderCamera.gameObject);
|
GameObject.DestroyImmediate(renderCamera.gameObject);
|
||||||
isSorted = true;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,12 +17,14 @@ Shader "OIT/TrianglesIdDepth"
|
|||||||
struct appdata
|
struct appdata
|
||||||
{
|
{
|
||||||
float4 vertex : POSITION;
|
float4 vertex : POSITION;
|
||||||
|
float3 normal : NORMAL;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VSOut
|
struct VSOut
|
||||||
{
|
{
|
||||||
float4 position : POSITION;
|
float4 position : POSITION;
|
||||||
uint index : TEXCOORD;
|
nointerpolation uint index : TEXCOORD0;
|
||||||
|
nointerpolation float vface : TEXCOORD1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GSOut
|
struct GSOut
|
||||||
@ -33,6 +35,10 @@ Shader "OIT/TrianglesIdDepth"
|
|||||||
VSOut vert(appdata v, uint index : SV_VertexID)
|
VSOut vert(appdata v, uint index : SV_VertexID)
|
||||||
{
|
{
|
||||||
VSOut o;
|
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.position = UnityObjectToClipPos(v.vertex);
|
||||||
o.index = index;
|
o.index = index;
|
||||||
return o;
|
return o;
|
||||||
@ -41,6 +47,7 @@ Shader "OIT/TrianglesIdDepth"
|
|||||||
struct PrimitiveDepth
|
struct PrimitiveDepth
|
||||||
{
|
{
|
||||||
float depth;
|
float depth;
|
||||||
|
float isfront;
|
||||||
uint a;
|
uint a;
|
||||||
uint b;
|
uint b;
|
||||||
uint c;
|
uint c;
|
||||||
@ -52,30 +59,16 @@ Shader "OIT/TrianglesIdDepth"
|
|||||||
void geom(triangle VSOut IN[3], uint primID : SV_PrimitiveID, inout TriangleStream<GSOut> triStream)
|
void geom(triangle VSOut IN[3], uint primID : SV_PrimitiveID, inout TriangleStream<GSOut> triStream)
|
||||||
{
|
{
|
||||||
PrimitiveDepth o;
|
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.a = IN[0].index;
|
||||||
o.b = IN[1].index;
|
o.b = IN[1].index;
|
||||||
o.c = IN[2].index;
|
o.c = IN[2].index;
|
||||||
// if (o.a > o.b)
|
|
||||||
// {
|
o.isfront = IN[0].vface;
|
||||||
// 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;
|
|
||||||
// }
|
|
||||||
primitiveBuffer[primID] = o;
|
primitiveBuffer[primID] = o;
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i)
|
for (int i = 0; i < 3; ++i)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user