Lux URP Flat Shaded Inputs.hlsl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef INPUT_LUXLWRP_BASE_INCLUDED
  2. #define INPUT_LUXLWRP_BASE_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. // defines a bunch of helper functions (like lerpwhiteto)
  5. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
  6. // defines SurfaceData, textures and the functions Alpha, SampleAlbedoAlpha, SampleNormal, SampleEmission
  7. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
  8. // defines e.g. "DECLARE_LIGHTMAP_OR_SH"
  9. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  10. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  11. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
  12. // Material Inputs
  13. CBUFFER_START(UnityPerMaterial)
  14. half4 _BaseColor;
  15. half _Cutoff;
  16. float4 _BaseMap_ST;
  17. half _Smoothness;
  18. half4 _SpecColor;
  19. half _BumpScale;
  20. half4 _RimColor;
  21. half _RimPower;
  22. half _RimMinPower;
  23. half _RimFrequency;
  24. half _RimPerPositionFrequency;
  25. CBUFFER_END
  26. // Additional textures
  27. #if defined(_MASKMAP)
  28. TEXTURE2D(_MaskMap); SAMPLER(sampler_MaskMap);
  29. #endif
  30. // Global Inputs
  31. // Structs
  32. struct VertexInput
  33. {
  34. float3 positionOS : POSITION;
  35. float3 normalOS : NORMAL;
  36. float4 tangentOS : TANGENT;
  37. float2 texcoord : TEXCOORD0;
  38. float2 lightmapUV : TEXCOORD1;
  39. half4 color : COLOR;
  40. UNITY_VERTEX_INPUT_INSTANCE_ID
  41. };
  42. struct VertexOutput
  43. {
  44. float4 positionCS : SV_POSITION;
  45. float2 uv : TEXCOORD0;
  46. #if defined(DEPTHNORMALONLYPASS)
  47. float3 normalWS : TEXCOORD4;
  48. #endif
  49. #if !defined(UNITY_PASS_SHADOWCASTER) && !defined(DEPTHONLYPASS)
  50. DECLARE_LIGHTMAP_OR_SH(lightmapUV, vertexSH, 1);
  51. float3 positionWS : TEXCOORD2;
  52. float3 viewDirWS : TEXCOORD3;
  53. #if defined(_NORMALMAP)
  54. //float3 normalWS : TEXCOORD4;
  55. float4 tangentWS : TEXCOORD5;
  56. #endif
  57. half4 fogFactorAndVertexLight : TEXCOORD6;
  58. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  59. float4 shadowCoord : TEXCOORD7;
  60. #endif
  61. #endif
  62. UNITY_VERTEX_INPUT_INSTANCE_ID
  63. UNITY_VERTEX_OUTPUT_STEREO
  64. };
  65. struct SurfaceDescription
  66. {
  67. half3 albedo;
  68. half alpha;
  69. half3 normalTS;
  70. half3 emission;
  71. half metallic;
  72. half3 specular;
  73. half smoothness;
  74. half occlusion;
  75. };
  76. // flat PBR lighting
  77. half4 LuxURPFlatFragmentPBR(InputData inputData, half3 albedo, half metallic, half3 specular,
  78. half smoothness, half occlusion, half3 emission, half alpha)
  79. {
  80. #ifdef _SPECULARHIGHLIGHTS_OFF
  81. bool specularHighlightsOff = true;
  82. #else
  83. bool specularHighlightsOff = false;
  84. #endif
  85. BRDFData brdfData;
  86. // NOTE: can modify alpha
  87. InitializeBRDFData(albedo, metallic, specular, smoothness, alpha, brdfData);
  88. BRDFData brdfDataClearCoat = (BRDFData)0;
  89. #if defined(_CLEARCOAT) || defined(_CLEARCOATMAP)
  90. // base brdfData is modified here, rely on the compiler to eliminate dead computation by InitializeBRDFData()
  91. // InitializeBRDFDataClearCoat(surfaceData.clearCoatMask, surfaceData.clearCoatSmoothness, brdfData, brdfDataClearCoat);
  92. #endif
  93. // To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders
  94. #if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
  95. half4 shadowMask = inputData.shadowMask;
  96. #elif !defined (LIGHTMAP_ON)
  97. half4 shadowMask = unity_ProbesOcclusion;
  98. #else
  99. half4 shadowMask = half4(1, 1, 1, 1);
  100. #endif
  101. Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, shadowMask);
  102. #if defined(_SCREEN_SPACE_OCCLUSION) && defined(_SSAO_ENABLED)
  103. AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(inputData.normalizedScreenSpaceUV);
  104. mainLight.color *= aoFactor.directAmbientOcclusion;
  105. occlusion = min(occlusion, aoFactor.indirectAmbientOcclusion);
  106. #endif
  107. MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI);
  108. half3 color = GlobalIllumination(brdfData, brdfDataClearCoat, 0,
  109. inputData.bakedGI, occlusion,
  110. inputData.normalWS, inputData.viewDirectionWS);
  111. color += LightingPhysicallyBased(brdfData, brdfDataClearCoat,
  112. mainLight,
  113. inputData.normalWS, inputData.viewDirectionWS,
  114. 0, specularHighlightsOff);
  115. #ifdef _ADDITIONAL_LIGHTS
  116. uint pixelLightCount = GetAdditionalLightsCount();
  117. for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
  118. {
  119. Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);
  120. #if defined(_SCREEN_SPACE_OCCLUSION) && defined(_SSAO_ENABLED)
  121. light.color *= aoFactor.directAmbientOcclusion;
  122. #endif
  123. color += LightingPhysicallyBased(brdfData, brdfDataClearCoat,
  124. light,
  125. inputData.normalWS, inputData.viewDirectionWS,
  126. 0, specularHighlightsOff);
  127. }
  128. #endif
  129. #ifdef _ADDITIONAL_LIGHTS_VERTEX
  130. color += inputData.vertexLighting * brdfData.diffuse;
  131. #endif
  132. color += emission;
  133. return half4(color, alpha);
  134. }
  135. #endif