{
  "format": "oryvio-effect",
  "formatVersion": 1,
  "id": "dev.oryvio.soft-vignette",
  "name": "Soft Vignette",
  "version": "1.0.0",
  "author": "Oryvio",
  "description": "Darkens the picture toward its edges, or tints them, in linear light: round, or following the picture’s shape.",
  "category": "Vignette",
  "kind": "filter",
  "params": [
    {
      "key": "amount",
      "type": "float",
      "label": "Amount",
      "default": 0.5,
      "tip": "How much of the color the edges take.",
      "min": 0,
      "max": 1,
      "unit": "pct"
    },
    {
      "key": "reach",
      "type": "float",
      "label": "Size",
      "default": 0.75,
      "tip": "How far from the center it starts, as a share of the picture.",
      "min": 0.05,
      "max": 2,
      "slider": [
        0.2,
        1.5
      ],
      "unit": "pct"
    },
    {
      "key": "softness",
      "type": "float",
      "label": "Softness",
      "default": 0.6,
      "tip": "How gradually it fades in.",
      "min": 0,
      "max": 1,
      "unit": "pct"
    },
    {
      "key": "center",
      "type": "point",
      "label": "Center",
      "default": [
        0.5,
        0.5
      ],
      "tip": "Where its middle is, as a share of the picture.",
      "min": -2,
      "max": 3
    },
    {
      "key": "tint",
      "type": "color",
      "label": "Color",
      "default": "#000000",
      "tip": "What the edges are taken toward."
    },
    {
      "key": "round",
      "type": "bool",
      "label": "Round",
      "default": true,
      "tip": "A circle, rather than an oval the picture’s shape."
    }
  ],
  "inputs": [
    "source"
  ],
  "wgsl": "// Soft Vignette: the picture taken toward a color at its edges, in linear light.\nfn render(uv: vec2f) -> vec4f {\n  let c = source(uv);\n  // Where this pixel is from the vignette's center, in the picture's own pixels.\n  let p = toPicture(uv) - params.center * frame.picture;\n  let half = frame.picture * 0.5;\n  // An oval the picture's shape, or a circle as wide as its shorter side.\n  let r = select(p / half, p / min(half.x, half.y), params.round != 0u);\n  let d = length(r);\n  let soft = max(params.softness * params.reach, 0.0001);\n  let k = smoothstep(params.reach - soft, params.reach + soft * 0.5, d) * params.amount;\n  // Premultiplied in, premultiplied out: worked on as light, without its cover.\n  let s = unpremultiply(c);\n  let lit = mix(toLinear(s.rgb), toLinear(params.tint.rgb), k);\n  return premultiply(vec4f(toStored(lit), s.a));\n}\n"
}
