planarReflection

A mirror floor: the child as it is above a line, and its reflection fading out below it.

planarReflection(
  opts: {line: PropRef; distance: PropRef; falloff: PropRef; edges: PropRef},
  original: Expr,
  reflection: (uv: Expr) =,
> Expr, reflectedUV: (params: GpuFragmentParams) => Expr): (params: GpuFragmentParams) => Expr

Import effects from shaders/std and use effects.blurs.planarReflection.

line (0–1 in uv), distance (how far below the line the reflection stays visible, in uv) and falloff (the width of the fade as a fraction of distance) are props. edges is a prop with transform: transformEdges and compileTime: true. original is the child's color at this pixel, reflection samples the child (or its blurred copy) at a coordinate, and reflectedUV is usually mirrorAcrossRow(line). Returns a fragment function whose result is premultiplied; unpremultiply it before returning from gpu.fragment.

Parameters

NameTypeNotes
opts{line: PropRef; distance: PropRef; falloff: PropRef; edges: PropRef}
originalExpr
reflection(uv: Expr) => Expr
reflectedUV(params: GpuFragmentParams) => Expr

Example

planarReflection({line: p('height'), distance: p('distance'), falloff: p('falloff'), edges: p('edges')}, source.sample(ctx.uv), (uv) => blurred.sample(uv), mirrorAcrossRow(p('height')))(params)

See also

  • mirrorAcrossRow — The coordinate mirrored across a horizontal line, for reading a reflection below it.
  • depthRampBlur — The blur half of a mirror floor: blurs the child more the further a row sits below the line.

Used by

ReflectivePlane