Toon.shader 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. Shader "Toon"
  4. {
  5. Properties
  6. {
  7. [HeaderHelpLuxURP_URL(snoamqpqhtdl)]
  8. [Header(Surface Options)]
  9. [Space(8)]
  10. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  11. _ReceiveShadows("Receive Shadows", Float) = 1.0
  12. _SkinShadowBias(" Shadow Caster Bias", Range(.1, 1.0)) = 1.0
  13. _SkinShadowSamplingBias(" Shadow Sampling Bias", Range(0, 0.05)) = 0
  14. [Header(Surface Inputs)]
  15. [Space(8)]
  16. [MainTexture]
  17. _BaseMap("Albedo (RGB) Smoothness (A)", 2D) = "white" {}
  18. _ClothMask1("Cloth Mask1", 2D) = "white" {}
  19. _ClothMask2("Cloth Mask2", 2D) = "white" {}
  20. _ClothMask3("Cloth Mask3", 2D) = "white" {}
  21. [MainColor]
  22. _BaseColor("Color", Color) = (1,1,1,1)
  23. [Space(5)]
  24. _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
  25. // For some reason android did not like _SpecColor!?
  26. _SpecularColor("Specular", Color) = (0.2, 0.2, 0.2)
  27. [Space(5)]
  28. [Toggle(_NORMALMAP)]
  29. _ApplyNormal("Enable Normal Map", Float) = 0.0
  30. [NoScaleOffset]
  31. _BumpMap(" Normal Map", 2D) = "bump" {}
  32. _BumpScale(" Normal Scale", Float) = 1.0
  33. [Toggle(_NORMALMAPDIFFUSE)]
  34. _ApplyNormalDiffuse(" Enable Diffuse Normal Sample", Float) = 0.0
  35. _Bias(" Bias", Range(0.0, 8.0)) = 3.0
  36. [Toggle]_VertexNormal(" Use Vertex Normal for Diffuse", Float) = 1
  37. _SSSMap("SSS Map", 2D) = "black" {}
  38. _ILMMap("ILM Map",2D) = "gray" {}
  39. _DetailMap("Detail Map",2D) = "white" {}
  40. _ToonThesHold("ToonThesHold",Range(0,1)) = 0.5
  41. _ToonHardness("ToonHardness",Float) = 20.0
  42. _SpecColor("Spec Color",Color) = (1,1,1,1)
  43. _SpecSize("Spec Size",Range(0,1)) = 0.1
  44. _RimLightDir("RimLight Dir",Vector) = (1,0,-1,0)
  45. _RimLightColor("RimLight Color",Color) = (1,1,1,1)
  46. _OutlineWidth("Outline Width",Float) = 7.0
  47. _OutlineZbias("Outline Zbias",Float) = -10
  48. _OutlineColor("Outline Color",Color) = (1,1,1,1)
  49. [Header(Mask)]
  50. [Space(8)]
  51. _MakeUpMask1_RGB("MakeUpMask1_RGB (R: 眼影 G: 腮红 B: 口红 A: 眼线)", 2D) = "black" {}
  52. _MakeUpMask2_RGB("MakeUpMask2_RGB (R: 纹身区域)", 2D) = "black" {}
  53. _Mask1_Rchannel_TextureAmountA("Mask1_Rchannel_Texture-Amount(A)", 2D) = "black" {}
  54. _Mask1_Gchannel_TextureAmountA("Mask1_Gchannel_Texture-Amount(A)", 2D) = "black" {}
  55. _Mask1_Bchannel_TextureAmountA("Mask1_Bchannel_Texture-Amount(A)", 2D) = "black" {}
  56. _Mask2_Rchannel_TextureAmountA("Mask2_Rchannel_Texture-Amount(A)", 2D) = "black" {}
  57. _Mask2_Gchannel_TextureAmountA("Mask2_Gchannel_Texture-Amount(A)", 2D) = "black" {}
  58. _Mask2_Bchannel_TextureAmountA("Mask2_Bchannel_Texture-Amount(A)", 2D) = "black" {}
  59. _Mask1_Rchannel_ColorAmountA("Mask1_Rchannel_Color-Amount(A)", Color) = (0.7735849, 0.2006942, 0.3233189, 0.7843137)
  60. _Mask1_Gchannel_ColorAmountA("Mask1_Gchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.4917381, 0.7843137)
  61. _Mask1_Bchannel_ColorAmountA("Mask1_Bchannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137)
  62. _Mask1_Achannel_ColorAmountA("Mask1_Achannel_Color-Amount(A)", Color) = (0.2, 0.406334, 0.772549, 0.7843137)
  63. _Mask2_Rchannel_ColorAmountA("Mask2_Rchannel_Color-Amount(A)", Color) = (0.2, 0.772549, 0.7071339, 0.7843137)
  64. _Mask2_Gchannel_ColorAmountA("Mask2_Gchannel_Color-Amount(A)", Color) = (0.772549, 0.2, 0.6776864, 0.7843137)
  65. _Mask2_Bchannel_ColorAmountA("Mask2_Bchannel_Color-Amount(A)", Color) = (0.772549, 0.7037676, 0.2, 0.7843137)
  66. // Needed by the inspector
  67. [HideInInspector] _Culling("Culling", Float) = 0.0
  68. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  69. [HideInInspector] _MainTex("Albedo", 2D) = "white" {}
  70. [HideInInspector] _Color("Color", Color) = (1,1,1,1)
  71. [HideInInspector] _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.0
  72. // URP 10.1. needs this for the depthnormal pass
  73. [HideInInspector] _Cutoff(" Threshold", Range(0.0, 1.0)) = 0.5
  74. [HideInInspector] _Surface("__surface", Float) = 0.0
  75. }
  76. SubShader
  77. {
  78. Tags
  79. {
  80. "RenderPipeline" = "UniversalPipeline"
  81. "RenderType" = "Opaque"
  82. "Queue" = "Geometry"
  83. }
  84. LOD 100
  85. Pass
  86. {
  87. Tags { "LightMode" = "UniversalForward" }
  88. HLSLPROGRAM
  89. #pragma vertex vert
  90. #pragma fragment frag
  91. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  92. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  93. #pragma multi_compile _ _ADDITIONAL_LIGHTS
  94. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  95. //#pragma multi_compile_fwdbase
  96. //#include "UnityCG.cginc"
  97. //#include "AutoLight.cginc"
  98. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  99. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  100. #include "Includes/Lux URP Skin Inputs Custom Toon.hlsl"
  101. struct Attritubes
  102. {
  103. float4 positionOS : POSITION;
  104. float2 texcoord0 : TEXCOORD0;
  105. float2 texcoord1 : TEXCOORD1;
  106. float3 normalOS : NORMAL;
  107. float4 color : COLOR;
  108. };
  109. struct Varyings
  110. {
  111. float4 positionCS : SV_POSITION;
  112. float4 uv : TEXCOORD0;
  113. float3 positionWS : TEXCOORD1;
  114. float3 normalWS : TEXCOORD2;
  115. float4 vertexColor : TEXCOORD3;
  116. float4 shadowCoord : TEXCOORD4;
  117. };
  118. //TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap);
  119. TEXTURE2D(_SSSMap); SAMPLER(sampler_SSSMap);
  120. TEXTURE2D(_ILMMap); SAMPLER(sampler_ILMMap);
  121. TEXTURE2D(_DetailMap); SAMPLER(sampler_DetailMap);
  122. /*CBUFFER_START(UnityPerMaterial)
  123. float _ToonThesHold;
  124. float _ToonHardness;
  125. float4 _SpecColor;
  126. float _SpecSize;
  127. float4 _RimLightDir;
  128. float4 _RimLightColor;
  129. CBUFFER_END*/
  130. Varyings vert (Attritubes input)
  131. {
  132. Varyings output = (Varyings)0;
  133. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  134. output.positionCS = vertexInput.positionCS;
  135. output.positionWS = vertexInput.positionWS;
  136. //output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  137. //output.positionWS = TransformObjectToWorld(input.positionOS.xyz);
  138. output.normalWS = TransformObjectToWorldNormal(input.normalOS);
  139. output.uv = float4(input.texcoord0,input.texcoord1);
  140. output.vertexColor = input.color;
  141. output.shadowCoord = GetShadowCoord(vertexInput);
  142. return output;
  143. }
  144. half4 GetColor(float2 uv) {
  145. //half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)) * _BaseColor;
  146. half4 albedoAlpha = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv * _BaseMap_ST.xy + _BaseMap_ST.zw) * _BaseColor;
  147. //--------------------------------------------------------
  148. float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw;
  149. float4 tex2DNode143 = SAMPLE_TEXTURE2D(_MakeUpMask1_RGB, sampler_MakeUpMask1_RGB, uv_MakeUpMask1_RGB);
  150. float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw;
  151. float4 tex2D_mask1_R = SAMPLE_TEXTURE2D(_Mask1_Rchannel_TextureAmountA, sampler_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA);
  152. float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw;
  153. float4 tex2D_mask1_G = SAMPLE_TEXTURE2D(_Mask1_Gchannel_TextureAmountA, sampler_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA);
  154. float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw;
  155. float4 tex2D_mask1_B = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA);
  156. float2 uv_Mask1_Achannel_TextureAmountA = uv.xy * _Mask1_Achannel_TextureAmountA_ST.xy + _Mask1_Achannel_TextureAmountA_ST.zw;
  157. float4 tex2D_mask1_A = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA);
  158. float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw;
  159. float4 tex2D_mask2_R = SAMPLE_TEXTURE2D(_Mask2_Rchannel_TextureAmountA, sampler_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA);
  160. float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw;
  161. float4 tex2D_mask2_G = SAMPLE_TEXTURE2D(_Mask2_Gchannel_TextureAmountA, sampler_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA);
  162. float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw;
  163. float4 tex2D_mask2_B = SAMPLE_TEXTURE2D(_Mask2_Bchannel_TextureAmountA, sampler_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA);
  164. float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0);
  165. float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA;
  166. float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295);
  167. float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0);
  168. float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA;
  169. float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296);
  170. float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0);
  171. float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA;
  172. float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297);
  173. float clampResult2971 = clamp((tex2DNode143.a * tex2D_mask1_A.a * _Mask1_Achannel_ColorAmountA.a), 0.0, 1.0);
  174. float4 _Mask1_A_Color = tex2D_mask1_A * _Mask1_Achannel_ColorAmountA;
  175. float4 lerpResult1611 = lerp(lerpResult161, _Mask1_A_Color, clampResult2971);
  176. //mask2
  177. float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw;
  178. float4 tex2DNode144 = SAMPLE_TEXTURE2D(_MakeUpMask2_RGB, sampler_MakeUpMask2_RGB, uv_MakeUpMask2_RGB);
  179. float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0);
  180. float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA;
  181. float4 lerpResult162 = lerp(lerpResult1611, _Mask2_Rchannel_ColorAmountA, clampResult298);
  182. float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0);
  183. float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA;
  184. float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299);
  185. float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0);
  186. float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA;
  187. float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300);
  188. albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b);
  189. return albedoAlpha;
  190. }
  191. half4 frag (Varyings input) : SV_Target
  192. {
  193. // clip cloth mask
  194. half v_ClothMask1 = _ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r;
  195. clip(v_ClothMask1 - 0.5);
  196. half v_ClothMask2 = _ClothMask2.Sample(sampler_ClothMask2, input.uv.xy).r;
  197. clip(v_ClothMask2 - 0.5);
  198. half v_ClothMask3 = _ClothMask3.Sample(sampler_ClothMask3, input.uv.xy).r;
  199. clip(v_ClothMask3 - 0.5);
  200. half2 uv1 = input.uv.xy;
  201. half2 uv2 = input.uv.zw;
  202. //向量
  203. float3 normalDir = normalize(input.normalWS);
  204. //float3 lightDir = normalize(_MainLightPosition.xyz);
  205. float3 viewDir = normalize(_WorldSpaceCameraPos - input.positionWS);
  206. //Base贴图
  207. //half4 base_map = SAMPLE_TEXTURE2D(_BaseMap,sampler_BaseMap,uv1);
  208. half4 base_map = GetColor(uv1);
  209. half3 base_color = base_map.rgb; // 亮部的颜色
  210. half base_mask = base_map.a; //用来区分皮肤和非皮肤区域
  211. //SSS贴图
  212. half4 sss_map = SAMPLE_TEXTURE2D(_SSSMap,sampler_SSSMap, uv1);
  213. //half3 sss_color = sss_map.rgb * _BaseColor; //暗部的颜色
  214. //half sss_alpha = sss_map.a; //边缘光的强度控制
  215. half3 sss_color = base_color; //暗部的颜色
  216. half sss_alpha = base_map.a; //边缘光的强度控制
  217. //ILM贴图
  218. half4 ilm_map = SAMPLE_TEXTURE2D(_ILMMap,sampler_ILMMap, uv1);
  219. float spec_intensity = ilm_map.r; //控制高光强度
  220. float diffuse_control = ilm_map.g * 2.0 - 1.0; //控制光照的偏移
  221. float spec_size = ilm_map.b; //控制高光形状大小
  222. float inner_line = ilm_map.a; //内描线
  223. //顶点色
  224. float ao = input.vertexColor.r;
  225. Light mainLight = GetMainLight(input.shadowCoord,input.positionWS,float4(1.0,1.0,1.0,1.0));
  226. float3 lightDir = mainLight.direction;
  227. float shadow = mainLight.shadowAttenuation;
  228. //float shadow = MainLightRealtimeShadow(input.shadowCoord);
  229. float atten = lerp(1 , shadow, input.vertexColor.g);
  230. //漫反射
  231. half NdotL = dot(normalDir, lightDir);
  232. half half_lambert = (NdotL + 1.0) * 0.5;
  233. half labmbert_term = half_lambert * ao * atten + diffuse_control;
  234. half toon_diffuse = saturate((labmbert_term - _ToonThesHold) * _ToonHardness);
  235. //多光源
  236. #ifdef _ADDITIONAL_LIGHTS
  237. uint pixelLightCount = GetAdditionalLightsCount();
  238. for(uint lightIndex = 0; lightIndex < pixelLightCount; ++lightIndex)
  239. {
  240. Light light = GetAdditionalLight(lightIndex,input.positionWS,float4(1.0,1.0,1.0,1.0));
  241. half NdotL_add = dot(normalDir, light.direction);
  242. half half_lambert_add = (NdotL_add + 1.0) * 0.5;
  243. float atten_add = lerp(1 , light.shadowAttenuation * light.distanceAttenuation , input.vertexColor.g);
  244. half labmbert_term_add = half_lambert_add * ao * atten_add + diffuse_control;
  245. toon_diffuse += saturate((labmbert_term_add * light.color - _ToonThesHold) * _ToonHardness);
  246. }
  247. #endif
  248. half3 final_diffuse = lerp(sss_color, base_color,toon_diffuse);
  249. //高光
  250. float NdotV = (dot(normalDir, viewDir) + 1.0) * 0.5;
  251. float spec_term = NdotV * ao + diffuse_control;
  252. spec_term = half_lambert * 0.9 + spec_term * 0.1;
  253. half toon_spec = saturate((spec_term - (1.0 - spec_size * _SpecSize)) * 500);
  254. half3 spec_color = (_SpecColor.rgb + base_color) * 0.5;
  255. half3 final_spec = toon_spec * spec_color * spec_intensity;
  256. //描线
  257. half3 inner_line_color = lerp(base_color * 0.2,float3(1.0,1.0,1.0),inner_line);
  258. half3 detail_color = SAMPLE_TEXTURE2D(_DetailMap,sampler_DetailMap, uv2);//第二套UV Detail细节图
  259. detail_color = lerp(base_color * 0.2, float3(1.0, 1.0, 1.0), detail_color);
  260. half3 final_line = inner_line_color * inner_line_color * detail_color;
  261. //补光、边缘
  262. float3 lightDir_rim = normalize(mul((float3x3)unity_MatrixInvV,_RimLightDir.xyz));
  263. half NdotL_rim = (dot(normalDir, lightDir_rim)+ 1.0) * 0.5;
  264. half rimlight_term = NdotL_rim + diffuse_control;
  265. half toon_rim = saturate((rimlight_term - _ToonThesHold) * 20);
  266. half3 rim_color = (_RimLightColor.rgb + base_color) * 0.5 * sss_alpha;
  267. half3 final_rimlight = toon_rim * rim_color * base_mask * toon_diffuse * _RimLightColor.a;
  268. half3 final_color = (final_diffuse + final_spec + final_rimlight) * final_line;
  269. final_color = sqrt(max(exp2(log2(max(final_color, 0.0)) * 2.2), 0.0));
  270. return float4(final_color,1.0);
  271. }
  272. ENDHLSL
  273. }
  274. Pass
  275. {
  276. Cull Front
  277. CGPROGRAM
  278. #pragma vertex vert
  279. #pragma fragment frag
  280. #include "UnityCG.cginc"
  281. #include "AutoLight.cginc"
  282. struct appdata
  283. {
  284. float4 vertex : POSITION;
  285. float2 texcoord0 : TEXCOORD0;
  286. float3 normal : NORMAL;
  287. float4 color : COLOR;
  288. };
  289. struct v2f
  290. {
  291. float4 pos : SV_POSITION;
  292. float2 uv : TEXCOORD0;
  293. float4 vertex_color : TEXCOORD3;
  294. };
  295. sampler2D _BaseMap;
  296. sampler2D _SSSMap;
  297. sampler2D _ILMMap;
  298. float _OutlineWidth;
  299. float _OutlineZbias;
  300. float4 _OutlineColor;
  301. sampler2D _ClothMask1;
  302. sampler2D _ClothMask2;
  303. sampler2D _ClothMask3;
  304. v2f vert (appdata v)
  305. {
  306. v2f o;
  307. float3 pos_view = UnityObjectToViewPos(v.vertex);
  308. float3 normal_world = UnityObjectToWorldNormal(v.normal);
  309. float3 outline_dir = normalize(mul((float3x3)UNITY_MATRIX_V, normal_world));
  310. outline_dir.z = _OutlineZbias * (1.0 - v.color.b);
  311. pos_view += outline_dir * _OutlineWidth * 0.001 * v.color.a;
  312. o.pos = mul(UNITY_MATRIX_P, float4(pos_view, 1.0));
  313. o.uv = v.texcoord0;
  314. o.vertex_color = v.color;
  315. return o;
  316. }
  317. half4 frag(v2f i) : SV_Target
  318. {
  319. half v_ClothMask1 = tex2D(_ClothMask1, i.uv.xy).r;//_ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r;
  320. clip(v_ClothMask1 - 0.5);
  321. half v_ClothMask2 = tex2D(_ClothMask2, i.uv.xy).r;
  322. clip(v_ClothMask2 - 0.5);
  323. half v_ClothMask3 = tex2D(_ClothMask3, i.uv.xy).r;
  324. clip(v_ClothMask3 - 0.5);
  325. float3 basecolor = tex2D(_BaseMap, i.uv.xy).xyz;
  326. half maxComponent = max(max(basecolor.r, basecolor.g), basecolor.b) - 0.004;
  327. half3 saturatedColor = step(maxComponent.rrr, basecolor) * basecolor;
  328. saturatedColor = lerp(basecolor.rgb, saturatedColor, 0.6);
  329. half3 outlineColor = 0.8 * saturatedColor * basecolor * _OutlineColor.xyz;
  330. return float4(outlineColor, 1.0);
  331. }
  332. ENDCG
  333. }
  334. Pass
  335. {
  336. Name "ShadowCaster"
  337. Tags{"LightMode" = "ShadowCaster"}
  338. ZWrite On
  339. ZTest LEqual
  340. ColorMask 0
  341. Cull[_Cull]
  342. HLSLPROGRAM
  343. #pragma exclude_renderers gles gles3 glcore
  344. #pragma target 4.5
  345. // -------------------------------------
  346. // Material Keywords
  347. #pragma shader_feature_local_fragment _ALPHATEST_ON
  348. #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  349. //--------------------------------------
  350. // GPU Instancing
  351. #pragma multi_compile_instancing
  352. #pragma multi_compile _ DOTS_INSTANCING_ON
  353. // -------------------------------------
  354. // Universal Pipeline keywords
  355. // This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias
  356. #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
  357. #pragma vertex ShadowPassVertex
  358. #pragma fragment ShadowPassFragment
  359. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  360. #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
  361. ENDHLSL
  362. }
  363. Pass
  364. {
  365. Name "DepthOnly"
  366. Tags{"LightMode" = "DepthOnly"}
  367. ZWrite On
  368. ColorMask 0
  369. Cull[_Cull]
  370. HLSLPROGRAM
  371. #pragma exclude_renderers gles gles3 glcore
  372. #pragma target 4.5
  373. #pragma vertex DepthOnlyVertex
  374. #pragma fragment DepthOnlyFragment
  375. // -------------------------------------
  376. // Material Keywords
  377. #pragma shader_feature_local_fragment _ALPHATEST_ON
  378. #pragma shader_feature_local_fragment _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
  379. //--------------------------------------
  380. // GPU Instancing
  381. #pragma multi_compile_instancing
  382. #pragma multi_compile _ DOTS_INSTANCING_ON
  383. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  384. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
  385. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  386. ENDHLSL
  387. }
  388. // Pass
  389. // {
  390. // Name "ForwardLit"
  391. // Tags{"LightMode" = "UniversalForward"}
  392. // Stencil {
  393. // Ref[_Stencil]
  394. // ReadMask[_ReadMask]
  395. // WriteMask[_WriteMask]
  396. // Comp[_StencilComp]
  397. // Pass[_StencilOp]
  398. // Fail[_StencilFail]
  399. // ZFail[_StencilZFail]
  400. // }
  401. // ZWrite On
  402. // Cull Back
  403. // HLSLPROGRAM
  404. // // Required to compile gles 2.0 with standard SRP library
  405. // #pragma prefer_hlslcc gles
  406. // #pragma exclude_renderers d3d11_9x
  407. // #pragma target 2.0
  408. // // -------------------------------------
  409. // // Material Keywords
  410. // #define _SPECULAR_SETUP
  411. // #pragma shader_feature_local _NORMALMAP
  412. // #pragma shader_feature_local_fragment _NORMALMAPDIFFUSE
  413. // #pragma shader_feature_local _DISTANCEFADE // not per fragment
  414. // #pragma shader_feature_local_fragment _RIMLIGHTING
  415. // #pragma shader_feature_local_fragment _BACKSCATTER
  416. // #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  417. // #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  418. // #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  419. // // -------------------------------------
  420. // // Universal Pipeline keywords
  421. // #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  422. // #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  423. // #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  424. // #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  425. // #pragma multi_compile_fragment _ _SHADOWS_SOFT
  426. // #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  427. // #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  428. // #pragma multi_compile _ SHADOWS_SHADOWMASK
  429. // // -------------------------------------
  430. // // Unity defined keywords
  431. // #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  432. // #pragma multi_compile _ LIGHTMAP_ON
  433. // #pragma multi_compile_fog
  434. // //--------------------------------------
  435. // // GPU Instancing
  436. // #pragma multi_compile_instancing
  437. // // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  438. // // Include base inputs and all other needed "base" includes
  439. // #include "Includes/Lux URP Skin Inputs Custom.hlsl"
  440. // #pragma vertex LitPassVertex
  441. // #pragma fragment LitPassFragment
  442. // //--------------------------------------
  443. // // Vertex shader
  444. // VertexOutput LitPassVertex(VertexInput input)
  445. // {
  446. // VertexOutput output = (VertexOutput)0;
  447. // UNITY_SETUP_INSTANCE_ID(input);
  448. // UNITY_TRANSFER_INSTANCE_ID(input, output);
  449. // UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  450. // // Set distance fade value
  451. // #if defined(_DISTANCEFADE)
  452. // float3 worldInstancePos = UNITY_MATRIX_M._m03_m13_m23;
  453. // float3 diff = (_WorldSpaceCameraPos - worldInstancePos);
  454. // float dist = dot(diff, diff);
  455. // output.fade = saturate((_DistanceFade.x - dist) * _DistanceFade.y);
  456. // #else
  457. // output.fade = 1.0h;
  458. // #endif
  459. // VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  460. // VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  461. // float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  462. // half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  463. // half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  464. // output.uv.xy = input.texcoord;
  465. // output.normalWS = normalInput.normalWS; //NormalizeNormalPerVertex(normalInput.normalWS);
  466. // output.viewDirWS = viewDirWS;
  467. // #ifdef _NORMALMAP
  468. // float sign = input.tangentOS.w * GetOddNegativeScale();
  469. // output.tangentWS = float4(normalInput.tangentWS.xyz, sign);
  470. // #endif
  471. // OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  472. // OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  473. // output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  474. // #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  475. // output.positionWS = vertexInput.positionWS;
  476. // #endif
  477. // #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  478. // // tweak the sampling position
  479. // vertexInput.positionWS += output.normalWS.xyz * _SkinShadowSamplingBias;
  480. // output.shadowCoord = GetShadowCoord(vertexInput);
  481. // #endif
  482. // output.positionCS = vertexInput.positionCS;
  483. // return output;
  484. // }
  485. // //--------------------------------------
  486. // // Fragment shader and functions
  487. // inline void InitializeSkinLitSurfaceData(float2 uv, half fade, out SurfaceDescription outSurfaceData)
  488. // {
  489. // half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)) * _BaseColor;
  490. // //--------------------------------------------------------
  491. // float2 uv_MakeUpMask1_RGB = uv.xy * _MakeUpMask1_RGB_ST.xy + _MakeUpMask1_RGB_ST.zw;
  492. // float4 tex2DNode143 = SAMPLE_TEXTURE2D(_MakeUpMask1_RGB, sampler_MakeUpMask1_RGB, uv_MakeUpMask1_RGB);
  493. // float2 uv_Mask1_Rchannel_TextureAmountA = uv.xy * _Mask1_Rchannel_TextureAmountA_ST.xy + _Mask1_Rchannel_TextureAmountA_ST.zw;
  494. // float4 tex2D_mask1_R = SAMPLE_TEXTURE2D(_Mask1_Rchannel_TextureAmountA, sampler_Mask1_Rchannel_TextureAmountA, uv_Mask1_Rchannel_TextureAmountA);
  495. // float2 uv_Mask1_Gchannel_TextureAmountA = uv.xy * _Mask1_Gchannel_TextureAmountA_ST.xy + _Mask1_Gchannel_TextureAmountA_ST.zw;
  496. // float4 tex2D_mask1_G = SAMPLE_TEXTURE2D(_Mask1_Gchannel_TextureAmountA, sampler_Mask1_Gchannel_TextureAmountA, uv_Mask1_Gchannel_TextureAmountA);
  497. // float2 uv_Mask1_Bchannel_TextureAmountA = uv.xy * _Mask1_Bchannel_TextureAmountA_ST.xy + _Mask1_Bchannel_TextureAmountA_ST.zw;
  498. // float4 tex2D_mask1_B = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Bchannel_TextureAmountA);
  499. // float2 uv_Mask1_Achannel_TextureAmountA = uv.xy * _Mask1_Achannel_TextureAmountA_ST.xy + _Mask1_Achannel_TextureAmountA_ST.zw;
  500. // float4 tex2D_mask1_A = SAMPLE_TEXTURE2D(_Mask1_Bchannel_TextureAmountA, sampler_Mask1_Bchannel_TextureAmountA, uv_Mask1_Achannel_TextureAmountA);
  501. // float2 uv_Mask2_Rchannel_TextureAmountA = uv.xy * _Mask2_Rchannel_TextureAmountA_ST.xy + _Mask2_Rchannel_TextureAmountA_ST.zw;
  502. // float4 tex2D_mask2_R = SAMPLE_TEXTURE2D(_Mask2_Rchannel_TextureAmountA, sampler_Mask2_Rchannel_TextureAmountA, uv_Mask2_Rchannel_TextureAmountA);
  503. // float2 uv_Mask2_Gchannel_TextureAmountA = uv.xy * _Mask2_Gchannel_TextureAmountA_ST.xy + _Mask2_Gchannel_TextureAmountA_ST.zw;
  504. // float4 tex2D_mask2_G = SAMPLE_TEXTURE2D(_Mask2_Gchannel_TextureAmountA, sampler_Mask2_Gchannel_TextureAmountA, uv_Mask2_Gchannel_TextureAmountA);
  505. // float2 uv_Mask2_Bchannel_TextureAmountA = uv.xy * _Mask2_Bchannel_TextureAmountA_ST.xy + _Mask2_Bchannel_TextureAmountA_ST.zw;
  506. // float4 tex2D_mask2_B = SAMPLE_TEXTURE2D(_Mask2_Bchannel_TextureAmountA, sampler_Mask2_Bchannel_TextureAmountA, uv_Mask2_Bchannel_TextureAmountA);
  507. // float clampResult295 = clamp((tex2DNode143.r * tex2D_mask1_R.a * _Mask1_Rchannel_ColorAmountA.a), 0.0, 1.0);
  508. // float4 _Mask1_R_Color = tex2D_mask1_R * _Mask1_Rchannel_ColorAmountA;
  509. // float4 lerpResult145 = lerp(albedoAlpha, _Mask1_R_Color, clampResult295);
  510. // float clampResult296 = clamp((tex2DNode143.g * tex2D_mask1_G.a * _Mask1_Gchannel_ColorAmountA.a), 0.0, 1.0);
  511. // float4 _Mask1_G_Color = tex2D_mask1_G * _Mask1_Gchannel_ColorAmountA;
  512. // float4 lerpResult160 = lerp(lerpResult145, _Mask1_G_Color, clampResult296);
  513. // float clampResult297 = clamp((tex2DNode143.b * tex2D_mask1_B.a * _Mask1_Bchannel_ColorAmountA.a), 0.0, 1.0);
  514. // float4 _Mask1_B_Color = tex2D_mask1_B * _Mask1_Bchannel_ColorAmountA;
  515. // float4 lerpResult161 = lerp(lerpResult160, _Mask1_B_Color, clampResult297);
  516. // float clampResult2971 = clamp((tex2DNode143.a * tex2D_mask1_A.a * _Mask1_Achannel_ColorAmountA.a), 0.0, 1.0);
  517. // float4 _Mask1_A_Color = tex2D_mask1_A * _Mask1_Achannel_ColorAmountA;
  518. // float4 lerpResult1611 = lerp(lerpResult161, _Mask1_A_Color, clampResult2971);
  519. // //mask2
  520. // float2 uv_MakeUpMask2_RGB = uv.xy * _MakeUpMask2_RGB_ST.xy + _MakeUpMask2_RGB_ST.zw;
  521. // float4 tex2DNode144 = SAMPLE_TEXTURE2D(_MakeUpMask2_RGB, sampler_MakeUpMask2_RGB, uv_MakeUpMask2_RGB);
  522. // float clampResult298 = clamp((tex2DNode144.r * tex2D_mask2_R.a * _Mask2_Rchannel_ColorAmountA.a), 0.0, 1.0);
  523. // float4 _Mask2_R_Color = tex2D_mask2_R * _Mask2_Rchannel_ColorAmountA;
  524. // float4 lerpResult162 = lerp(lerpResult1611, _Mask2_Rchannel_ColorAmountA, clampResult298);
  525. // float clampResult299 = clamp((tex2DNode144.g * tex2D_mask2_G.a * _Mask2_Gchannel_ColorAmountA.a), 0.0, 1.0);
  526. // float4 _Mask2_G_Color = tex2D_mask2_G * _Mask2_Gchannel_ColorAmountA;
  527. // float4 lerpResult163 = lerp(lerpResult162, _Mask2_Gchannel_ColorAmountA, clampResult299);
  528. // float clampResult300 = clamp((tex2DNode144.b * tex2D_mask2_B.a * _Mask2_Bchannel_ColorAmountA.a), 0.0, 1.0);
  529. // float4 _Mask2_B_Color = tex2D_mask2_B * _Mask2_Bchannel_ColorAmountA;
  530. // float4 lerpResult164 = lerp(lerpResult163, _Mask2_Bchannel_ColorAmountA, clampResult300);
  531. // albedoAlpha.rgb = half3(lerpResult164.r, lerpResult164.g, lerpResult164.b);
  532. // //--------------------------------
  533. // outSurfaceData.alpha = 1;
  534. // outSurfaceData.albedo = albedoAlpha.rgb;
  535. // outSurfaceData.metallic = 0;
  536. // outSurfaceData.specular = _SpecularColor.rgb;
  537. // // Normal Map
  538. // #if defined (_NORMALMAP)
  539. // outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  540. // #if defined(_NORMALMAPDIFFUSE)
  541. // half4 sampleNormalDiffuse = SAMPLE_TEXTURE2D_BIAS(_BumpMap, sampler_BumpMap, uv, _Bias);
  542. // // Do not manually unpack the normal map as it might use RGB.
  543. // outSurfaceData.diffuseNormalTS = UnpackNormal(sampleNormalDiffuse);
  544. // #else
  545. // outSurfaceData.diffuseNormalTS = half3(0,0,1);
  546. // #endif
  547. // #else
  548. // outSurfaceData.normalTS = half3(0,0,1);
  549. // outSurfaceData.diffuseNormalTS = half3(0,0,1);
  550. // #endif
  551. // half4 SSSAOSample = SAMPLE_TEXTURE2D(_SSSAOMap, sampler_SSSAOMap, uv);
  552. // outSurfaceData.translucency = SSSAOSample.g;
  553. // outSurfaceData.skinMask = SSSAOSample.r;
  554. // outSurfaceData.occlusion = lerp(1.0h, SSSAOSample.a, _OcclusionStrength);
  555. // outSurfaceData.curvature = SSSAOSample.b;
  556. // outSurfaceData.smoothness = albedoAlpha.a * _Smoothness;
  557. // outSurfaceData.emission = SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, uv).rgb * _EmissionColor.rgb;
  558. // }
  559. // void InitializeInputData(VertexOutput input, half3 normalTS, half3 diffuseNormalTS, out InputData inputData
  560. // #ifdef _NORMALMAP
  561. // , inout float3 bitangent
  562. // #endif
  563. // , inout half3 diffuseNormalWS
  564. // )
  565. // {
  566. // inputData = (InputData)0;
  567. // #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  568. // inputData.positionWS = input.positionWS;
  569. // #endif
  570. // half3 viewDirWS = SafeNormalize(input.viewDirWS);
  571. // #ifdef _NORMALMAP
  572. // float sgn = input.tangentWS.w; // should be either +1 or -1
  573. // bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  574. // half3x3 ToW = half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz);
  575. // inputData.normalWS = TransformTangentToWorld(normalTS, ToW);
  576. // inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  577. // #ifdef _NORMALMAPDIFFUSE
  578. // diffuseNormalWS = TransformTangentToWorld(diffuseNormalTS, ToW);
  579. // diffuseNormalWS = NormalizeNormalPerPixel(diffuseNormalWS);
  580. // #else
  581. // // Here we let the user decide to use the per vertex or the specular normal.
  582. // diffuseNormalWS = (_VertexNormal) ? NormalizeNormalPerPixel(input.normalWS.xyz) : inputData.normalWS;
  583. // #endif
  584. // #else
  585. // inputData.normalWS = NormalizeNormalPerPixel(input.normalWS);
  586. // diffuseNormalWS = inputData.normalWS;
  587. // #endif
  588. // inputData.viewDirectionWS = viewDirWS;
  589. // #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  590. // inputData.shadowCoord = input.shadowCoord;
  591. // #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  592. // inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS + input.normalWS * _SkinShadowSamplingBias);
  593. // #else
  594. // inputData.shadowCoord = float4(0, 0, 0, 0);
  595. // #endif
  596. // inputData.fogCoord = input.fogFactorAndVertexLight.x;
  597. // inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  598. // inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, diffuseNormalWS); //inputData.normalWS);
  599. // //inputData.normalizedScreenSpaceUV = input.positionCS.xy;
  600. // inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  601. // }
  602. // half4 LitPassFragment(VertexOutput input) : SV_Target
  603. // {
  604. // UNITY_SETUP_INSTANCE_ID(input);
  605. // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  606. // // clip cloth mask
  607. // half v_ClothMask1 = _ClothMask1.Sample(sampler_ClothMask1, input.uv.xy).r;
  608. // clip(v_ClothMask1 - 0.5);
  609. // half v_ClothMask2 = _ClothMask2.Sample(sampler_ClothMask1, input.uv.xy).r;
  610. // clip(v_ClothMask2 - 0.5);
  611. // half v_ClothMask3 = _ClothMask3.Sample(sampler_ClothMask1, input.uv.xy).r;
  612. // clip(v_ClothMask3 - 0.5);
  613. // // Get the surface description
  614. // SurfaceDescription surfaceData;
  615. // InitializeSkinLitSurfaceData(input.uv.xy, input.fade, surfaceData);
  616. // // Prepare surface data (like bring normal into world space and get missing inputs like gi
  617. // half3 diffuseNormalWS;
  618. // InputData inputData;
  619. // #ifdef _NORMALMAP
  620. // float3 bitangent;
  621. // #endif
  622. // InitializeInputData(input, surfaceData.normalTS, surfaceData.diffuseNormalTS, inputData
  623. // #ifdef _NORMALMAP
  624. // , bitangent
  625. // #endif
  626. // , diffuseNormalWS
  627. // );
  628. // #if defined(_RIMLIGHTING)
  629. // half rim = saturate(1.0h - saturate(dot(inputData.normalWS, inputData.viewDirectionWS)));
  630. // half power = _RimPower;
  631. // UNITY_BRANCH if (_RimFrequency > 0) {
  632. // half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h) * _RimPerPositionFrequency) * 3.1416h;
  633. // power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition)) * 0.5h);
  634. // }
  635. // surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
  636. // #endif
  637. // // Apply lighting
  638. // half4 color = LuxLWRPSkinFragmentPBR(
  639. // inputData,
  640. // surfaceData.albedo,
  641. // surfaceData.metallic,
  642. // surfaceData.specular,
  643. // surfaceData.smoothness,
  644. // surfaceData.occlusion,
  645. // surfaceData.emission,
  646. // surfaceData.alpha,
  647. // // Subsurface Scattering
  648. // half4(_TranslucencyStrength * surfaceData.translucency, _TranslucencyPower, _ShadowStrength, _Distortion),
  649. // // AmbientReflection Strength
  650. // _AmbientReflectionStrength,
  651. // // Diffuse Normal
  652. // // #if defined(_NORMALMAP) && defined(_NORMALMAPDIFFUSE)
  653. // // NormalizeNormalPerPixel( TransformTangentToWorld(surfaceData.diffuseNormalTS, half3x3(input.tangentWS.xyz, bitangent, input.normalWS.xyz)) )
  654. // // #else
  655. // // input.normalWS
  656. // // #endif
  657. // diffuseNormalWS,
  658. // _SubsurfaceColor.rgb,
  659. // (_SampleCurvature) ? surfaceData.curvature * _Curvature : lerp(surfaceData.translucency, 1, _Curvature),
  660. // // Lerp lighting towards standard according the distance fade
  661. // surfaceData.skinMask * input.fade,
  662. // _MaskByShadowStrength,
  663. // _Backscatter
  664. // );
  665. // // Add fog
  666. // color.rgb = MixFog(color.rgb, inputData.fogCoord);
  667. // return color;
  668. // }
  669. // ENDHLSL
  670. // }
  671. // // Shadows -----------------------------------------------------
  672. // Pass
  673. // {
  674. // Name "ShadowCaster"
  675. // Tags{"LightMode" = "ShadowCaster"}
  676. // ZWrite On
  677. // ZTest LEqual
  678. // ColorMask 0
  679. // Cull Back
  680. // HLSLPROGRAM
  681. // // Required to compile gles 2.0 with standard srp library
  682. // #pragma prefer_hlslcc gles
  683. // #pragma exclude_renderers d3d11_9x
  684. // #pragma target 2.0
  685. // // -------------------------------------
  686. // // Material Keywords
  687. // //--------------------------------------
  688. // // GPU Instancing
  689. // #pragma multi_compile_instancing
  690. // #pragma vertex ShadowPassVertex
  691. // #pragma fragment ShadowPassFragment
  692. // // Include base inputs and all other needed "base" includes
  693. // #include "Includes/Lux URP Skin Inputs Custom.hlsl"
  694. // #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  695. // // Shadow caster specific input
  696. // float3 _LightDirection;
  697. // VertexOutput ShadowPassVertex(VertexInput input)
  698. // {
  699. // VertexOutput output = (VertexOutput)0;
  700. // UNITY_SETUP_INSTANCE_ID(input);
  701. // UNITY_TRANSFER_INSTANCE_ID(input, output);
  702. // float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  703. // float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  704. // output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _SkinShadowBias, _LightDirection));
  705. // #if UNITY_REVERSED_Z
  706. // output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  707. // #else
  708. // output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  709. // #endif
  710. // return output;
  711. // }
  712. // half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  713. // {
  714. // UNITY_SETUP_INSTANCE_ID(input);
  715. // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  716. // return 0;
  717. // }
  718. // ENDHLSL
  719. // }
  720. //// Depth -----------------------------------------------------
  721. // Pass
  722. // {
  723. // Tags{"LightMode" = "DepthOnly"}
  724. // ZWrite On
  725. // ColorMask 0
  726. // Cull Back
  727. // HLSLPROGRAM
  728. // // Required to compile gles 2.0 with standard srp library
  729. // #pragma prefer_hlslcc gles
  730. // #pragma exclude_renderers d3d11_9x
  731. // #pragma target 2.0
  732. // #pragma vertex DepthOnlyVertex
  733. // #pragma fragment DepthOnlyFragment
  734. // // -------------------------------------
  735. // // Material Keywords
  736. // //--------------------------------------
  737. // // GPU Instancing
  738. // #pragma multi_compile_instancing
  739. // #define DEPTHONLYPASS
  740. // #include "Includes/Lux URP Skin Inputs Custom.hlsl"
  741. // VertexOutput DepthOnlyVertex(VertexInput input)
  742. // {
  743. // VertexOutput output = (VertexOutput)0;
  744. // UNITY_SETUP_INSTANCE_ID(input);
  745. // UNITY_TRANSFER_INSTANCE_ID(input, output);
  746. // UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  747. // output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  748. // return output;
  749. // }
  750. // half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  751. // {
  752. // UNITY_SETUP_INSTANCE_ID(input);
  753. // UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  754. // return 0;
  755. // }
  756. // ENDHLSL
  757. // }
  758. //// Depth Normals --------------------------------------------
  759. // Pass
  760. // {
  761. // Name "DepthNormals"
  762. // Tags{"LightMode" = "DepthNormals"}
  763. // ZWrite On
  764. // Cull Back
  765. // HLSLPROGRAM
  766. // // Required to compile gles 2.0 with standard SRP library
  767. // #pragma prefer_hlslcc gles
  768. // #pragma exclude_renderers d3d11_9x
  769. // #pragma target 2.0
  770. // #pragma vertex DepthNormalsVertex
  771. // #pragma fragment DepthNormalsFragment
  772. // // -------------------------------------
  773. // // Material Keywords
  774. // #pragma shader_feature_local _NORMALMAP
  775. // //--------------------------------------
  776. // // GPU Instancing
  777. // #pragma multi_compile_instancing
  778. // // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  779. // //#include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  780. // #include "Includes/Lux URP Skin Inputs Custom.hlsl"
  781. // #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthNormalsPass.hlsl"
  782. // ENDHLSL
  783. // }
  784. //// Meta -----------------------------------------------------
  785. // Pass
  786. // {
  787. // Tags{"LightMode" = "Meta"}
  788. // Cull Off
  789. // HLSLPROGRAM
  790. // // Required to compile gles 2.0 with standard srp library
  791. // #pragma prefer_hlslcc gles
  792. // #pragma vertex UniversalVertexMeta
  793. // #pragma fragment UniversalFragmentMeta
  794. // #define _SPECULAR_SETUP
  795. // // First include all our custom stuff
  796. // #include "Includes/Lux URP Skin Inputs Custom.hlsl"
  797. // //--------------------------------------
  798. // // Fragment shader and functions
  799. // inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  800. // {
  801. // half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  802. // outSurfaceData.alpha = 1;
  803. // outSurfaceData.albedo = albedoAlpha.rgb;
  804. // outSurfaceData.metallic = 0;
  805. // outSurfaceData.specular = _SpecularColor.rgb;
  806. // outSurfaceData.smoothness = _Smoothness;
  807. // outSurfaceData.normalTS = half3(0,0,1);
  808. // outSurfaceData.occlusion = 1;
  809. // outSurfaceData.emission = 0;
  810. // outSurfaceData.clearCoatMask = 0;
  811. // outSurfaceData.clearCoatSmoothness = 0;
  812. // }
  813. // // Finally include the meta pass related stuff
  814. // #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  815. // ENDHLSL
  816. // }
  817. // End Passes -----------------------------------------------------
  818. }
  819. CustomEditor "LuxURPCustomSkinShaderGUI"
  820. FallBack "Hidden/InternalErrorShader"
  821. }