Cycles / Blackbody node:
authorThomas Dinges <blender@dingto.org>
Mon, 15 Jul 2013 04:38:35 +0000 (04:38 +0000)
committerThomas Dinges <blender@dingto.org>
Mon, 15 Jul 2013 04:38:35 +0000 (04:38 +0000)
* Fix the weird results with 800-804.3 Kelvin in SVM. This was an offset issue with the lookup table, made the table slightly larger now (from 954 to 956) which gives a small gap between the R/G/B components.
* Use Luminance also for values below 800 Kelvin, for consistency.

intern/cycles/kernel/svm/svm_blackbody.h
intern/cycles/render/blackbody.cpp

index 46b2f910f74771a21811ce5633c8d891059370ca..44803254bebf1116befe7ef3d8e04c5ca76b2dbc 100644 (file)
@@ -47,9 +47,9 @@ __device void svm_node_blackbody(KernelGlobals *kg, ShaderData *sd, float *stack
                color_rgb = make_float3(1.0e-6f,0.0f,0.0f);
        }
        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;
+               /* This is the overall size of the table */
+               const int lookuptablesize = 956;
+               const float lookuptablesizef = 956.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") */
@@ -60,21 +60,21 @@ __device void svm_node_blackbody(KernelGlobals *kg, ShaderData *sd, float *stack
                /* Retrieve colors from the lookup table */
                float lutval = t/lookuptablesizef;
                float R = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
-               lutval = (t + 317.0f*1.0f)/lookuptablesizef;
+               lutval = (t + 319.0f*1.0f)/lookuptablesizef;
                float G = lookup_table_read(kg, lutval, blackbody_table_offset, lookuptablesize);
-               lutval = (t + 317.0f*2.0f)/lookuptablesizef;
+               lutval = (t + 319.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);
 
-               /* Luminance */
-               float l = linear_rgb_to_gray(make_float3(R, G, B));
-
                color_rgb = make_float3(R, G, B);
-               color_rgb /= l;
        }
+       
+       /* Luminance */
+       float l = linear_rgb_to_gray(color_rgb);
+       color_rgb /= l;
 
        if (stack_valid(col_offset))
                stack_store_float3(stack, col_offset, color_rgb);
index 75b515aa3cbabd146582efccaca4a7abb8eed56d..467368935d7c8053e810e19f2cc842d0604955f3 100644 (file)
@@ -93,8 +93,8 @@ vector<float> blackbody_table()
                                                                   // h is Planck's const, k is Boltzmann's
        const float dlambda = 5.0f * 1e-9;  // in meters
 
-       /* Blackbody table from 800 to 12k Kelvin (317 entries) */
-       vector<float> blackbody_table(317*3+3);
+       /* Blackbody table from 800 to 12k Kelvin (319 entries (317+2 offset) * 3) */
+       vector<float> blackbody_table(956);
 
        float X, Y, Z;
 
@@ -131,8 +131,8 @@ vector<float> blackbody_table()
 
                /* Store in table in RRRGGGBBB format */
                blackbody_table[i] = col.x;
-               blackbody_table[i+317*1] = col.y;
-               blackbody_table[i+317*2] = col.z;       
+               blackbody_table[i+319*1] = col.y;
+               blackbody_table[i+319*2] = col.z;       
        }
 
        return blackbody_table;