Skip to content

Commit

Permalink
Fix blackbody node clamping.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolassavva-autodesk committed May 31, 2023
1 parent bedc293 commit 0cd998e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions libraries/pbrlib/genglsl/mx_blackbody.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ void mx_blackbody(float temperatureKelvin, out vec3 colorValue)
float xc, yc;
float t, t2, t3, xc2, xc3;

// if value outside valid range of approximation clamp to accepted temperature range
temperatureKelvin = clamp(temperatureKelvin, 1667.0, 25000.0);

t = 1000.0 / temperatureKelvin;
t2 = t * t;
t3 = t * t * t;

// if value outside valid range of approximation clamp to accepted temperature range
clamp(temperatureKelvin, 1667.0, 25000.0);


// Cubic spline approximation for Kelvin temperature to sRGB conversion
// (https://en.wikipedia.org/wiki/Planckian_locus#Approximation)
if (temperatureKelvin < 4000.0) { // 1667K <= temperatureKelvin < 4000K
Expand Down
7 changes: 3 additions & 4 deletions libraries/pbrlib/genosl/mx_blackbody.osl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ void mx_blackbody(float temperature, output color color_value)
float xc, yc;
float t, t2, t3, xc2, xc3;

// if value outside valid range of approximation clamp to accepted temperature range
temperature = clamp(temperature, 1667.0, 25000.0);

t = 1000.0 / temperature;
t2 = t * t;
t3 = t * t * t;

// if value outside valid range of approximation clamp to accepted temperature range
clamp(temperature, 1667.0, 25000.0);


// Cubic spline approximation for Kelvin temperature to sRGB conversion
// (https://en.wikipedia.org/wiki/Planckian_locus#Approximation)
if (temperature < 4000.0) { // 1667K <= temperature < 4000K
Expand Down

0 comments on commit 0cd998e

Please sign in to comment.