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. VertData VSDefault(VertData v_in)
  20. {
  21. VertData vert_out;
  22. vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj);
  23. vert_out.uv = v_in.uv;
  24. return vert_out;
  25. }
  26. float4 PSLumaWipe(VertData v_in) : TARGET
  27. {
  28. float2 uv = v_in.uv;
  29. float4 a_color = a_tex.Sample(textureSampler, uv);
  30. float4 b_color = b_tex.Sample(textureSampler, uv);
  31. float luma = l_tex.Sample(textureSampler, uv).x;
  32. if (invert)
  33. luma = 1.0f - luma;
  34. float time = lerp(0.0f, 1.0f + softness, progress);
  35. float4 rgba;
  36. if (luma <= time - softness) {
  37. rgba = b_color;
  38. } else if (luma >= time) {
  39. rgba = a_color;
  40. } else {
  41. float alpha = (time - luma) / softness;
  42. rgba = lerp(a_color, b_color, alpha);
  43. }
  44. return rgba;
  45. }
  46. technique LumaWipe
  47. {
  48. pass
  49. {
  50. vertex_shader = VSDefault(v_in);
  51. pixel_shader = PSLumaWipe(v_in);
  52. }
  53. }