Skip to content

Instantly share code, notes, and snippets.

@phobon
Created September 20, 2025 05:30
Show Gist options
  • Select an option

  • Save phobon/63ba9224854a2f90363b406fc3e630f1 to your computer and use it in GitHub Desktop.

Select an option

Save phobon/63ba9224854a2f90363b406fc3e630f1 to your computer and use it in GitHub Desktop.
import { Fn, float } from 'three/tsl'
/**
* Applies Reinhard tonemapping to a color vector.
* @param {vec3} _color Input color vector
* @returns {vec3} Tonemapped color
*/
export const reinhardTonemap = Fn(([_color]) => {
return _color.div(_color.add(1.0))
})
/**
* Applies Uncharted2 filmic tonemapping to a color vector.
* @param {vec3} color Input color vector
* @returns {vec3} Tonemapped color
*/
export const uncharted2Tonemap = Fn(([color]) => {
const _color = color
_color.mulAssign(16.0)
const a = float(0.15)
const b = float(0.5)
const c = float(0.1)
const d = float(0.2)
const e = float(0.02)
const f = float(0.3)
return _color
.mul(a.mul(_color).add(c.mul(b)))
.add(d.mul(e))
.div(_color.mul(a.mul(_color).add(b)).add(d.mul(f)))
.sub(e.div(f))
})
/**
* Applies ACES tonemapping to a color vector.
* @param {vec3} _color Input color vector
* @returns {vec3} Tonemapped color
*/
export const acesTonemap = Fn(([_color]) => {
const a = float(2.51)
const b = float(0.03)
const c = float(2.43)
const d = float(0.59)
const e = float(0.14)
return _color.mul(a.mul(_color).add(b)).div(_color.mul(c.mul(_color).add(d)).add(e))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment