{
  "format": "oryvio-effect",
  "formatVersion": 1,
  "id": "dev.oryvio.soft-wipe",
  "name": "Soft Wipe",
  "version": "1.0.0",
  "author": "Oryvio",
  "description": "Wipes from one picture to the other along a direction, its edge soft and lit.",
  "category": "Wipes",
  "kind": "transition",
  "params": [
    {
      "key": "angle",
      "type": "angle",
      "label": "Direction",
      "default": 0,
      "tip": "Which way the edge moves: 0 is to the right, 90 down.",
      "min": -180,
      "max": 180
    },
    {
      "key": "softness",
      "type": "float",
      "label": "Softness",
      "default": 0.2,
      "tip": "How wide its edge is, as a share of the picture.",
      "min": 0,
      "max": 1,
      "unit": "pct"
    },
    {
      "key": "glow",
      "type": "float",
      "label": "Glow",
      "default": 0.3,
      "tip": "How much light is on its edge.",
      "min": 0,
      "max": 2,
      "slider": [
        0,
        1
      ],
      "unit": "x"
    },
    {
      "key": "glowColor",
      "type": "color",
      "label": "Glow color",
      "default": "#ffd8a0"
    }
  ],
  "inputs": [
    "from",
    "to"
  ],
  "wgsl": "// Soft Wipe: from the outgoing picture to the incoming one, along a direction, as frame.progress runs from 0 to 1.\nfn render(uv: vec2f) -> vec4f {\n  let a = outgoing(uv);\n  let b = incoming(uv);\n  // Where this pixel is across the picture, from its middle: -0.5 to 0.5 each way.\n  let p = toPicture(uv) / frame.picture - 0.5;\n  let dir = vec2f(cos(params.angle), sin(params.angle));\n  // How far along the wipe it is, from 0 at the corner it starts from to 1 at the far one.\n  let span = max(0.5 * (abs(dir.x) + abs(dir.y)), 0.0001);\n  let s = dot(p, dir) / span * 0.5 + 0.5;\n  let soft = max(params.softness, 0.0001);\n  // The edge starts past one end and finishes past the other, so 0 is all outgoing and 1 all incoming.\n  let edge = frame.progress * (1.0 + soft) - soft;\n  let keep = smoothstep(edge, edge + soft, s);\n  let c = mix(b, a, keep);\n  let lit = params.glow * (1.0 - abs(2.0 * keep - 1.0));\n  return vec4f(c.rgb + params.glowColor.rgb * lit * c.a, c.a);\n}\n"
}
