stinger_matte_transition.effect 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. uniform float4x4 ViewProj;
  2. uniform texture2d a_tex;
  3. uniform texture2d b_tex;
  4. uniform texture2d matte_tex;
  5. uniform bool invert_matte;
  6. sampler_state textureSampler {
  7. Filter = Linear;
  8. AddressU = Clamp;
  9. AddressV = Clamp;
  10. };
  11. struct VertData {
  12. float4 pos : POSITION;
  13. float2 uv : TEXCOORD0;
  14. };
  15. VertData VSDefault(VertData v_in)
  16. {
  17. VertData vert_out;
  18. vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
  19. vert_out.uv = v_in.uv;
  20. return vert_out;
  21. }
  22. float srgb_nonlinear_to_linear_channel(float u)
  23. {
  24. return (u <= 0.04045) ? (u / 12.92) : pow((u + 0.055) / 1.055, 2.4);
  25. }
  26. float3 srgb_nonlinear_to_linear(float3 v)
  27. {
  28. return float3(srgb_nonlinear_to_linear_channel(v.r), srgb_nonlinear_to_linear_channel(v.g), srgb_nonlinear_to_linear_channel(v.b));
  29. }
  30. float4 StingerMatte(VertData f_in)
  31. {
  32. float2 uv = f_in.uv;
  33. float4 a_color = a_tex.Sample(textureSampler, uv);
  34. float4 b_color = b_tex.Sample(textureSampler, uv);
  35. float4 matte_color = matte_tex.Sample(textureSampler, uv);
  36. // RGB -> Luma conversion using Rec. 709 factors
  37. float matte_luma = (
  38. (matte_color.x * 0.2126) +
  39. (matte_color.y * 0.7152) +
  40. (matte_color.z * 0.0722)
  41. );
  42. // if matte invert is enabled, invert the matte color
  43. matte_luma = (invert_matte ? (1.0 - matte_luma) : matte_luma);
  44. float4 rgba = lerp(a_color, b_color, matte_luma);
  45. return rgba;
  46. }
  47. float4 PSStingerMatte(VertData f_in) : TARGET
  48. {
  49. float4 rgba = StingerMatte(f_in);
  50. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  51. return rgba;
  52. }
  53. float4 PSStingerMatteLinear(VertData f_in) : TARGET
  54. {
  55. float4 rgba = StingerMatte(f_in);
  56. return rgba;
  57. }
  58. technique StingerMatte
  59. {
  60. pass
  61. {
  62. vertex_shader = VSDefault(v_in);
  63. pixel_shader = PSStingerMatte(f_in);
  64. }
  65. }
  66. technique StingerMatteLinear
  67. {
  68. pass
  69. {
  70. vertex_shader = VSDefault(v_in);
  71. pixel_shader = PSStingerMatteLinear(f_in);
  72. }
  73. }