Lux URP Tree Creator Bark.shader 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. Shader "Lux URP/Nature/Tree Creator Bark"
  2. {
  3. Properties
  4. {
  5. _Color ("Main Color", Color) = (1,1,1,1)
  6. [PowerSlider(5.0)]
  7. _Shininess ("Shininess", Range (0.01, 1)) = 0.078125
  8. _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
  9. [NoScaleOffset]
  10. _BumpMap ("Normalmap", 2D) = "bump" {}
  11. [NoScaleOffset]
  12. _GlossMap ("Gloss (A)", 2D) = "black" {}
  13. [HideInInspector] _TreeInstanceColor ("TreeInstanceColor", Vector) = (1,1,1,1)
  14. [HideInInspector] _TreeInstanceScale ("TreeInstanceScale", Vector) = (1,1,1,1)
  15. [HideInInspector] _SquashAmount ("Squash", Float) = 1
  16. // Lightmapper and outline selection shader need _MainTex, _Color and _Cutoff
  17. }
  18. SubShader
  19. {
  20. Tags
  21. {
  22. "RenderPipeline" = "UniversalPipeline"
  23. "RenderType" = "Opaque"
  24. "Queue" = "Geometry"
  25. }
  26. LOD 100
  27. Pass
  28. {
  29. Name "ForwardLit"
  30. Tags{"LightMode" = "UniversalForward"}
  31. ZWrite On
  32. Cull Back
  33. HLSLPROGRAM
  34. // Required to compile gles 2.0 with standard SRP library
  35. #pragma prefer_hlslcc gles
  36. #pragma exclude_renderers d3d11_9x
  37. // Shader target needs to be 3.0 due to tex2Dlod in the vertex shader and VFACE
  38. #pragma target 2.0
  39. // -------------------------------------
  40. // Material Keywords
  41. // #define _SPECULAR_SETUP 1
  42. //#pragma shader_feature _NORMALMAP
  43. #define DUMMYSHADER
  44. #define _NORMALMAP
  45. // -------------------------------------
  46. // Lightweight Pipeline keywords
  47. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  48. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  49. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  50. #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  51. #pragma multi_compile _ _SHADOWS_SOFT
  52. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  53. // -------------------------------------
  54. // Unity defined keywords
  55. // #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  56. // #pragma multi_compile _ LIGHTMAP_ON
  57. #pragma multi_compile_fog
  58. // Include base inputs and all other needed "base" includes
  59. #include "Includes/Lux URP Tree Creator Inputs.hlsl"
  60. #include "Includes/Lux URP Tree Creator Library.hlsl"
  61. #pragma vertex LitPassVertex
  62. #pragma fragment LitPassFragment
  63. //--------------------------------------
  64. // Vertex shader
  65. VertexOutput LitPassVertex(VertexInput input)
  66. {
  67. VertexOutput output = (VertexOutput)0;
  68. UNITY_SETUP_INSTANCE_ID(input);
  69. UNITY_TRANSFER_INSTANCE_ID(input, output);
  70. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  71. VertexPositionInputs vertexInput; //
  72. vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  73. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  74. half3 viewDirWS = GetCameraPositionWS() - vertexInput.positionWS;
  75. half3 vertexLight = VertexLighting(vertexInput.positionWS, normalInput.normalWS);
  76. half fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
  77. output.uv = TRANSFORM_TEX(input.texcoord, _MainTex);
  78. output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
  79. output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
  80. output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
  81. OUTPUT_LIGHTMAP_UV(input.lightmapUV, unity_LightmapST, output.lightmapUV);
  82. OUTPUT_SH(output.normalWS.xyz, output.vertexSH);
  83. output.fogFactorAndVertexLight = half4(fogFactor, vertexLight);
  84. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  85. output.positionWS = vertexInput.positionWS;
  86. #endif
  87. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  88. output.shadowCoord = GetShadowCoord(vertexInput);
  89. #endif
  90. output.positionCS = vertexInput.positionCS;
  91. output.color = input.color;
  92. return output;
  93. }
  94. //--------------------------------------
  95. // Fragment shader and functions
  96. inline void InitializeSurfaceData(
  97. float2 uv,
  98. out SurfaceDescription outSurfaceData)
  99. {
  100. half4 albedoAlpha = SampleAlbedoAlpha(uv.xy, TEXTURE2D_ARGS(_MainTex, sampler_MainTex));
  101. outSurfaceData.alpha = 1;
  102. outSurfaceData.albedo = albedoAlpha.rgb; // * _Color.rgb;
  103. // Normal
  104. outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap), 1);
  105. outSurfaceData.specular = _Shininess;
  106. outSurfaceData.occlusion = 1;
  107. outSurfaceData.translucency = 0;
  108. // Transmission
  109. half4 maskSample = SAMPLE_TEXTURE2D(_TranslucencyMap, sampler_TranslucencyMap, uv);
  110. outSurfaceData.translucency *= maskSample.b;
  111. //outSurfaceData.occlusion = lerp(1.0h, maskSample.b, _Occlusion);
  112. //outSurfaceData.mask = maskSample.r;
  113. outSurfaceData.gloss = maskSample.a;
  114. }
  115. void InitializeInputData(VertexOutput input, half3 normalTS, out InputData inputData)
  116. {
  117. inputData = (InputData)0;
  118. #if defined(REQUIRES_WORLD_SPACE_POS_INTERPOLATOR)
  119. inputData.positionWS = input.positionWS;
  120. #endif
  121. half3 viewDirWS = half3(input.normalWS.w, input.tangentWS.w, input.bitangentWS.w);
  122. inputData.normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  123. inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
  124. viewDirWS = SafeNormalize(viewDirWS);
  125. inputData.viewDirectionWS = viewDirWS;
  126. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  127. inputData.shadowCoord = input.shadowCoord;
  128. #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  129. inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
  130. #else
  131. inputData.shadowCoord = float4(0, 0, 0, 0);
  132. #endif
  133. inputData.fogCoord = input.fogFactorAndVertexLight.x;
  134. inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
  135. inputData.bakedGI = SAMPLE_GI(input.lightmapUV, input.vertexSH, inputData.normalWS);
  136. }
  137. half4 LitPassFragment(VertexOutput input) : SV_Target
  138. {
  139. UNITY_SETUP_INSTANCE_ID(input);
  140. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  141. // Get the surface description
  142. SurfaceDescription surfaceData;
  143. InitializeSurfaceData(input.uv, surfaceData);
  144. // Apply tree color
  145. surfaceData.albedo *= input.color.rgb;
  146. surfaceData.occlusion = input.color.a;
  147. // Prepare surface data (like bring normal into world space and get missing inputs like gi)
  148. InputData inputData;
  149. InitializeInputData(input, surfaceData.normalTS, inputData);
  150. // Apply lighting
  151. half4 color = LuxURPTreeBarkFragment (
  152. inputData,
  153. surfaceData.albedo,
  154. surfaceData.specular,
  155. surfaceData.gloss,
  156. surfaceData.occlusion,
  157. surfaceData.alpha,
  158. UNITY_ACCESS_INSTANCED_PROP(Props, _SquashAmount)
  159. );
  160. // Add fog
  161. color.rgb = MixFog(color.rgb, inputData.fogCoord);
  162. return color;
  163. }
  164. ENDHLSL
  165. }
  166. // End Passes -----------------------------------------------------
  167. }
  168. FallBack "Hidden/InternalErrorShader"
  169. Dependency "OptimizedShader" = "Lux URP/Nature/Tree Creator Bark Optimized"
  170. }