DummyTransformColor.azsl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // We don't actually run this shader anywhere. It is used to test that optimization successfully strips away shader option constants.
  2. // When the shader options are *unspecified* at build time, the pixel shader should have 9 dynamic branches in DirectX and 22 dynamic branches in Vulkan.
  3. // When the shader options are *specificed* at build time, the pixel shader should have 0 dynamic branches on all platforms.
  4. float3 srgb_to_linearsrgb(float3 color)
  5. {
  6. return color * 2;
  7. }
  8. float3 linearsrgb_to_acescg(float3 color)
  9. {
  10. return color * 3;
  11. }
  12. float3 AcesCgToAces2065(float3 color)
  13. {
  14. return color * 5;
  15. }
  16. enum class ColorSpaceId
  17. {
  18. SRGB,
  19. LinearSRGB,
  20. ACEScg,
  21. ACES2065,
  22. Invalid
  23. };
  24. float3 TransformColor(float3 color, ColorSpaceId fromColorSpace, ColorSpaceId toColorSpace)
  25. {
  26. float3 transformedColor = color;
  27. static const float3 invalidColor = float3(1,0,1);
  28. if(fromColorSpace == ColorSpaceId::Invalid || toColorSpace == ColorSpaceId::Invalid)
  29. {
  30. transformedColor = invalidColor;
  31. }
  32. else if(fromColorSpace == toColorSpace)
  33. {
  34. return color;
  35. }
  36. else if(fromColorSpace == ColorSpaceId::SRGB && toColorSpace == ColorSpaceId::LinearSRGB)
  37. {
  38. transformedColor = srgb_to_linearsrgb(transformedColor);
  39. }
  40. else if(fromColorSpace == ColorSpaceId::LinearSRGB && toColorSpace == ColorSpaceId::ACEScg)
  41. {
  42. transformedColor = linearsrgb_to_acescg(transformedColor);
  43. }
  44. else if(fromColorSpace == ColorSpaceId::SRGB && toColorSpace == ColorSpaceId::ACEScg)
  45. {
  46. transformedColor = srgb_to_linearsrgb(transformedColor);
  47. transformedColor = linearsrgb_to_acescg(transformedColor);
  48. }
  49. else if(fromColorSpace == ColorSpaceId::ACEScg && toColorSpace == ColorSpaceId::ACES2065)
  50. {
  51. transformedColor = AcesCgToAces2065(transformedColor);
  52. }
  53. else
  54. {
  55. transformedColor = invalidColor;
  56. }
  57. return transformedColor;
  58. }
  59. ShaderResourceGroupSemantic SRG_Main
  60. {
  61. FrequencyId = 0;
  62. ShaderVariantFallback = 128;
  63. }
  64. ShaderResourceGroup MainSrg : SRG_Main
  65. {
  66. float4x4 m_modelToWorld;
  67. float4x4 m_viewProjectionMatrix;
  68. Texture2D m_texture;
  69. Sampler m_sampler
  70. {
  71. MaxAnisotropy = 16;
  72. AddressU = Wrap;
  73. AddressV = Wrap;
  74. AddressW = Wrap;
  75. };
  76. }
  77. option ColorSpaceId o_textureColorSpace = ColorSpaceId::Invalid;
  78. option ColorSpaceId o_workingColorSpace = ColorSpaceId::Invalid;
  79. struct VertexInput
  80. {
  81. float3 m_position : POSITION;
  82. float2 m_uv : UV0;
  83. };
  84. struct VertexOutput
  85. {
  86. float4 m_position : SV_Position;
  87. float2 m_uv : UV0;
  88. };
  89. struct PixelOutput
  90. {
  91. float4 m_color : SV_Target0;
  92. };
  93. VertexOutput MainVS(VertexInput input)
  94. {
  95. VertexOutput output;
  96. float4 worldPosition = mul(MainSrg::m_modelToWorld, float4(input.m_position, 1));
  97. output.m_position = mul(MainSrg::m_viewProjectionMatrix, worldPosition);
  98. output.m_uv = input.m_uv;
  99. return output;
  100. }
  101. PixelOutput MainPS(VertexOutput input)
  102. {
  103. PixelOutput output;
  104. float4 sampledColor = MainSrg::m_texture.Sample(MainSrg::m_sampler, input.m_uv);
  105. output.m_color.xyz = TransformColor(sampledColor.xyz, o_textureColorSpace, o_workingColorSpace);
  106. output.m_color.a = 1.0;
  107. return output;
  108. }