Cycles / Blackbody node:
* Code cleanup to avoid duplicated table defines, moved them into kernel_types.h.
This commit is contained in:
parent
9042b599e0
commit
ac4058a211
@ -44,6 +44,12 @@ CCL_NAMESPACE_BEGIN
|
||||
#define BSSRDF_MIN_RADIUS 1e-8f
|
||||
#define BSSRDF_MAX_ATTEMPTS 8
|
||||
|
||||
#define BB_DRAPPER 800.0
|
||||
#define BB_MAX_TABLE_RANGE 12000.0
|
||||
#define BB_TABLE_XPOWER 1.5
|
||||
#define BB_TABLE_YPOWER 5.0
|
||||
#define BB_TABLE_SPACING 2.0
|
||||
|
||||
#define TEX_NUM_FLOAT_IMAGES 5
|
||||
|
||||
/* device capabilities */
|
||||
|
@ -36,31 +36,24 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
__device void svm_node_blackbody(KernelGlobals *kg, ShaderData *sd, float *stack, uint temperature_offset, uint col_offset)
|
||||
{
|
||||
/* ToDo: move those defines to kernel_types.h ? */
|
||||
float bb_drapper = 800.0f;
|
||||
float bb_max_table_range = 12000.0f;
|
||||
float bb_table_xpower = 1.5f;
|
||||
float bb_table_ypower = 5.0f;
|
||||
float bb_table_spacing = 2.0f;
|
||||
|
||||
/* Output */
|
||||
float3 color_rgb = make_float3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
/* Input */
|
||||
float temperature = stack_load_float(stack, temperature_offset);
|
||||
|
||||
if (temperature < bb_drapper) {
|
||||
if (temperature < BB_DRAPPER) {
|
||||
/* just return very very dim red */
|
||||
color_rgb = make_float3(1.0e-6f,0.0f,0.0f);
|
||||
}
|
||||
else if (temperature <= bb_max_table_range) {
|
||||
else if (temperature <= BB_MAX_TABLE_RANGE) {
|
||||
/* This is the overall size of the table (317*3+3) */
|
||||
const int lookuptablesize = 954;
|
||||
const float lookuptablesizef = 954.0f;
|
||||
|
||||
/* reconstruct a proper index for the table lookup, compared to OSL we don't look up two colors
|
||||
just one (the OSL-lerp is also automatically done for us by "lookup_table_read") */
|
||||
float t = powf ((temperature - bb_drapper) / bb_table_spacing, 1.0f/bb_table_xpower);
|
||||
float t = powf ((temperature - BB_DRAPPER) / BB_TABLE_SPACING, 1.0f/BB_TABLE_XPOWER);
|
||||
|
||||
int blackbody_table_offset = kernel_data.blackbody.table_offset;
|
||||
|
||||
@ -72,9 +65,9 @@ __device void svm_node_blackbody(KernelGlobals *kg, ShaderData *sd, float *stack
|
||||
lutval = (t + 317.0f*2.0f)/lookuptablesizef;
|
||||
float B = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
|
||||
|
||||
R = powf(R, bb_table_ypower);
|
||||
G = powf(G, bb_table_ypower);
|
||||
B = powf(B, bb_table_ypower);
|
||||
R = powf(R, BB_TABLE_YPOWER);
|
||||
G = powf(G, BB_TABLE_YPOWER);
|
||||
B = powf(B, BB_TABLE_YPOWER);
|
||||
|
||||
/* Luminance */
|
||||
float l = linear_rgb_to_gray(make_float3(R, G, B));
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "util_color.h"
|
||||
#include "util_math.h"
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
vector<float> blackbody_table()
|
||||
@ -94,18 +96,11 @@ vector<float> blackbody_table()
|
||||
/* Blackbody table from 800 to 12k Kelvin (317 entries) */
|
||||
vector<float> blackbody_table(317*3+3);
|
||||
|
||||
/* ToDo: move those defines to kernel_types.h ? */
|
||||
float bb_drapper = 800.0f;
|
||||
float bb_max_table_range = 12000.0f;
|
||||
float bb_table_xpower = 1.5f;
|
||||
float bb_table_ypower = 5.0f;
|
||||
float bb_table_spacing = 2.0f;
|
||||
|
||||
float X, Y, Z;
|
||||
|
||||
/* ToDo: bring this back to what OSL does with the lastTemperature limit ? */
|
||||
for (int i = 0; i <= 317; ++i) {
|
||||
float Temperature = powf (float(i), bb_table_xpower) * bb_table_spacing + bb_drapper;
|
||||
float Temperature = powf (float(i), BB_TABLE_XPOWER) * BB_TABLE_SPACING + BB_DRAPPER;
|
||||
X = 0;
|
||||
Y = 0;
|
||||
Z = 0;
|
||||
@ -130,9 +125,9 @@ vector<float> blackbody_table()
|
||||
/* Clamp to zero if values are smaller */
|
||||
col = max(col, make_float3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
col.x = powf(col.x, 1.0f / bb_table_ypower);
|
||||
col.y = powf(col.y, 1.0f / bb_table_ypower);
|
||||
col.z = powf(col.z, 1.0f / bb_table_ypower);
|
||||
col.x = powf(col.x, 1.0f / BB_TABLE_YPOWER);
|
||||
col.y = powf(col.y, 1.0f / BB_TABLE_YPOWER);
|
||||
col.z = powf(col.z, 1.0f / BB_TABLE_YPOWER);
|
||||
|
||||
/* Store in table in RRRGGGBBB format */
|
||||
blackbody_table[i] = col.x;
|
||||
|
Loading…
Reference in New Issue
Block a user