MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / BlackbodyTemperatureAsRgb

Function BlackbodyTemperatureAsRgb

Hydrogent/src/HnLight.cpp:144–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142
143
144static float3 BlackbodyTemperatureAsRgb(float temp)
145{
146 // Catmull-Rom interpolation of kBblackbodyRGB
147 constexpr int numKnots = kBblackbodyRGB.size();
148
149 // Parametric distance along spline
150 const float u_spline = clamp((temp - kMinBlackbodyTemp) / (kMaxBlackbodyTemp - kMinBlackbodyTemp), 0.0f, 1.0f);
151
152 // Last 4 knots represent a trailing segment starting at u_spline==1.0,
153 // to simplify boundary behavior
154 constexpr int numSegs = (numKnots - 4);
155 const float x = u_spline * numSegs;
156 const int seg = static_cast<int>(std::floor(x));
157 const float u_seg = x - seg; // Parameter within segment
158
159 // Knot values for this segment
160 float3 k0 = kBblackbodyRGB[seg + 0];
161 float3 k1 = kBblackbodyRGB[seg + 1];
162 float3 k2 = kBblackbodyRGB[seg + 2];
163 float3 k3 = kBblackbodyRGB[seg + 3];
164
165 // Compute cubic coefficients.
166 float3 a = kCRBasis[0][0] * k0 + kCRBasis[0][1] * k1 + kCRBasis[0][2] * k2 + kCRBasis[0][3] * k3;
167 float3 b = kCRBasis[1][0] * k0 + kCRBasis[1][1] * k1 + kCRBasis[1][2] * k2 + kCRBasis[1][3] * k3;
168 float3 c = kCRBasis[2][0] * k0 + kCRBasis[2][1] * k1 + kCRBasis[2][2] * k2 + kCRBasis[2][3] * k3;
169 float3 d = kCRBasis[3][0] * k0 + kCRBasis[3][1] * k1 + kCRBasis[3][2] * k2 + kCRBasis[3][3] * k3;
170
171 // Eval cubic polynomial.
172 float3 rgb = ((a * u_seg + b) * u_seg + c) * u_seg + d;
173
174 // Clamp at zero, since the spline can produce small negative values,
175 // e.g. in the blue component at 1300k.
176 rgb = std::max(rgb, float3{0, 0, 0});
177
178 // Normalize to the same luminance as (1, 1, 1)
179 rgb /= Rec709RgbToLuma(rgb);
180
181 return rgb;
182}
183
184static float3 GetLightColor(pxr::HdSceneDelegate& SceneDelegate, const pxr::SdfPath& Id)
185{

Callers 1

GetLightColorFunction · 0.85

Calls 1

Rec709RgbToLumaFunction · 0.85

Tested by

no test coverage detected