# Notes on 1D Nonlinear Transformations for Games

game-dev
notes
My notes from Squirrel Eiserloh’s presentation on 1D nonlinear transformations for game development.
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.

## Implicit versus Parametric Equations

• Implicit equations are rules:
• Equation for a circle: $$x^{2} + Y^{2} = 25$$
• A point is either on the circle or not
• Parametric functions
• Yield an output for an input value
• $$P_{x} = 5 \cdot cos(2 \pi \cdot t)$$
• $$P_{y} = 5 \cdot sin(2 \pi \cdot t)$$
• $$P(t) = ?$$
• $$P(t) = (t, t \cdot cos(t), t*sin(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
• % 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) = t^{n}$$
• 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 - (1 - t)^{n}$$
• Larger exponents results in longer braking period at the end
• Techniques
• exponentiating
• flipping

### $$Mix(a, b, weightB, t)= a + weightB(b-a)$$

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

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

### Scale

• $$Scale(Function, t) = t \cdot Function(t)$$

### ReverseScale

• $$ReverseScale(Function, t) = (1-t) \cdot Function(t)$$

$$Arch2(t) = Scale(Flip(t)) = t \cdot (1-t)$$

$$SmoothStartArch3(t) = Scale(Arch2, t) = t^{2}(1-t)$$

$$SmoothStopArch3(t) = ReverseScale(Arch2, t) = t(1-t)^{2}$$

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

$$BellCurve6(t) = SmoothStop3(t) \cdot SmoothStart3(t)$$