MetaInput.hlsl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef UNIVERSAL_META_PASS_INCLUDED
  2. #define UNIVERSAL_META_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  5. CBUFFER_START(UnityMetaPass)
  6. // x = use uv1 as raster position
  7. // y = use uv2 as raster position
  8. bool4 unity_MetaVertexControl;
  9. // x = return albedo
  10. // y = return normal
  11. bool4 unity_MetaFragmentControl;
  12. CBUFFER_END
  13. float unity_OneOverOutputBoost;
  14. float unity_MaxOutputValue;
  15. float unity_UseLinearSpace;
  16. struct MetaInput
  17. {
  18. half3 Albedo;
  19. half3 Emission;
  20. half3 SpecularColor;
  21. };
  22. float4 MetaVertexPosition(float4 positionOS, float2 uv1, float2 uv2, float4 uv1ST, float4 uv2ST)
  23. {
  24. if (unity_MetaVertexControl.x)
  25. {
  26. positionOS.xy = uv1 * uv1ST.xy + uv1ST.zw;
  27. // OpenGL right now needs to actually use incoming vertex position,
  28. // so use it in a very dummy way
  29. positionOS.z = positionOS.z > 0 ? REAL_MIN : 0.0f;
  30. }
  31. if (unity_MetaVertexControl.y)
  32. {
  33. positionOS.xy = uv2 * uv2ST.xy + uv2ST.zw;
  34. // OpenGL right now needs to actually use incoming vertex position,
  35. // so use it in a very dummy way
  36. positionOS.z = positionOS.z > 0 ? REAL_MIN : 0.0f;
  37. }
  38. return TransformWorldToHClip(positionOS.xyz);
  39. }
  40. half4 MetaFragment(MetaInput input)
  41. {
  42. half4 res = 0;
  43. if (unity_MetaFragmentControl.x)
  44. {
  45. res = half4(input.Albedo, 1.0);
  46. // Apply Albedo Boost from LightmapSettings.
  47. res.rgb = clamp(PositivePow(res.rgb, saturate(unity_OneOverOutputBoost)), 0, unity_MaxOutputValue);
  48. }
  49. if (unity_MetaFragmentControl.y)
  50. {
  51. half3 emission;
  52. if (unity_UseLinearSpace)
  53. emission = input.Emission;
  54. else
  55. emission = LinearToSRGB(input.Emission);
  56. res = half4(emission, 1.0);
  57. }
  58. return res;
  59. }
  60. #endif