exponentialRamp

an exponential ramp function with derivative.

110 total functionsUpdated: Invalid Date

exponentialRamp

an exponential ramp function with derivative.

Parameters

NameTypeDescription
xf32Input value.
basef32Exponential base.
scalef32Scale factor.
offsetf32Vertical offset.

Returns

vec2<f32>value and derivative.

WGSL Code

fn exponentialRamp(x: f32, base: f32, scale: f32, offset: f32) -> vec2<f32> {
// Ensure base is positive and not 1 (which would make it linear)
let b = select(base, 2.71828, abs(base - 1.0) < 0.001);
// Calculate the exponential function
let result = scale * pow(b, x) + offset;
// Calculate the derivative
let derivative = scale * pow(b, x) * log(b);
return vec2<f32>(result, derivative);
}

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