pulseWave

a pulse wave with smooth falloff edges.

110 total functionsUpdated: Invalid Date

pulseWave

a pulse wave with smooth falloff edges.

Parameters

NameTypeDescription
xf32Input position.
frequencyf32Wave frequency.
amplitudef32Wave amplitude.
phasef32Phase offset.
widthf32Pulse width (0-1).
fallofff32Smooth falloff duration.

Returns

f32wave value.

WGSL Code

fn pulseWave(x: f32, frequency: f32, amplitude: f32, phase: f32, width: f32, falloff: f32) -> f32 {
let t = x * frequency + phase;
let tt = fract(t);
// Create a pulse with smooth edges
var pulse = 0.0;
// If tt is within the width, pulse is 1.0
if (tt < width) {
pulse = 1.0;
} else if (tt < width + falloff) {
// Smooth falloff
pulse = 1.0 - (tt - width) / falloff;
}
return pulse * amplitude;
}

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 { pulseWave, getFns } from 'wgsl-fns'
Usage:getFns(['pulseWave'])