stinger_matte_transition.effect 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. float4 PSStingerMatte(VertData v_in) : TARGET
  23. {
  24. float2 uv = v_in.uv;
  25. float4 a_color = a_tex.Sample(textureSampler, uv);
  26. float4 b_color = b_tex.Sample(textureSampler, uv);
  27. float4 matte_color = matte_tex.Sample(textureSampler, uv);
  28. // RGB -> Luma conversion using Rec. 709 factors
  29. float matte_luma = (
  30. (matte_color.x * 0.2126) +
  31. (matte_color.y * 0.7152) +
  32. (matte_color.z * 0.0722)
  33. );
  34. // if matte invert is enabled, invert the matte color
  35. matte_luma = (invert_matte ? (1.0 - matte_luma) : matte_luma);
  36. return lerp(a_color, b_color, matte_luma);
  37. }
  38. technique StingerMatte
  39. {
  40. pass
  41. {
  42. vertex_shader = VSDefault(v_in);
  43. pixel_shader = PSStingerMatte(v_in);
  44. }
  45. }