Notes on 1D Nonlinear Transformations for Games

My notes from Squirrel Eiserloh’s presentation on 1D nonlinear transformations for game development.
Author

Christian Mills

Published

December 29, 2021

Overview

Here are some notes I took while watching Squirrel Eiserloh’s presentation covering how 1D nonlinear transformations can be used by game programmers.

Motivations

Implicit versus Parametric Equations

  • Implicit equations are rules:
    • Equation for a circle: x2+Y2=25
      • A point is either on the circle or not
  • Parametric functions
    • Yield an output for an input value
      • Px=5cos(2πt)
      • Py=5sin(2πt)
    • P(t)=?
    • P(t)=(t,tcos(t),tsin(t))
      • (x,y,z)
      • Generates a spiral that increases in radius along the x axis
    • Anything you can express in terms of a single float as input
    • A common float input is “time”

Parametric Manipulations

  • Do NOT mess with the interpolation itself (e.g. color, position, AI disposition, etc.)
  • Instead just mess the parameter

Parametric Opportunities

  • Anytime you have a single float to change
  • Anytime you can express something in terms of a single float
  • Pretty much whenever you use time

The Big Idea

  • You can make any parametric equation more interesting without modifying the function itself, without knowing anything about the function

The Two Most Important Number Ranges

  • [0,1]
    • Useful for fractions
      • % shadow
      • % luminance
      • % falloff
      • % complete
      • % damage
      • % experience
      • % cost
      • % penalty
      • % fog
      • % AI aggression
      • % chance to hit
      • % chance to drop loot
      • % time to complete
      • Fuzzy Logic
      • Most anything parametric
  • [1,1]
    • Useful for deviations
      • noise
      • perturbation
      • terrain and map generation
      • variation
      • distribution
      • sinusoidal
      • AI response curves

Normalized Non-Linear Functions

  • [0,1]
  • Functions for which:
    • P(0)=0
    • P(1)=1
    • P(t) !=t
  • Examples
    • Position over time
    • Scale over time
    • Alpha over time
    • Color over time
    • Strength over time
    • Aggression over time
  • Also called
    • easing functions
    • filter functions
    • lerping functions
    • tweening functions

Range Mapping

  • can be applied during middle of range-mapping
out RangeMap(in, inStart, inEnd, outStart, outEnd)
{
    // Puts in [0, inEnd - inStart]
    out = in - inStart;
    // Puts in [0,1]
    out /= (inEnd - inStart);
    // in [0,1]
    out = ApplySomeEasingFunction(out);
    // Puts in [0, outRange]
    out *= (outEnd - outStart);
    // Puts in [outStart, outEnd]
    return out + outStart
}

SmoothStart

  • SmoothStartN(t)=tn
  • Larger exponents result in steeper curve
  • Will always start and end at the same time, regardless of exponent value
  • Technique
    • exponentiating

SmoothStop

  • SmoothStopN(t)=1(1t)n
  • Larger exponents results in longer braking period at the end
  • Techniques
    • exponentiating
    • flipping

Mix(a,b,weightB,t)=a+weightB(ba)

  • Mix(SmoothStart2,SmoothStop2,blend,t)
  • SmoothStart2.2=Mix(SmoothStart2,SmoothStart3,0.2);
    • Way faster than using the pow() function

Crossfade

  • Like Mix, but use t itself as the mix weight
  • Also called SmoothStep

Scale

  • Scale(Function,t)=tFunction(t)

ReverseScale

  • ReverseScale(Function,t)=(1t)Function(t)

Arch2(t)=Scale(Flip(t))=t(1t)

SmoothStartArch3(t)=Scale(Arch2,t)=t2(1t)

SmoothStopArch3(t)=ReverseScale(Arch2,t)=t(1t)2

SmoothStepArch3(t)=ReverseScale(Scale(Arch2,t),t)

BellCurve6(t)=SmoothStop3(t)SmoothStart3(t)