Merged revision(s) 57828-57907 from trunk/blender into soc-2013-dingto
[blender.git] / intern / cycles / render / shader.cpp
index 21b43380f2cf951496b6ac451ff3f36aa7dea1c8..72a0645c779eea96d0a67775123e4bf3d8b29dfe 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "background.h"
 #include "bssrdf.h"
 
 #include "background.h"
 #include "bssrdf.h"
+#include "blackbody.h"
 #include "device.h"
 #include "graph.h"
 #include "light.h"
 #include "device.h"
 #include "graph.h"
 #include "light.h"
@@ -51,6 +52,7 @@ Shader::Shader()
        has_surface_transparent = false;
        has_surface_emission = false;
        has_surface_bssrdf = false;
        has_surface_transparent = false;
        has_surface_emission = false;
        has_surface_bssrdf = false;
+       has_converter_blackbody = false;
        has_volume = false;
        has_displacement = false;
 
        has_volume = false;
        has_displacement = false;
 
@@ -127,6 +129,7 @@ ShaderManager::ShaderManager()
 {
        need_update = true;
        bssrdf_table_offset = TABLE_OFFSET_INVALID;
 {
        need_update = true;
        bssrdf_table_offset = TABLE_OFFSET_INVALID;
+       blackbody_table_offset = TABLE_OFFSET_INVALID;
 }
 
 ShaderManager::~ShaderManager()
 }
 
 ShaderManager::~ShaderManager()
@@ -218,6 +221,7 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
        uint *shader_flag = dscene->shader_flag.resize(shader_flag_size);
        uint i = 0;
        bool has_surface_bssrdf = false;
        uint *shader_flag = dscene->shader_flag.resize(shader_flag_size);
        uint i = 0;
        bool has_surface_bssrdf = false;
+       bool has_converter_blackbody = false;
 
        foreach(Shader *shader, scene->shaders) {
                uint flag = 0;
 
        foreach(Shader *shader, scene->shaders) {
                uint flag = 0;
@@ -232,6 +236,8 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
                        flag |= SD_HOMOGENEOUS_VOLUME;
                if(shader->has_surface_bssrdf)
                        has_surface_bssrdf = true;
                        flag |= SD_HOMOGENEOUS_VOLUME;
                if(shader->has_surface_bssrdf)
                        has_surface_bssrdf = true;
+               if(shader->has_converter_blackbody)
+                       has_converter_blackbody = true;
 
                shader_flag[i++] = flag;
                shader_flag[i++] = shader->pass_id;
 
                shader_flag[i++] = flag;
                shader_flag[i++] = shader->pass_id;
@@ -257,6 +263,21 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
                scene->lookup_tables->remove_table(bssrdf_table_offset);
                bssrdf_table_offset = TABLE_OFFSET_INVALID;
        }
                scene->lookup_tables->remove_table(bssrdf_table_offset);
                bssrdf_table_offset = TABLE_OFFSET_INVALID;
        }
+
+       /* blackbody lookup table */
+       KernelBLACKBODY *kblackbody = &dscene->data.blackbody;
+       
+       if(has_converter_blackbody && blackbody_table_offset == TABLE_OFFSET_INVALID) {
+               vector<float> table = blackbody_table();
+               blackbody_table_offset = scene->lookup_tables->add_table(dscene, table);
+               
+               kblackbody->table_offset = (int)blackbody_table_offset;
+       }
+       else if(!has_converter_blackbody && blackbody_table_offset != TABLE_OFFSET_INVALID) {
+               scene->lookup_tables->remove_table(blackbody_table_offset);
+               blackbody_table_offset = TABLE_OFFSET_INVALID;
+       }
+
 }
 
 void ShaderManager::device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
 }
 
 void ShaderManager::device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
@@ -266,6 +287,11 @@ void ShaderManager::device_free_common(Device *device, DeviceScene *dscene, Scen
                bssrdf_table_offset = TABLE_OFFSET_INVALID;
        }
 
                bssrdf_table_offset = TABLE_OFFSET_INVALID;
        }
 
+       if(blackbody_table_offset != TABLE_OFFSET_INVALID) {
+               scene->lookup_tables->remove_table(blackbody_table_offset);
+               blackbody_table_offset = TABLE_OFFSET_INVALID;
+       }
+
        device->tex_free(dscene->shader_flag);
        dscene->shader_flag.clear();
 }
        device->tex_free(dscene->shader_flag);
        dscene->shader_flag.clear();
 }