SimpleLitInput.hlsl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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(half2 uv, half alpha, half4 specColor, TEXTURE2D_PARAM(specMap, sampler_specMap))
  29. {
  30. half4 specularSmoothness = half4(0.0h, 0.0h, 0.0h, 1.0h);
  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 = exp2(10 * alpha + 1);
  38. #else
  39. specularSmoothness.a = exp2(10 * specularSmoothness.a + 1);
  40. #endif
  41. return specularSmoothness;
  42. }
  43. inline void InitializeSimpleLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
  44. {
  45. outSurfaceData = (SurfaceData)0;
  46. half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
  47. outSurfaceData.alpha = albedoAlpha.a * _BaseColor.a;
  48. AlphaDiscard(outSurfaceData.alpha, _Cutoff);
  49. outSurfaceData.albedo = albedoAlpha.rgb * _BaseColor.rgb;
  50. #ifdef _ALPHAPREMULTIPLY_ON
  51. outSurfaceData.albedo *= outSurfaceData.alpha;
  52. #endif
  53. half4 specularSmoothness = SampleSpecularSmoothness(uv, outSurfaceData.alpha, _SpecColor, TEXTURE2D_ARGS(_SpecGlossMap, sampler_SpecGlossMap));
  54. outSurfaceData.metallic = 0.0; // unused
  55. outSurfaceData.specular = specularSmoothness.rgb;
  56. outSurfaceData.smoothness = specularSmoothness.a;
  57. outSurfaceData.normalTS = SampleNormal(uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
  58. outSurfaceData.occlusion = 1.0; // unused
  59. outSurfaceData.emission = SampleEmission(uv, _EmissionColor.rgb, TEXTURE2D_ARGS(_EmissionMap, sampler_EmissionMap));
  60. }
  61. #endif