Lux URP Lit Decal.shader 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. Shader "Lux URP/Projection/Decal Lit"
  2. {
  3. Properties
  4. {
  5. [HeaderHelpLuxURP_URL(skzrp97i0tvt)]
  6. [Header(Surface Options)]
  7. [Space(8)]
  8. [ToggleOff(_RECEIVE_SHADOWS_OFF)]
  9. _ReceiveShadows ("Receive Shadows", Float) = 1.0
  10. [Toggle(ORTHO_SUPPORT)]
  11. _OrthoSpport ("Enable Orthographic Support", Float) = 0
  12. [Toggle(HQ_SAMPLING)]
  13. _HQSampling ("Enable HQ Sampling", Float) = 0
  14. [Toggle(NORMALS_SAMPLING)]
  15. _NormalBuffer ("Enable Normal Buffer (SSAO)", Float) = 0
  16. [Header(Surface Inputs)]
  17. [Space(8)]
  18. [HDR]_Color ("Color", Color) = (1,1,1,1)
  19. [NoScaleOffset] _BaseMap ("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  20. _Smoothness ("Smoothness", Range (0, 1)) = 0.1
  21. _SpecColor ("Specular", Color) = (0.2, 0.2, 0.2)
  22. [Space(10)]
  23. [Toggle(_DECALNORMAL)] _DecalNormal ("Blend with Decal Normal", Float) = 0.0
  24. _DecalNormalStrength (" Decal Normal Strength", Range(0, 1)) = 0.5
  25. [Space(10)]
  26. [Toggle(_NORMALMAP)] _ApplyNormal ("Enable Normal Map", Float) = 1.0
  27. [NoScaleOffset] _BumpMap (" Normal Map", 2D) = "bump" {}
  28. _BumpScale (" Normal Scale", Float) = 1.0
  29. [Header(Mask Map)]
  30. [Space(8)]
  31. [Toggle(_COMBINEDTEXTURE)] _CombinedTexture ("Enable Mask Map", Float) = 0.0
  32. [NoScaleOffset] _MaskMap (" Metallness (R) Occlusion (G) Emission (B) Smoothness (A) ", 2D) = "bump" {}
  33. [HDR]_EmissionColor (" Emission Color", Color) = (0,0,0,0)
  34. _Occlusion (" Occlusion", Range(0.0, 1.0)) = 1.0
  35. [Header(Distance Fading)]
  36. [Space(8)]
  37. [LuxURPDistanceFadeDrawer]
  38. _DistanceFade ("Distance Fade Params", Vector) = (2500, 0.001, 0, 0)
  39. [Header(Stencil)]
  40. [Space(8)]
  41. [IntRange] _StencilRef ("Stencil Reference", Range (0, 255)) = 0
  42. [IntRange] _ReadMask (" Read Mask", Range (0, 255)) = 255
  43. [IntRange] _WriteMask (" Write Mask", Range (0, 255)) = 255
  44. [Enum(UnityEngine.Rendering.CompareFunction)]
  45. _StencilCompare ("Stencil Comparison", Int) = 8 // always
  46. [Header(Advanced)]
  47. [Space(8)]
  48. [ToggleOff]
  49. _SpecularHighlights ("Enable Specular Highlights", Float) = 1.0
  50. [ToggleOff]
  51. _EnvironmentReflections ("Environment Reflections", Float) = 1.0
  52. }
  53. SubShader
  54. {
  55. Tags
  56. {
  57. "RenderPipeline" = "UniversalPipeline"
  58. "RenderType" = "Opaque"
  59. "Queue" = "Transparent" // +59 smalltest to get drawn on top of transparents
  60. }
  61. Pass
  62. {
  63. Name "ForwardLit"
  64. Tags{"LightMode" = "UniversalForward"}
  65. Stencil {
  66. Ref [_StencilRef]
  67. ReadMask [_ReadMask]
  68. WriteMask [_WriteMask]
  69. Comp [_StencilCompare]
  70. }
  71. Blend SrcAlpha OneMinusSrcAlpha
  72. // We draw backfaces to prevent clipping
  73. Cull Front
  74. // So we have to set ZTest to always
  75. ZTest Always
  76. // It is a decal!
  77. ZWrite Off
  78. HLSLPROGRAM
  79. // Required to compile gles 2.0 with standard srp library
  80. #pragma prefer_hlslcc gles
  81. #pragma exclude_renderers d3d11_9x
  82. #pragma target 2.0
  83. // -------------------------------------
  84. // Material Keywords
  85. // _NORMALMAP must NOT be shader_feature_local – otherwise fade fails?! Na, it just fails. Toggling "Mask Map" may help bringing back the decal.
  86. #pragma shader_feature _NORMALMAP
  87. #pragma shader_feature_local _COMBINEDTEXTURE
  88. #pragma shader_feature_local _DECALNORMAL
  89. #pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
  90. #pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
  91. #pragma shader_feature_local _RECEIVE_SHADOWS_OFF
  92. #pragma shader_feature_local ORTHO_SUPPORT
  93. #pragma shader_feature_local_fragment HQ_SAMPLING
  94. #pragma multi_compile_fragment _ NORMALS_SAMPLING
  95. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  96. #define _SPECULAR_SETUP 1
  97. // -------------------------------------
  98. // Universal Pipeline keywords
  99. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  100. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  101. // #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  102. #pragma multi_compile _ _ADDITIONAL_LIGHTS
  103. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  104. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  105. // -------------------------------------
  106. // Unity defined keywords
  107. #pragma multi_compile_fog
  108. //--------------------------------------
  109. // GPU Instancing
  110. #pragma multi_compile_instancing
  111. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  112. #pragma vertex vert
  113. #pragma fragment frag
  114. // Lighting include is needed because of GI
  115. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  116. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  117. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  118. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  119. CBUFFER_START(UnityPerMaterial)
  120. // Latest notes from Uty: do not if else here.
  121. half4 _Color;
  122. half _Smoothness;
  123. half4 _SpecColor;
  124. float2 _DistanceFade;
  125. //#if defined(_NORMALMAP)
  126. half _BumpScale;
  127. //#endif
  128. //#if defined(_COMBINEDTEXTURE)
  129. half4 _EmissionColor;
  130. half _Occlusion;
  131. //#endif
  132. //#if defined(_DECALNORMAL)
  133. half _DecalNormalStrength;
  134. //#endif
  135. float4 _BaseMap_TexelSize;
  136. CBUFFER_END
  137. #if defined(SHADER_API_GLES)
  138. TEXTURE2D(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture);
  139. #else
  140. TEXTURE2D_X_FLOAT(_CameraDepthTexture);
  141. #endif
  142. float4 _CameraDepthTexture_TexelSize;
  143. #if defined(_COMBINEDTEXTURE)
  144. TEXTURE2D(_MaskMap); SAMPLER(sampler_MaskMap);
  145. #endif
  146. #if defined(NORMALS_SAMPLING)
  147. TEXTURE2D_X_FLOAT(_CameraNormalsTexture);
  148. #endif
  149. struct VertexInput
  150. {
  151. float4 vertex : POSITION;
  152. float3 normal : NORMAL;
  153. UNITY_VERTEX_INPUT_INSTANCE_ID
  154. };
  155. struct VertexOutput
  156. {
  157. float4 positionCS : SV_POSITION;
  158. UNITY_VERTEX_INPUT_INSTANCE_ID
  159. UNITY_VERTEX_OUTPUT_STEREO
  160. float4 viewRayOS : TEXCOORD0;
  161. float3 camPosOS : TEXCOORD1;
  162. float4 screenUV : TEXCOORD2;
  163. float fogCoord : TEXCOORD3;
  164. #if defined(_NORMALMAP) || defined(_DECALNORMAL)
  165. half3 normalWS : TEXCOORD4;
  166. #endif
  167. #if defined(_NORMALMAP)
  168. half3 tangentWS : TEXCOORD5;
  169. half3 bitangentWS : TEXCOORD6;
  170. #endif
  171. half fade : TEXCOORD7;
  172. };
  173. VertexOutput vert (VertexInput v)
  174. {
  175. VertexOutput output = (VertexOutput)0;
  176. UNITY_SETUP_INSTANCE_ID(v);
  177. UNITY_TRANSFER_INSTANCE_ID(v, output);
  178. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  179. output.positionCS = TransformObjectToHClip(v.vertex.xyz);
  180. // We do all calculations in Object Space
  181. float4 positionVS = mul(UNITY_MATRIX_V, mul(UNITY_MATRIX_M, v.vertex)); //mul(UNITY_MATRIX_MV, v.vertex);
  182. float3 viewRayVS = positionVS.xyz;
  183. // positionVS.z here acts as view space to object space ratio (negative)
  184. output.viewRayOS.w = positionVS.z;
  185. // NOTE: Fix direction of the viewRay
  186. float4x4 ViewToObjectMatrix = mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V);
  187. output.viewRayOS.xyz = mul((float3x3)ViewToObjectMatrix, -viewRayVS).xyz;
  188. output.camPosOS = ViewToObjectMatrix._m03_m13_m23;
  189. // Get the screen uvs needed to sample the depth texture
  190. output.screenUV = ComputeScreenPos(output.positionCS);
  191. output.fogCoord = ComputeFogFactor(output.positionCS.z);
  192. // Set distance fade value
  193. float3 worldInstancePos = UNITY_MATRIX_M._m03_m13_m23;
  194. float3 diff = (_WorldSpaceCameraPos - worldInstancePos);
  195. float dist = dot(diff, diff);
  196. output.fade = saturate( (_DistanceFade.x - dist) * _DistanceFade.y );
  197. #if defined(_NORMALMAP) || defined(_DECALNORMAL)
  198. output.normalWS = TransformObjectToWorldNormal(half3(0.0h, 1.0h, 0.0h));
  199. #endif
  200. #if defined(_NORMALMAP)
  201. output.tangentWS = TransformObjectToWorldDir(half3(1.0h, 0.0h, 0.0h));
  202. half tangentSign = (-1.0) * unity_WorldTransformParams.w;
  203. output.bitangentWS = cross(output.normalWS, output.tangentWS) * tangentSign;
  204. #endif
  205. return output;
  206. }
  207. // https://www.gamedev.net/forums/topic/678043-how-to-blend-world-space-normals/
  208. // same as in: ScriptableRenderPipeline/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl
  209. half3 ReorientNormalInWorldSpace(in half3 u, in half3 t, in half3 s) {
  210. // Build the shortest-arc quaternion
  211. half dotSTplusOne = dot(s, t) + 1.0h;
  212. half4 q = half4(cross(s, t), dotSTplusOne ) / sqrt(2.0h * ( dotSTplusOne ));
  213. // Rotate the normal
  214. return u * (q.w * q.w - dot(q.xyz, q.xyz)) + 2.0h * q.xyz * dot(q.xyz, u) + 2.0h * q.w * cross(q.xyz, u);
  215. }
  216. #define oneMinusDielectricSpecConst half(1.0 - 0.04)
  217. // HQ decal sampling from: http://www.humus.name/index.php?page=3D&ID=84
  218. // Decal MipmapLevel to avoid the 2x2 pixels artefacts on the edges where the decal is projected to.
  219. float2 ComputeDecalDDX(VertexOutput input, float2 uv, float2 decalUV) {
  220. float2 ScreenDeltaX = float2(1, 0);
  221. float depth0 = LOAD_TEXTURE2D_X(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * uv - ScreenDeltaX).x;
  222. depth0 = LinearEyeDepth(depth0, _ZBufferParams);
  223. float depth1 = LOAD_TEXTURE2D_X(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * uv + ScreenDeltaX).x;
  224. depth1 = LinearEyeDepth(depth1, _ZBufferParams);
  225. float2 UvDiffX0 = decalUV - ((input.camPosOS + input.viewRayOS.xyz * depth0).xz + float2(0.5, 0.5));
  226. float2 UvDiffX1 = ((input.camPosOS + input.viewRayOS.xyz * depth1).xz + float2(0.5, 0.5)) - decalUV;
  227. return dot(UvDiffX0, UvDiffX0) < dot(UvDiffX1, UvDiffX1) ? UvDiffX0 : UvDiffX1;
  228. }
  229. float2 ComputeDecalDDY(VertexOutput input, float2 uv, float2 decalUV) {
  230. float2 ScreenDeltaY = float2(0, 1);
  231. float depth0 = LOAD_TEXTURE2D_X(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * uv - ScreenDeltaY).x;
  232. depth0 = LinearEyeDepth(depth0, _ZBufferParams);
  233. float depth1 = LOAD_TEXTURE2D_X(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * uv + ScreenDeltaY).x;
  234. depth1 = LinearEyeDepth(depth1, _ZBufferParams);
  235. float2 UvDiffY0 = decalUV - ((input.camPosOS + input.viewRayOS.xyz * depth0).xz + float2(0.5, 0.5));
  236. float2 UvDiffY1 = ((input.camPosOS + input.viewRayOS.xyz * depth1).xz + float2(0.5, 0.5)) - decalUV;
  237. return dot(UvDiffY0, UvDiffY0) < dot(UvDiffY1, UvDiffY1) ? UvDiffY0 : UvDiffY1;
  238. }
  239. // HQ decal sampling END
  240. half4 frag (VertexOutput input ) : SV_Target
  241. {
  242. UNITY_SETUP_INSTANCE_ID(input);
  243. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  244. input.viewRayOS.xyz *= rcp(input.viewRayOS.w); // precision problem? calculating 1.0 / w in vertex shader.
  245. float2 uv = input.screenUV.xy / input.screenUV.w;
  246. // Fix screenUV for Single Pass Stereo Rendering
  247. #if defined(UNITY_SINGLE_PASS_STEREO)
  248. uv.x = uv.x * 0.5f + (float)unity_StereoEyeIndex * 0.5f;
  249. #endif
  250. #if defined(SHADER_API_GLES)
  251. float rawDepth = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, uv, 0);
  252. #else
  253. float rawDepth = LOAD_TEXTURE2D_X(_CameraDepthTexture, _CameraDepthTexture_TexelSize.zw * uv).x;
  254. #endif
  255. float3 positionOS;
  256. float3 positionWS;
  257. // Get Position in Object Space
  258. #if defined(ORTHO_SUPPORT)
  259. UNITY_BRANCH
  260. if(unity_OrthoParams.w == 1) {
  261. float depthOrtho = rawDepth;
  262. #if defined(UNITY_REVERSED_Z)
  263. // Needed to handle openGL
  264. #if UNITY_REVERSED_Z == 1
  265. depthOrtho = 1.0f - depthOrtho;
  266. #endif
  267. #endif
  268. // Get ortho Depth
  269. // Old code, works with HDRP10.1 again... crazy
  270. depthOrtho = lerp(_ProjectionParams.y, _ProjectionParams.z, depthOrtho);
  271. float2 rayOrtho = -float2( unity_OrthoParams.xy * ( input.screenUV.xy - 0.5) * 2 /* to clip space */);
  272. float4 vposOrtho = float4(rayOrtho, -depthOrtho, 1);
  273. float3 wposOrtho = mul(unity_CameraToWorld, vposOrtho).xyz;
  274. wposOrtho -= _WorldSpaceCameraPos * 2; // TODO: Why * 2 ????
  275. wposOrtho *= -1;
  276. float3 positionOrthoOS = mul( GetWorldToObjectMatrix(), float4(wposOrtho, 1)).xyz;
  277. // depthOrtho = lerp(_ProjectionParams.y, _ProjectionParams.z, depthOrtho);
  278. // float2 rayOrtho = float2( unity_OrthoParams.xy * ( input.screenUV.xy - 0.5) * 2 /* to clip space */);
  279. // float4 vposOrtho = float4(rayOrtho, -depthOrtho, 1);
  280. // float3 wposOrtho = mul(unity_CameraToWorld, vposOrtho).xyz;
  281. // float3 positionOrthoOS = mul( GetWorldToObjectMatrix(), float4(wposOrtho, 1)).xyz;
  282. positionOS = positionOrthoOS;
  283. positionWS = wposOrtho;
  284. }
  285. else {
  286. // Get perspective Depth
  287. float depth = LinearEyeDepth(rawDepth, _ZBufferParams);
  288. // Position in Object Space
  289. positionOS = input.camPosOS + input.viewRayOS.xyz * depth;
  290. positionWS = mul(GetObjectToWorldMatrix(), float4(positionOS, 1)).xyz;
  291. }
  292. #else
  293. // Get perspective Depth
  294. float depth = LinearEyeDepth(rawDepth, _ZBufferParams);
  295. // Position in Object Space
  296. positionOS = input.camPosOS + input.viewRayOS.xyz * depth;
  297. positionWS = mul(GetObjectToWorldMatrix(), float4(positionOS, 1)).xyz;
  298. #endif
  299. // Clip decal to volume
  300. clip(float3(0.5, 0.5, 0.5) - abs(positionOS.xyz));
  301. float2 texUV = positionOS.xz + float2(0.5, 0.5);
  302. // HQ Decal Sampling
  303. #if defined(HQ_SAMPLING) && !defined(ORTHO_SUPPORT)
  304. float2 UvPixelDiffX = ComputeDecalDDX(input, uv, texUV) * _BaseMap_TexelSize.zw;
  305. float2 UvPixelDiffY = ComputeDecalDDY(input, uv, texUV) * _BaseMap_TexelSize.zw;
  306. float MaxDiff = max(dot(UvPixelDiffX, UvPixelDiffX), dot(UvPixelDiffY, UvPixelDiffY));
  307. float Mip = 0.5 * log2(MaxDiff);
  308. half4 col = SAMPLE_TEXTURE2D_LOD(_BaseMap, sampler_BaseMap, texUV, Mip) * _Color;
  309. #else
  310. half4 col = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, texUV) * _Color;
  311. #endif
  312. // Distance Fade
  313. #if defined(ORTHO_SUPPORT)
  314. half alpha = col.a * ((unity_OrthoParams.w == 1.0h) ? 1.0h : input.fade);
  315. #else
  316. half alpha = col.a * input.fade;
  317. #endif
  318. #if defined(_COMBINEDTEXTURE)
  319. #if defined(HQ_SAMPLING) && !defined(ORTHO_SUPPORT)
  320. half4 combinedTextureSample = SAMPLE_TEXTURE2D_LOD(_MaskMap, sampler_MaskMap, texUV, Mip);
  321. #else
  322. half4 combinedTextureSample = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, texUV);
  323. #endif
  324. half3 specular = lerp(_SpecColor.rgb, col.rgb, combinedTextureSample.rrr);
  325. // Remap albedo
  326. col.rgb *= oneMinusDielectricSpecConst - combinedTextureSample.rrr * oneMinusDielectricSpecConst;
  327. half smoothness = combinedTextureSample.a;
  328. half occlusion = lerp(1.0h, combinedTextureSample.g, _Occlusion);
  329. half3 emission = _EmissionColor.rgb * combinedTextureSample.b;
  330. #else
  331. half3 specular = _SpecColor.rgb;
  332. half smoothness = _Smoothness;
  333. half occlusion = 1.0h;
  334. half3 emission = 0;
  335. #endif
  336. // Prepare inputs for the lighting function and get normals
  337. // I hat this ZERO initialize - but it is just the quicket way here
  338. InputData inputData = (InputData)0;
  339. inputData.positionWS = positionWS;
  340. // SSAO
  341. #if defined(_SCREEN_SPACE_OCCLUSION)
  342. inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
  343. #endif
  344. // Normals
  345. #if defined(NORMALS_SAMPLING) && defined(_SCREEN_SPACE_OCCLUSION)
  346. // view space normal!
  347. float2 nSample = LOAD_TEXTURE2D_X(_CameraNormalsTexture, _CameraDepthTexture_TexelSize.zw * uv).rg;
  348. inputData.normalWS = UnpackNormalOctRectEncode(nSample.rg);
  349. inputData.normalWS = mul((float3x3)UNITY_MATRIX_I_V, inputData.normalWS );
  350. #else
  351. // As ddx and ddy may return super small values we have to normalize on platforms where half actually means something
  352. #if defined (SHADER_API_MOBILE) || defined (SHADER_API_SWITCH)
  353. inputData.normalWS = normalize( cross( ddy(positionWS), ddx(positionWS) ) );
  354. #else
  355. #if defined(_DECALNORMAL)
  356. // In case we blend we have to normalize first as well.
  357. inputData.normalWS = normalize( cross( ddy(positionWS), ddx(positionWS) ) );
  358. #else
  359. inputData.normalWS = cross( ddy(positionWS), ddx(positionWS) );
  360. #endif
  361. #endif
  362. #if defined(_DECALNORMAL)
  363. inputData.normalWS = (lerp(inputData.normalWS, input.normalWS.xyz, _DecalNormalStrength));
  364. #endif
  365. #endif
  366. #if defined(_NORMALMAP)
  367. #if defined(HQ_SAMPLING) && !defined(ORTHO_SUPPORT)
  368. half4 normalSample = SAMPLE_TEXTURE2D_LOD(_BumpMap, sampler_BumpMap, texUV, Mip);
  369. #else
  370. half4 normalSample = SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, texUV);
  371. #endif
  372. #if BUMP_SCALE_NOT_SUPPORTED
  373. half3 normalTS = UnpackNormal(normalSample);
  374. #else
  375. half3 normalTS = UnpackNormalScale(normalSample, _BumpScale);
  376. #endif
  377. half3 normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  378. inputData.normalWS = ReorientNormalInWorldSpace(inputData.normalWS, normalWS, input.normalWS.xyz);
  379. #endif
  380. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  381. inputData.viewDirectionWS = SafeNormalize( _WorldSpaceCameraPos - positionWS);
  382. inputData.shadowCoord = TransformWorldToShadowCoord(positionWS); //vertexInput.positionWS);
  383. inputData.fogCoord = 0;
  384. // We can't calculate per vertex lighting
  385. inputData.vertexLighting = 0;
  386. // So we have to sample SH fully per pixel
  387. inputData.bakedGI = SampleSH(inputData.normalWS);
  388. col = LightweightFragmentPBR(
  389. inputData,
  390. col.rgb,
  391. 0, //surfaceData.metallic,
  392. specular,
  393. smoothness,
  394. occlusion,
  395. emission,
  396. alpha);
  397. col.rgb = MixFog(col.rgb, input.fogCoord);
  398. return half4(col.rgb, alpha);
  399. }
  400. ENDHLSL
  401. }
  402. }
  403. FallBack "Hidden/InternalErrorShader"
  404. CustomEditor "LuxURPUniversalCustomShaderGUI"
  405. }