D3D12_PixelShader_NV12_BT601.hlsl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Texture2D theTextureY : register(t0);
  2. Texture2D theTextureUV : register(t1);
  3. SamplerState theSampler : register(s0);
  4. struct PixelShaderInput
  5. {
  6. float4 pos : SV_POSITION;
  7. float2 tex : TEXCOORD0;
  8. float4 color : COLOR0;
  9. };
  10. #define NVRS \
  11. "RootFlags ( ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT |" \
  12. " DENY_DOMAIN_SHADER_ROOT_ACCESS |" \
  13. " DENY_GEOMETRY_SHADER_ROOT_ACCESS |" \
  14. " DENY_HULL_SHADER_ROOT_ACCESS )," \
  15. "RootConstants(num32BitConstants=32, b0),"\
  16. "DescriptorTable ( SRV(t0), visibility = SHADER_VISIBILITY_PIXEL ),"\
  17. "DescriptorTable ( SRV(t1), visibility = SHADER_VISIBILITY_PIXEL ),"\
  18. "DescriptorTable ( Sampler(s0), visibility = SHADER_VISIBILITY_PIXEL )"
  19. [RootSignature(NVRS)]
  20. float4 main(PixelShaderInput input) : SV_TARGET
  21. {
  22. const float3 offset = {-0.0627451017, -0.501960814, -0.501960814};
  23. const float3 Rcoeff = {1.1644, 0.0000, 1.5960};
  24. const float3 Gcoeff = {1.1644, -0.3918, -0.8130};
  25. const float3 Bcoeff = {1.1644, 2.0172, 0.0000};
  26. float4 Output;
  27. float3 yuv;
  28. yuv.x = theTextureY.Sample(theSampler, input.tex).r;
  29. yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg;
  30. yuv += offset;
  31. Output.r = dot(yuv, Rcoeff);
  32. Output.g = dot(yuv, Gcoeff);
  33. Output.b = dot(yuv, Bcoeff);
  34. Output.a = 1.0f;
  35. return Output * input.color;
  36. }