Skip to content

Instantly share code, notes, and snippets.

@jamornsriwasansak
Last active October 29, 2020 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamornsriwasansak/42a43d69c51a10f59d2b90d993faf6b4 to your computer and use it in GitHub Desktop.
Save jamornsriwasansak/42a43d69c51a10f59d2b90d993faf6b4 to your computer and use it in GitHub Desktop.
// https://portsmouth.github.io/Trinity/
// Approximate map from temperature in Kelvin to blackbody emission color.
// Valid from 1000 to 40000 K (and additionally 0 for pure full white)
vec3 colorTemperatureToRGB(const in float temperature)
{
mat3 m = (temperature <= 6500.0) ? mat3(vec3(0.0, -2902.1955373783176, -8257.7997278925690),
vec3(0.0, 1669.5803561666639, 2575.2827530017594),
vec3(1.0, 1.3302673723350029, 1.8993753891711275)) :
mat3(vec3(1745.0425298314172, 1216.6168361476490, -8257.7997278925690),
vec3(-2666.3474220535695, -2173.1012343082230, 2575.2827530017594),
vec3(0.55995389139931482, 0.70381203140554553, 1.8993753891711275));
return mix(clamp(vec3(m[0] / (vec3(clamp(temperature, 1000.0, 40000.0)) + m[1]) + m[2]), vec3(0.0), vec3(1.0)),
vec3(1.0),
smoothstep(1000.0, 0.0, temperature));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment