DOTS支持的shader
生活随笔
收集整理的這篇文章主要介紹了
DOTS支持的shader
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近項目需要用到DOTS的技術,發現除了程序部分需要做代碼調整外,Shader的編寫也需要進行一些調整,不然運行的時候會出些各種奇怪的現象,比如不顯示模型,模型位置錯亂等等。
由于也在慢慢摸索,可能有部分寫的不對的地方,請各位大佬指教。。。
支持DOTS的Shader分為帶骨骼的SkinnedMeshedRender和普通的MeshedRender,普通的MeshedRender實現的方式和普通的GPUInstancing類似,注意是必須增加Instance。
增加變體:
#pragma multi_compile _ DOTS_INSTANCING_ON #pragma target 4.5?頂點著色器輸入結構體增加:
#if UNITY_ANY_INSTANCING_ENABLED uint instanceID : INSTANCEID_SEMANTIC; #endif頂點著色器輸出結構體增加:
#if UNITY_ANY_INSTANCING_ENABLED uint instanceID : CUSTOM_INSTANCE_ID; #endif頂點著色器:
#if UNITY_ANY_INSTANCING_ENABLED o.instanceID = v.instanceID; #endif對于蒙皮對象的Shader,需要另外處理:
//Properties加入相關[HideInInspector]_ComputeMeshIndex("Compute Mesh Buffer Index Offset", Float) = 0//加入變體//DOTS#pragma multi_compile _ DOTS_INSTANCING_ON#pragma target 4.5//加入方法和結構//Dots#if defined(UNITY_DOTS_INSTANCING_ENABLED)// DOTS instancing definitionsUNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)UNITY_DOTS_INSTANCED_PROP(float, _ComputeMeshIndex)UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)// DOTS instancing usage macros// This_macro_cannot_be_called_without_UNITY_DOTS_INSTANCING_ENABLED#define _ComputeMeshIndex UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float, Metadata__ComputeMeshIndex)#endif// Object and Global properties// Graph Functionsstruct DeformedVertexData{float3 Position;float3 Normal;float3 Tangent;};uniform StructuredBuffer<DeformedVertexData> _DeformedMeshData : register(t1);void Unity_ComputeDeformedVertex_float(uint vertexID, out float3 positionOut, out float3 normalOut, out float3 tangentOut){const DeformedVertexData vertexData = _DeformedMeshData[asuint(_ComputeMeshIndex) + vertexID];positionOut = vertexData.Position;normalOut = vertexData.Normal;tangentOut = vertexData.Tangent;}//Attributes中加入//DOTSuint vertexID : SV_VertexID;/////Varyings中加入//dots#if defined(UNITY_DOTS_INSTANCING_ENABLED)float3 SkinnedPosition = 0;float3 SkinnedNormal = 0;float3 SkinnedTangent = 0;Unity_ComputeDeformedVertex_float(v.vertexID, SkinnedPosition, SkinnedNormal, SkinnedTangent);#elsefloat3 SkinnedPosition = v.positionOS.xyz;float3 SkinnedNormal = v.normalOS;float3 SkinnedTangent = v.tangentOS.xyz;#endifv.positionOS = float4(SkinnedPosition,v.positionOS.z);v.normalOS = SkinnedNormal;v.tangentOS = float4(SkinnedTangent , v.tangentOS.z);///總結
以上是生活随笔為你收集整理的DOTS支持的shader的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 游戏开发unity性能优化:DOTS导航
- 下一篇: 从http协议看百度360大战