logisticCurve

a logistic (S-curve) function with derivative.

110 total functionsUpdated: Invalid Date

logisticCurve

a logistic (S-curve) function with derivative.

Parameters

NameTypeDescription
xf32Input value.
midpointf32Curve midpoint (inflection point).
steepnessf32Curve steepness factor.
minf32Minimum output value.
maxf32Maximum output value.

Returns

vec2<f32>value and derivative.

WGSL Code

fn logisticCurve(x: f32, midpoint: f32, steepness: f32, minValue: f32, maxValue: f32) -> vec2<f32> {
// Scale factor for steepness
let k = max(0.001, steepness);
// Shift x relative to midpoint
let z = -k * (x - midpoint);
// Calculate the exponent
let expTerm = exp(z);
// Calculate the logistic function value
let logistic = 1.0 / (1.0 + expTerm);
// Scale to min-max range
let range = maxValue - minValue;
let value = minValue + range * logistic;
// Calculate the derivative
let derivative = range * k * expTerm / ((1.0 + expTerm) * (1.0 + expTerm));
return vec2<f32>(value, 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 { logisticCurve, getFns } from 'wgsl-fns'
Usage:getFns(['logisticCurve'])