sdfMirror

an SDF across a plane defined by a normal vector.

110 total functionsUpdated: Invalid Date

sdfMirror

an SDF across a plane defined by a normal vector.

Parameters

NameTypeDescription
positionvec3<f32>3D position to transform.
normalvec3<f32>Normal vector of the mirror plane.
offsetf32Distance offset of the mirror plane.

Returns

vec3<f32>position.

WGSL Code

fn sdfMirror(position: vec3<f32>, normal: vec3<f32>, offset: f32) -> vec3<f32> {
let n = normalize(normal);
let d = dot(position, n) - offset;
return position - 2.0 * max(0.0, d) * n;
}

About wgsl-fns

A JavaScript library providing WGSL utility functions as strings for WebGPU shader development. Includes mathematical utilities, noise generation, signed distance fields, and color manipulation functions.

Install:npm install wgsl-fns
Import:import { sdfMirror, getFns } from 'wgsl-fns'
Usage:getFns(['sdfMirror'])