Lux URP Simple Fuzz.shader 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. // Shader uses custom editor to set double sided GI
  2. // Needs _Culling to be set properly
  3. Shader "Lux URP/Simple Fuzz"
  4. {
  5. Properties
  6. {
  7. [HeaderHelpLuxURP_URL(oln7rjvorl9x)]
  8. [Header(Surface Options)]
  9. [Space(8)]
  10. [Enum(UnityEngine.Rendering.CullMode)]
  11. _Cull ("Culling", Float) = 2
  12. [Toggle(_ALPHATEST_ON)]
  13. _AlphaClip ("Alpha Clipping", Float) = 0.0
  14. [LuxURPHelpDrawer]
  15. _Help ("Enabling Alpha Clipping needs you to enable and assign the Mask Map as well.", Float) = 0.0
  16. _Cutoff (" Threshold", Range(0.0, 1.0)) = 0.5
  17. [Enum(Off,0,On,1)]_Coverage (" Alpha To Coverage", Float) = 0
  18. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  19. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  20. _ShadowOffset ("Shadow Offset", Float) = 1.0
  21. [Header(Fuzz Lighting)]
  22. [Space(8)]
  23. [Toggle(_SIMPLEFUZZ)]
  24. _EnableFuzzyLighting ("Enable Fuzzy Lighting", Float) = 1.0
  25. _FuzzWrap (" Diffuse Wrap", Range(0, 1)) = 0.5
  26. _FuzzStrength (" Fuzz Strength", Range(0, 8)) = 2
  27. _FuzzPower (" Fuzz Power", Range(1, 16)) = 4
  28. _FuzzBias (" Fuzz Bias", Range(0, 1)) = 0
  29. _FuzzAmbient (" Ambient Strength", Range(0, 1)) = 1
  30. [Header(Transmission)]
  31. [Space(8)]
  32. [Toggle(_SCATTERING)]
  33. _UseScattering ("Enable Transmission", Float) = 0.0
  34. _TranslucencyPower (" Power", Range(0.0, 32.0)) = 7.0
  35. _TranslucencyStrength (" Strength", Range(0.0, 1.0)) = 1.0
  36. _ShadowStrength (" Shadow Strength", Range(0.0, 1.0)) = 0.7
  37. _Distortion (" Distortion", Range(0.0, 0.1)) = 0.01
  38. [Header(Surface Inputs)]
  39. [Space(8)]
  40. [MainColor]
  41. _BaseColor ("Color", Color) = (1,1,1,1)
  42. [MainTexture]
  43. _BaseMap ("Albedo (RGB) Smoothness (A)", 2D) = "white" {}
  44. [Space(5)]
  45. _Smoothness ("Smoothness", Range(0.0, 1.0)) = 0.5
  46. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  47. [Space(5)]
  48. [Toggle(_NORMALMAP)]
  49. _ApplyNormal ("Enable Normal Map", Float) = 0.0
  50. [NoScaleOffset]
  51. _BumpMap (" Normal Map", 2D) = "bump" {}
  52. _BumpScale (" Normal Scale", Float) = 1.0
  53. [Space(5)]
  54. [Toggle(_MASKMAP)]
  55. _EnableMaskMap ("Enable Mask Map", Float) = 0.0
  56. _MaskMap (" FuzzMask (R) Thickness (G) Occlusion (B) Alpha (A)", 2D) = "white" {}
  57. _OcclusionStrength (" Occlusion", Range(0.0, 1.0)) = 1
  58. [Header(Rim Lighting)]
  59. [Space(8)]
  60. [Toggle(_RIMLIGHTING)]
  61. _Rim ("Enable Rim Lighting", Float) = 0
  62. [HDR] _RimColor ("Rim Color", Color) = (0.5,0.5,0.5,1)
  63. _RimPower ("Rim Power", Float) = 2
  64. _RimFrequency ("Rim Frequency", Float) = 0
  65. _RimMinPower (" Rim Min Power", Float) = 1
  66. _RimPerPositionFrequency (" Rim Per Position Frequency", Range(0.0, 1.0)) = 1
  67. [Header(Stencil)]
  68. [Space(8)]
  69. [IntRange] _Stencil ("Stencil Reference", Range (0, 255)) = 0
  70. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  71. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  72. [Enum(UnityEngine.Rendering.CompareFunction)]
  73. _StencilComp ("Stencil Comparison", Int) = 8 // always – terrain should be the first thing being rendered anyway
  74. [Enum(UnityEngine.Rendering.StencilOp)]
  75. _StencilOp ("Stencil Operation", Int) = 0 // 0 = keep, 2 = replace
  76. [Enum(UnityEngine.Rendering.StencilOp)]
  77. _StencilFail ("Stencil Fail Op", Int) = 0 // 0 = keep
  78. [Enum(UnityEngine.Rendering.StencilOp)]
  79. _StencilZFail ("Stencil ZFail Op", Int) = 0 // 0 = keep
  80. [Header(Advanced)]
  81. [Space(8)]
  82. [ToggleOff]
  83. _SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  84. [ToggleOff]
  85. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  86. [Space(5)]
  87. [Toggle(_RECEIVE_SHADOWS_OFF)]
  88. _Shadows ("Disable Receive Shadows", Float) = 0.0
  89. [Header(Render Queue)]
  90. [Space(8)]
  91. [IntRange] _QueueOffset ("Queue Offset", Range(-50, 50)) = 0
  92. // Needed by the inspector
  93. [HideInInspector] _Culling ("Culling", Float) = 0.0
  94. [HideInInspector] _AlphaFromMaskMap ("AlphaFromMaskMap", Float) = 1.0
  95. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  96. [HideInInspector] _MainTex ("Albedo", 2D) = "white" {}
  97. [HideInInspector] _Color ("Color", Color) = (1,1,1,1)
  98. }
  99. SubShader
  100. {
  101. Tags
  102. {
  103. "RenderPipeline" = "UniversalPipeline"
  104. "RenderType" = "Opaque"
  105. "Queue" = "Geometry"
  106. }
  107. LOD 100
  108. Pass
  109. {
  110. Name "ForwardLit"
  111. Tags{"LightMode" = "UniversalForward"}
  112. Stencil {
  113. Ref [_Stencil]
  114. ReadMask [_ReadMask]
  115. WriteMask [_WriteMask]
  116. Comp [_StencilComp]
  117. Pass [_StencilOp]
  118. Fail [_StencilFail]
  119. ZFail [_StencilZFail]
  120. }
  121. ZWrite On
  122. Cull [_Cull]
  123. AlphaToMask [_Coverage]
  124. HLSLPROGRAM
  125. // Required to compile gles 2.0 with standard srp library
  126. #pragma prefer_hlslcc gles
  127. #pragma exclude_renderers d3d11_9x
  128. #pragma target 2.0
  129. // -------------------------------------
  130. // Material Keywords
  131. #define _SPECULAR_SETUP 1
  132. #pragma shader_feature_local _NORMALMAP
  133. #pragma shader_feature_local_fragment _ALPHATEST_ON
  134. #pragma shader_feature_local_fragment _SIMPLEFUZZ
  135. #pragma shader_feature_local _MASKMAP // not per fragment!
  136. #pragma shader_feature_local_fragment _SCATTERING
  137. #pragma shader_feature_local_fragment _RIMLIGHTING
  138. #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  139. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  140. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  141. // -------------------------------------
  142. // Universal Pipeline keywords
  143. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  144. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  145. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  146. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  147. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  148. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  149. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  150. #pragma multi_compile _ SHADOWS_SHADOWMASK
  151. // -------------------------------------
  152. // Unity defined keywords
  153. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  154. #pragma multi_compile _ LIGHTMAP_ON
  155. #pragma multi_compile_fog
  156. //--------------------------------------
  157. // GPU Instancing
  158. #pragma multi_compile_instancing
  159. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  160. // Include base inputs and all other needed "base" includes
  161. #include "Includes/Lux URP Simple Fuzz Inputs.hlsl"
  162. #pragma vertex LitPassVertex
  163. #pragma fragment LitPassFragment
  164. //--------------------------------------
  165. // Vertex shader
  166. VertexOutput LitPassVertex(VertexInput input)
  167. {
  168. VertexOutput output = (VertexOutput)0;
  169. UNITY_SETUP_INSTANCE_ID(input);
  170. UNITY_TRANSFER_INSTANCE_ID(input, output);
  171. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  172. VertexPositionInputs vertexInput; //
  173. vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  174. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  175. float3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  176. half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  177. half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  178. output.uv.xy = TRANSFORM_TEX(input.texcoord, _BaseMap);
  179. #if defined(_MASKMAP)
  180. output.uv.zw = TRANSFORM_TEX(input.texcoord, _MaskMap);
  181. #endif
  182. output.normalWS = normalInput.normalWS;
  183. output.viewDirWS = viewDirWS;
  184. #ifdef _NORMALMAP
  185. float sign = input.tangentOS.w * GetOddNegativeScale();
  186. output.tangentWS = float4(normalInput.tangentWS.xyz, sign);
  187. #endif
  188. OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  189. OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  190. output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  191. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  192. output.positionWS = vertexInput.positionWS;
  193. #endif
  194. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  195. output.shadowCoord = GetShadowCoord(vertexInput);
  196. #endif
  197. output.positionCS = vertexInput.positionCS;
  198. return output;
  199. }
  200. //--------------------------------------
  201. // Fragment shader and functions
  202. inline void InitializeSurfaceData(
  203. #if defined(_MASKMAP)
  204. float4 uv,
  205. #else
  206. float2 uv,
  207. #endif
  208. out SurfaceDescription outSurfaceData)
  209. {
  210. half4 albedoSmoothness = SampleAlbedoAlpha(uv.xy, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  211. #if defined(_MASKMAP)
  212. half4 maskSample = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, uv.zw);
  213. outSurfaceData.fuzzMask = maskSample.r;
  214. outSurfaceData.translucency = maskSample.g;
  215. //outSurfaceData.skinMask = SSSAOSample.r;
  216. outSurfaceData.occlusion = lerp(1.0h, maskSample.b, _OcclusionStrength);
  217. #else
  218. outSurfaceData.fuzzMask = 1;
  219. outSurfaceData.translucency = 1;
  220. outSurfaceData.occlusion = 1;
  221. #endif
  222. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  223. outSurfaceData.alpha = Alpha(maskSample.a, 1, _Cutoff);
  224. #else
  225. outSurfaceData.alpha = 1;
  226. #endif
  227. outSurfaceData.albedo = albedoSmoothness.rgb * _BaseColor.rgb;
  228. outSurfaceData.metallic = 0;
  229. outSurfaceData.specular = _SpecColor.rgb;
  230. outSurfaceData.smoothness = albedoSmoothness.a * _Smoothness;
  231. // Normal Map
  232. #if defined (_NORMALMAP)
  233. outSurfaceData.normalTS = SampleNormal(uv.xy, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), _BumpScale);
  234. #else
  235. outSurfaceData.normalTS = half3(0,0,1);
  236. #endif
  237. outSurfaceData.emission = 0;
  238. }
  239. void InitializeInputData(VertexOutput input, half3 normalTS, half facing, out InputData inputData)
  240. {
  241. inputData = (InputData)0;
  242. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  243. inputData.positionWS = input.positionWS;
  244. #endif
  245. half3 viewDirWS = SafeNormalize(input.viewDirWS);
  246. #if defined(_NORMALMAP) || !defined(_COTTONWOOL)
  247. normalTS.z *= facing;
  248. float sgn = input.tangentWS.w; // should be either +1 or -1
  249. float3 bitangent = sgn * cross(input.normalWS.xyz, input.tangentWS.xyz);
  250. inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz));
  251. #else
  252. inputData.normalWS = input.normalWS * facing;
  253. #endif
  254. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  255. inputData.viewDirectionWS = viewDirWS;
  256. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  257. inputData.shadowCoord = input.shadowCoord;
  258. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  259. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  260. #else
  261. inputData.shadowCoord = float4(0, 0, 0, 0);
  262. #endif
  263. inputData.fogCoord = input.fogFactorAndVertexLight.x;
  264. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  265. inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
  266. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  267. inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
  268. }
  269. half4 LitPassFragment(VertexOutput input, half facing : VFACE) : SV_Target
  270. {
  271. UNITY_SETUP_INSTANCE_ID(input);
  272. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  273. // Get the surface description
  274. SurfaceDescription surfaceData;
  275. InitializeSurfaceData(input.uv, surfaceData);
  276. // Prepare surface data (like bring normal into world space and get missing inputs like gi)
  277. InputData inputData;
  278. InitializeInputData(input, surfaceData.normalTS, facing, inputData);
  279. #if defined(_RIMLIGHTING)
  280. half rim = saturate(1.0h - saturate( dot(inputData.normalWS, inputData.viewDirectionWS) ) );
  281. half power = _RimPower;
  282. UNITY_BRANCH if(_RimFrequency > 0 ) {
  283. half perPosition = lerp(0.0h, 1.0h, dot(1.0h, frac(UNITY_MATRIX_M._m03_m13_m23) * 2.0h - 1.0h ) * _RimPerPositionFrequency ) * 3.1416h;
  284. power = lerp(power, _RimMinPower, (1.0h + sin(_Time.y * _RimFrequency + perPosition) ) * 0.5h );
  285. }
  286. surfaceData.emission += pow(rim, power) * _RimColor.rgb * _RimColor.a;
  287. #endif
  288. // Apply lighting
  289. half4 color = LuxURPSimpleFuzzFragmentPBR(
  290. inputData,
  291. surfaceData.albedo,
  292. surfaceData.metallic,
  293. surfaceData.specular,
  294. surfaceData.smoothness,
  295. surfaceData.occlusion,
  296. surfaceData.emission,
  297. surfaceData.alpha,
  298. #if defined(_SCATTERING)
  299. half4(surfaceData.translucency * _TranslucencyStrength, _TranslucencyPower, _ShadowStrength, _Distortion),
  300. #else
  301. half4(0,0,0,0),
  302. #endif
  303. surfaceData.fuzzMask, // Fuzzmask
  304. _FuzzPower,
  305. _FuzzBias,
  306. _FuzzWrap,
  307. _FuzzStrength * PI,
  308. _FuzzAmbient
  309. );
  310. // Add fog
  311. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  312. return color;
  313. }
  314. ENDHLSL
  315. }
  316. // Shadows -----------------------------------------------------
  317. Pass
  318. {
  319. Name "ShadowCaster"
  320. Tags{"LightMode" = "ShadowCaster"}
  321. ZWrite On
  322. ZTest LEqual
  323. ColorMask 0
  324. Cull [_Cull]
  325. HLSLPROGRAM
  326. // Required to compile gles 2.0 with standard srp library
  327. #pragma prefer_hlslcc gles
  328. #pragma exclude_renderers d3d11_9x
  329. #pragma target 2.0
  330. // -------------------------------------
  331. // Material Keywords
  332. #pragma shader_feature_local _ALPHATEST_ON // not per fragment
  333. #pragma shader_feature_local _MASKMAP // not per fragment
  334. //--------------------------------------
  335. // GPU Instancing
  336. #pragma multi_compile_instancing
  337. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  338. #pragma vertex ShadowPassVertex
  339. #pragma fragment ShadowPassFragment
  340. // Include base inputs and all other needed "base" includes
  341. #include "Includes/Lux URP Simple Fuzz Inputs.hlsl"
  342. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  343. // Shadow caster specific input
  344. float3 _LightDirection;
  345. VertexOutput ShadowPassVertex(VertexInput input)
  346. {
  347. VertexOutput output = (VertexOutput)0;
  348. UNITY_SETUP_INSTANCE_ID(input);
  349. UNITY_TRANSFER_INSTANCE_ID(input, output);
  350. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  351. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  352. #endif
  353. float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
  354. float3 normalWS = TransformObjectToWorldDir(input.normalOS);
  355. output.positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS * _ShadowOffset, _LightDirection));
  356. #if UNITY_REVERSED_Z
  357. output.positionCS.z = min(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  358. #else
  359. output.positionCS.z = max(output.positionCS.z, output.positionCS.w * UNITY_NEAR_CLIP_VALUE);
  360. #endif
  361. return output;
  362. }
  363. half4 ShadowPassFragment(VertexOutput input) : SV_TARGET
  364. {
  365. UNITY_SETUP_INSTANCE_ID(input);
  366. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  367. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  368. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv).a;
  369. clip (mask - _Cutoff);
  370. #endif
  371. return 0;
  372. }
  373. ENDHLSL
  374. }
  375. // Depth -----------------------------------------------------
  376. Pass
  377. {
  378. Tags{"LightMode" = "DepthOnly"}
  379. ZWrite On
  380. ColorMask 0
  381. Cull [_Cull]
  382. HLSLPROGRAM
  383. // Required to compile gles 2.0 with standard srp library
  384. #pragma prefer_hlslcc gles
  385. #pragma exclude_renderers d3d11_9x
  386. #pragma target 2.0
  387. #pragma vertex DepthOnlyVertex
  388. #pragma fragment DepthOnlyFragment
  389. // -------------------------------------
  390. // Material Keywords
  391. #pragma shader_feature_local _ALPHATEST_ON // not per fragment
  392. #pragma shader_feature_local _MASKMAP // not per fragment
  393. //--------------------------------------
  394. // GPU Instancing
  395. #pragma multi_compile_instancing
  396. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  397. #define DEPTHONLYPASS
  398. #include "Includes/Lux URP Simple Fuzz Inputs.hlsl"
  399. VertexOutput DepthOnlyVertex(VertexInput input)
  400. {
  401. VertexOutput output = (VertexOutput)0;
  402. UNITY_SETUP_INSTANCE_ID(input);
  403. UNITY_TRANSFER_INSTANCE_ID(input, output);
  404. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  405. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  406. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  407. #endif
  408. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  409. return output;
  410. }
  411. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  412. {
  413. UNITY_SETUP_INSTANCE_ID(input);
  414. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  415. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  416. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv.xy).a;
  417. clip (mask - _Cutoff);
  418. #endif
  419. return 0;
  420. }
  421. ENDHLSL
  422. }
  423. // Depth Normal ---------------------------------------------
  424. // This pass is used when drawing to a _CameraNormalsTexture texture
  425. Pass
  426. {
  427. Name "DepthNormals"
  428. Tags{"LightMode" = "DepthNormals"}
  429. ZWrite On
  430. Cull[_Cull]
  431. HLSLPROGRAM
  432. // Required to compile gles 2.0 with standard srp library
  433. #pragma prefer_hlslcc gles
  434. #pragma exclude_renderers d3d11_9x
  435. #pragma target 2.0
  436. #pragma vertex DepthNormalVertex
  437. #pragma fragment DepthNormalFragment
  438. // -------------------------------------
  439. // Material Keywords
  440. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  441. #pragma shader_feature_local _MASKMAP // not per fragment!
  442. //--------------------------------------
  443. // GPU Instancing
  444. #pragma multi_compile_instancing
  445. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  446. #define DEPTHNORMALPASS
  447. #include "Includes/Lux URP Simple Fuzz Inputs.hlsl"
  448. VertexOutput DepthNormalVertex(VertexInput input)
  449. {
  450. VertexOutput output = (VertexOutput)0;
  451. UNITY_SETUP_INSTANCE_ID(input);
  452. UNITY_TRANSFER_INSTANCE_ID(input, output);
  453. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  454. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  455. output.uv.xy = TRANSFORM_TEX(input.texcoord, _MaskMap);
  456. #endif
  457. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  458. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, float4(1,1,1,1)); //input.tangentOS);
  459. output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);
  460. return output;
  461. }
  462. half4 DepthNormalFragment(VertexOutput input) : SV_TARGET
  463. {
  464. UNITY_SETUP_INSTANCE_ID(input);
  465. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  466. #if defined(_ALPHATEST_ON) && defined(_MASKMAP)
  467. half mask = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, input.uv.xy).a;
  468. clip (mask - _Cutoff);
  469. #endif
  470. float3 normal = input.normalWS;
  471. return float4(PackNormalOctRectEncode(TransformWorldToViewDir(normal, true)), 0.0, 0.0);
  472. }
  473. ENDHLSL
  474. }
  475. // Meta -----------------------------------------------------
  476. Pass
  477. {
  478. Tags{"LightMode" = "Meta"}
  479. Cull Off
  480. HLSLPROGRAM
  481. // Required to compile gles 2.0 with standard srp library
  482. #pragma prefer_hlslcc gles
  483. #pragma vertex UniversalVertexMeta
  484. #pragma fragment UniversalFragmentMeta
  485. #define _SPECULAR_SETUP
  486. // First include all our custom stuff
  487. #include "Includes/Lux URP Simple Fuzz Inputs.hlsl"
  488. //--------------------------------------
  489. // Fragment shader and functions
  490. inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  491. {
  492. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  493. outSurfaceData.alpha = 1;
  494. outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
  495. outSurfaceData.metallic = 0;
  496. outSurfaceData.specular = _SpecColor.rgb;
  497. outSurfaceData.smoothness = _Smoothness;
  498. outSurfaceData.normalTS = half3(0,0,1);
  499. outSurfaceData.occlusion = 1;
  500. outSurfaceData.emission = 0;
  501. outSurfaceData.clearCoatMask = 0;
  502. outSurfaceData.clearCoatSmoothness = 0;
  503. }
  504. // Finally include the meta pass related stuff
  505. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
  506. ENDHLSL
  507. }
  508. // End Passes -----------------------------------------------------
  509. }
  510. FallBack "Hidden/InternalErrorShader"
  511. CustomEditor "LuxURPUniversalCustomShaderGUI"
  512. }