luma_wipe_transition.effect 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Based rendermix wipe shader
  2. // https://github.com/rectalogic/rendermix-basic-effects/blob/master/assets/com/rendermix/Wipe/Wipe.frag
  3. uniform float4x4 ViewProj;
  4. uniform texture2d a_tex;
  5. uniform texture2d b_tex;
  6. uniform texture2d l_tex;
  7. uniform float progress;
  8. uniform bool invert;
  9. uniform float softness;
  10. sampler_state textureSampler {
  11. Filter = Linear;
  12. AddressU = Clamp;
  13. AddressV = Clamp;
  14. };
  15. struct VertData {
  16. float4 pos : POSITION;
  17. float2 uv : TEXCOORD0;
  18. };
  19. #include "premultiplied.inc"
  20. VertData VSDefault(VertData v_in)
  21. {
  22. VertData vert_out;
  23. vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
  24. vert_out.uv = v_in.uv;
  25. return vert_out;
  26. }
  27. float4 PSLumaWipe(VertData v_in) : TARGET
  28. {
  29. float2 uv = v_in.uv;
  30. float4 a_color = convert_pmalpha(a_tex.Sample(textureSampler, uv));
  31. float4 b_color = convert_pmalpha(b_tex.Sample(textureSampler, uv));
  32. float luma = l_tex.Sample(textureSampler, uv).x;
  33. if (invert)
  34. luma = 1.0f - luma;
  35. float time = lerp(0.0f, 1.0f + softness, progress);
  36. if (luma <= time - softness)
  37. return b_color;
  38. if (luma >= time)
  39. return a_color;
  40. float alpha = (time - luma) / softness;
  41. return lerp(a_color, b_color, alpha);
  42. }
  43. technique LumaWipe
  44. {
  45. pass
  46. {
  47. vertex_shader = VSDefault(v_in);
  48. pixel_shader = PSLumaWipe(v_in);
  49. }
  50. }