SimpleLitInput.hlsl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef UNIVERSAL_SIMPLE_LIT_INPUT_INCLUDED
  2. #define UNIVERSAL_SIMPLE_LIT_INPUT_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
  5. CBUFFER_START(UnityPerMaterial)
  6. float4 _BaseMap_ST;
  7. half4 _BaseColor;
  8. half4 _SpecColor;
  9. half4 _EmissionColor;
  10. half _Cutoff;
  11. half _Surface;
  12. CBUFFER_END
  13. #ifdef UNITY_DOTS_INSTANCING_ENABLED
  14. UNITY_DOTS_INSTANCING_START(MaterialPropertyMetadata)
  15. UNITY_DOTS_INSTANCED_PROP(float4, _BaseColor)
  16. UNITY_DOTS_INSTANCED_PROP(float4, _SpecColor)
  17. UNITY_DOTS_INSTANCED_PROP(float4, _EmissionColor)
  18. UNITY_DOTS_INSTANCED_PROP(float , _Cutoff)
  19. UNITY_DOTS_INSTANCED_PROP(float , _Surface)
  20. UNITY_DOTS_INSTANCING_END(MaterialPropertyMetadata)
  21. #define _BaseColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata_BaseColor)
  22. #define _SpecColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata_SpecColor)
  23. #define _EmissionColor UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float4 , Metadata_EmissionColor)
  24. #define _Cutoff UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata_Cutoff)
  25. #define _Surface UNITY_ACCESS_DOTS_INSTANCED_PROP_FROM_MACRO(float , Metadata_Surface)
  26. #endif
  27. TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap);
  28. half4 SampleSpecularSmoothness(float2 uv, half alpha, half4 specColor, TEXTURE2D_PARAM(specMap, sampler_specMap))
  29. {
  30. half4 specularSmoothness = half4(0, 0, 0, 1);
  31. #ifdef _SPECGLOSSMAP
  32. specularSmoothness = SAMPLE_TEXTURE2D(specMap, sampler_specMap, uv) * specColor;
  33. #elif defined(_SPECULAR_COLOR)
  34. specularSmoothness = specColor;
  35. #endif
  36. #ifdef _GLOSSINESS_FROM_BASE_ALPHA
  37. specularSmoothness.a = alpha;
  38. #endif
  39. return specularSmoothness;
  40. }
  41. inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  42. {
  43. outSurfaceData = (SurfaceData)0;
  44. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  45. outSurfaceData.alpha = albedoAlpha.a * _BaseColor.a;
  46. AlphaDiscard(outSurfaceData.alpha, _Cutoff);
  47. outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
  48. #ifdef _ALPHAPREMULTIPLY_ON
  49. outSurfaceData.albedo *= outSurfaceData.alpha;
  50. #endif
  51. half4 specularSmoothness = SampleSpecularSmoothness(uv, outSurfaceData.alpha, _SpecColor, TEXTURE2D_ARGS(_SpecGlossMap, sampler_SpecGlossMap));
  52. outSurfaceData.metallic = 0.0; // unused
  53. outSurfaceData.specular = specularSmoothness.rgb;
  54. outSurfaceData.smoothness = specularSmoothness.a;
  55. outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
  56. outSurfaceData.occlusion = 1.0;
  57. outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap));
  58. }
  59. #endif