2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2013-06-28 13:05:21 +00:00
|
|
|
#include "background.h"
|
2013-07-31 20:56:32 +00:00
|
|
|
#include "blackbody.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "device.h"
|
|
|
|
#include "graph.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "nodes.h"
|
|
|
|
#include "osl.h"
|
|
|
|
#include "scene.h"
|
|
|
|
#include "shader.h"
|
|
|
|
#include "svm.h"
|
2013-04-01 20:26:52 +00:00
|
|
|
#include "tables.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "util_foreach.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-20 19:21:05 +00:00
|
|
|
/* Beckmann sampling precomputed table, see bsdf_microfacet.h */
|
|
|
|
|
|
|
|
/* 2D slope distribution (alpha = 1.0) */
|
|
|
|
static float beckmann_table_P22(const float slope_x, const float slope_y)
|
|
|
|
{
|
|
|
|
return expf(-(slope_x*slope_x + slope_y*slope_y));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* maximal slope amplitude (range that contains 99.99% of the distribution) */
|
|
|
|
static float beckmann_table_slope_max()
|
|
|
|
{
|
|
|
|
return 6.0;
|
|
|
|
}
|
|
|
|
|
2014-07-10 11:55:56 +00:00
|
|
|
/* Paper used: Importance Sampling Microfacet-Based BSDFs with the
|
|
|
|
* Distribution of Visible Normals. Supplemental Material 2/2.
|
|
|
|
*
|
|
|
|
* http://hal.inria.fr/docs/01/00/66/20/ANNEX/supplemental2.pdf
|
|
|
|
*/
|
2014-06-20 19:21:05 +00:00
|
|
|
static void beckmann_table_rows(float *table, int row_from, int row_to)
|
|
|
|
{
|
|
|
|
/* allocate temporary data */
|
|
|
|
const int DATA_TMP_SIZE = 512;
|
|
|
|
vector<double> slope_x(DATA_TMP_SIZE);
|
|
|
|
vector<double> CDF_P22_omega_i(DATA_TMP_SIZE);
|
|
|
|
|
|
|
|
/* loop over incident directions */
|
|
|
|
for(int index_theta = row_from; index_theta < row_to; index_theta++) {
|
|
|
|
/* incident vector */
|
|
|
|
const float cos_theta = index_theta / (BECKMANN_TABLE_SIZE - 1.0f);
|
|
|
|
const float sin_theta = safe_sqrtf(1.0f - cos_theta*cos_theta);
|
|
|
|
|
|
|
|
/* for a given incident vector
|
|
|
|
* integrate P22_{omega_i}(x_slope, 1, 1), Eq. (10) */
|
|
|
|
slope_x[0] = -beckmann_table_slope_max();
|
|
|
|
CDF_P22_omega_i[0] = 0;
|
|
|
|
|
|
|
|
for(int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x) {
|
|
|
|
/* slope_x */
|
|
|
|
slope_x[index_slope_x] = -beckmann_table_slope_max() + 2.0f * beckmann_table_slope_max() * index_slope_x/(DATA_TMP_SIZE - 1.0f);
|
|
|
|
|
|
|
|
/* dot product with incident vector */
|
2014-06-23 07:47:52 +00:00
|
|
|
float dot_product = fmaxf(0.0f, -(float)slope_x[index_slope_x]*sin_theta + cos_theta);
|
2014-06-20 19:21:05 +00:00
|
|
|
/* marginalize P22_{omega_i}(x_slope, 1, 1), Eq. (10) */
|
|
|
|
float P22_omega_i = 0.0f;
|
|
|
|
|
|
|
|
for(int j = 0; j < 100; ++j) {
|
|
|
|
float slope_y = -beckmann_table_slope_max() + 2.0f * beckmann_table_slope_max() * j * (1.0f/99.0f);
|
2014-06-23 07:47:52 +00:00
|
|
|
P22_omega_i += dot_product * beckmann_table_P22((float)slope_x[index_slope_x], slope_y);
|
2014-06-20 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CDF of P22_{omega_i}(x_slope, 1, 1), Eq. (10) */
|
2014-10-07 22:09:36 +00:00
|
|
|
CDF_P22_omega_i[index_slope_x] = CDF_P22_omega_i[index_slope_x - 1] + (double)P22_omega_i;
|
2014-06-20 19:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* renormalize CDF_P22_omega_i */
|
|
|
|
for(int index_slope_x = 1; index_slope_x < DATA_TMP_SIZE; ++index_slope_x)
|
|
|
|
CDF_P22_omega_i[index_slope_x] /= CDF_P22_omega_i[DATA_TMP_SIZE - 1];
|
|
|
|
|
|
|
|
/* loop over random number U1 */
|
|
|
|
int index_slope_x = 0;
|
|
|
|
|
|
|
|
for(int index_U = 0; index_U < BECKMANN_TABLE_SIZE; ++index_U) {
|
2014-07-10 11:42:38 +00:00
|
|
|
const double U = 0.0000001 + 0.9999998 * index_U / (double)(BECKMANN_TABLE_SIZE - 1);
|
2014-06-20 19:21:05 +00:00
|
|
|
|
|
|
|
/* inverse CDF_P22_omega_i, solve Eq.(11) */
|
|
|
|
while(CDF_P22_omega_i[index_slope_x] <= U)
|
|
|
|
++index_slope_x;
|
|
|
|
|
|
|
|
const double interp =
|
|
|
|
(CDF_P22_omega_i[index_slope_x] - U) /
|
|
|
|
(CDF_P22_omega_i[index_slope_x] - CDF_P22_omega_i[index_slope_x - 1]);
|
|
|
|
|
|
|
|
/* store value */
|
|
|
|
table[index_U + index_theta*BECKMANN_TABLE_SIZE] = (float)(
|
2014-10-07 22:09:36 +00:00
|
|
|
interp * slope_x[index_slope_x - 1] +
|
|
|
|
(1.0 - interp) * slope_x[index_slope_x]);
|
2014-06-20 19:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void beckmann_table_build(vector<float>& table)
|
|
|
|
{
|
|
|
|
table.resize(BECKMANN_TABLE_SIZE*BECKMANN_TABLE_SIZE);
|
|
|
|
|
|
|
|
/* multithreaded build */
|
|
|
|
TaskPool pool;
|
|
|
|
|
|
|
|
for(int i = 0; i < BECKMANN_TABLE_SIZE; i+=8)
|
|
|
|
pool.push(function_bind(&beckmann_table_rows, &table[0], i, i+8));
|
|
|
|
|
|
|
|
pool.wait_work();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Shader */
|
|
|
|
|
|
|
|
Shader::Shader()
|
|
|
|
{
|
|
|
|
name = "";
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
pass_id = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
graph = NULL;
|
|
|
|
graph_bump = NULL;
|
|
|
|
|
2013-06-18 09:36:00 +00:00
|
|
|
use_mis = true;
|
|
|
|
use_transparent_shadow = true;
|
2013-12-29 21:19:38 +00:00
|
|
|
heterogeneous_volume = true;
|
2014-10-22 14:17:03 +00:00
|
|
|
volume_sampling_method = VOLUME_SAMPLING_DISTANCE;
|
|
|
|
volume_interpolation_method = VOLUME_INTERPOLATION_LINEAR;
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2011-10-12 23:03:12 +00:00
|
|
|
has_surface = false;
|
2011-09-27 20:37:24 +00:00
|
|
|
has_surface_transparent = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
has_surface_emission = false;
|
2013-04-01 20:26:52 +00:00
|
|
|
has_surface_bssrdf = false;
|
2013-07-31 20:56:32 +00:00
|
|
|
has_converter_blackbody = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
has_volume = false;
|
|
|
|
has_displacement = false;
|
2013-08-18 14:15:57 +00:00
|
|
|
has_bssrdf_bump = false;
|
2014-04-03 20:04:39 +00:00
|
|
|
has_heterogeneous_volume = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-30 11:51:17 +00:00
|
|
|
used = false;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = true;
|
2011-05-31 11:31:00 +00:00
|
|
|
need_update_attributes = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Shader::~Shader()
|
|
|
|
{
|
|
|
|
delete graph;
|
|
|
|
delete graph_bump;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shader::set_graph(ShaderGraph *graph_)
|
|
|
|
{
|
2013-05-10 11:31:57 +00:00
|
|
|
/* do this here already so that we can detect if mesh or object attributes
|
|
|
|
* are needed, since the node attribute callbacks check if their sockets
|
|
|
|
* are connected but proxy nodes should not count */
|
|
|
|
if(graph_)
|
|
|
|
graph_->remove_unneeded_nodes();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* assign graph */
|
|
|
|
delete graph;
|
|
|
|
delete graph_bump;
|
|
|
|
graph = graph_;
|
|
|
|
graph_bump = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shader::tag_update(Scene *scene)
|
|
|
|
{
|
|
|
|
/* update tag */
|
|
|
|
need_update = true;
|
|
|
|
scene->shader_manager->need_update = true;
|
|
|
|
|
|
|
|
/* if the shader previously was emissive, update light distribution,
|
|
|
|
* if the new shader is emissive, a light manager update tag will be
|
|
|
|
* done in the shader manager device update. */
|
2013-06-18 09:36:00 +00:00
|
|
|
if(use_mis && has_surface_emission)
|
2011-04-27 11:58:34 +00:00
|
|
|
scene->light_manager->need_update = true;
|
|
|
|
|
2013-12-31 16:30:34 +00:00
|
|
|
/* quick detection of which kind of shaders we have to avoid loading
|
|
|
|
* e.g. surface attributes when there is only a volume shader. this could
|
|
|
|
* be more fine grained but it's better than nothing */
|
|
|
|
OutputNode *output = graph->output();
|
|
|
|
has_surface = has_surface || output->input("Surface")->link;
|
|
|
|
has_volume = has_volume || output->input("Volume")->link;
|
|
|
|
has_displacement = has_displacement || output->input("Displacement")->link;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* get requested attributes. this could be optimized by pruning unused
|
2012-06-09 17:22:52 +00:00
|
|
|
* nodes here already, but that's the job of the shader manager currently,
|
|
|
|
* and may not be so great for interactive rendering where you temporarily
|
|
|
|
* disconnect a node */
|
2013-12-31 16:30:34 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
AttributeRequestSet prev_attributes = attributes;
|
|
|
|
|
|
|
|
attributes.clear();
|
|
|
|
foreach(ShaderNode *node, graph->nodes)
|
2013-12-31 16:30:34 +00:00
|
|
|
node->attributes(this, &attributes);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* compare if the attributes changed, mesh manager will check
|
2012-06-09 17:22:52 +00:00
|
|
|
* need_update_attributes, update the relevant meshes and clear it. */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(attributes.modified(prev_attributes)) {
|
|
|
|
need_update_attributes = true;
|
|
|
|
scene->mesh_manager->need_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 11:51:17 +00:00
|
|
|
void Shader::tag_used(Scene *scene)
|
|
|
|
{
|
|
|
|
/* if an unused shader suddenly gets used somewhere, it needs to be
|
|
|
|
* recompiled because it was skipped for compilation before */
|
|
|
|
if(!used) {
|
|
|
|
need_update = true;
|
|
|
|
scene->shader_manager->need_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Shader Manager */
|
|
|
|
|
|
|
|
ShaderManager::ShaderManager()
|
|
|
|
{
|
|
|
|
need_update = true;
|
2013-07-31 20:56:32 +00:00
|
|
|
blackbody_table_offset = TABLE_OFFSET_INVALID;
|
2014-06-20 19:21:05 +00:00
|
|
|
beckmann_table_offset = TABLE_OFFSET_INVALID;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderManager::~ShaderManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-04 07:48:09 +00:00
|
|
|
ShaderManager *ShaderManager::create(Scene *scene, int shadingsystem)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
ShaderManager *manager;
|
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
2014-05-19 10:49:36 +00:00
|
|
|
if(shadingsystem == SHADINGSYSTEM_OSL)
|
2011-04-27 11:58:34 +00:00
|
|
|
manager = new OSLShaderManager();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
manager = new SVMShaderManager();
|
|
|
|
|
|
|
|
add_default(scene);
|
|
|
|
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ShaderManager::get_attribute_id(ustring name)
|
|
|
|
{
|
|
|
|
/* get a unique id for each name, for SVM attribute lookup */
|
|
|
|
AttributeIDMap::iterator it = unique_attribute_id.find(name);
|
|
|
|
|
|
|
|
if(it != unique_attribute_id.end())
|
|
|
|
return it->second;
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
uint id = (uint)ATTR_STD_NUM + unique_attribute_id.size();
|
2011-04-27 11:58:34 +00:00
|
|
|
unique_attribute_id[name] = id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
uint ShaderManager::get_attribute_id(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
return (uint)std;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ShaderManager::get_shader_id(uint shader, Mesh *mesh, bool smooth)
|
|
|
|
{
|
|
|
|
/* get a shader id to pass to the kernel */
|
|
|
|
int id = shader*2;
|
|
|
|
|
|
|
|
/* index depends bump since this setting is not in the shader */
|
|
|
|
if(mesh && mesh->displacement_method != Mesh::DISPLACE_TRUE)
|
|
|
|
id += 1;
|
2011-09-27 20:37:24 +00:00
|
|
|
/* smooth flag */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(smooth)
|
2011-09-27 20:37:24 +00:00
|
|
|
id |= SHADER_SMOOTH_NORMAL;
|
|
|
|
|
|
|
|
/* default flags */
|
|
|
|
id |= SHADER_CAST_SHADOW|SHADER_AREA_LIGHT;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-10-30 11:51:17 +00:00
|
|
|
void ShaderManager::device_update_shaders_used(Scene *scene)
|
|
|
|
{
|
|
|
|
/* figure out which shaders are in use, so SVM/OSL can skip compiling them
|
|
|
|
* for speed and avoid loading image textures into memory */
|
|
|
|
foreach(Shader *shader, scene->shaders)
|
|
|
|
shader->used = false;
|
|
|
|
|
2013-06-28 13:05:21 +00:00
|
|
|
scene->shaders[scene->background->shader]->used = true;
|
2012-10-30 11:51:17 +00:00
|
|
|
scene->shaders[scene->default_surface]->used = true;
|
|
|
|
scene->shaders[scene->default_light]->used = true;
|
|
|
|
scene->shaders[scene->default_background]->used = true;
|
|
|
|
scene->shaders[scene->default_empty]->used = true;
|
|
|
|
|
|
|
|
foreach(Mesh *mesh, scene->meshes)
|
|
|
|
foreach(uint shader, mesh->used_shaders)
|
|
|
|
scene->shaders[shader]->used = true;
|
|
|
|
|
|
|
|
foreach(Light *light, scene->lights)
|
|
|
|
scene->shaders[light->shader]->used = true;
|
|
|
|
}
|
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
2013-04-01 20:26:52 +00:00
|
|
|
device->tex_free(dscene->shader_flag);
|
|
|
|
dscene->shader_flag.clear();
|
2011-09-27 20:37:24 +00:00
|
|
|
|
|
|
|
if(scene->shaders.size() == 0)
|
|
|
|
return;
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
uint shader_flag_size = scene->shaders.size()*4;
|
2011-09-27 20:37:24 +00:00
|
|
|
uint *shader_flag = dscene->shader_flag.resize(shader_flag_size);
|
|
|
|
uint i = 0;
|
2013-07-31 20:56:32 +00:00
|
|
|
bool has_converter_blackbody = false;
|
2013-12-28 01:27:48 +00:00
|
|
|
bool has_volumes = false;
|
2011-09-27 20:37:24 +00:00
|
|
|
|
|
|
|
foreach(Shader *shader, scene->shaders) {
|
|
|
|
uint flag = 0;
|
|
|
|
|
2013-06-18 09:36:00 +00:00
|
|
|
if(shader->use_mis)
|
|
|
|
flag |= SD_USE_MIS;
|
|
|
|
if(shader->has_surface_transparent && shader->use_transparent_shadow)
|
|
|
|
flag |= SD_HAS_TRANSPARENT_SHADOW;
|
2013-12-28 01:27:48 +00:00
|
|
|
if(shader->has_volume) {
|
2011-09-27 20:37:24 +00:00
|
|
|
flag |= SD_HAS_VOLUME;
|
2013-12-28 01:27:48 +00:00
|
|
|
has_volumes = true;
|
|
|
|
|
|
|
|
/* in this case we can assume transparent surface */
|
|
|
|
if(!shader->has_surface)
|
|
|
|
flag |= SD_HAS_ONLY_VOLUME;
|
|
|
|
|
|
|
|
/* todo: this could check more fine grained, to skip useless volumes
|
|
|
|
* enclosed inside an opaque bsdf, although we still need to handle
|
|
|
|
* the case with camera inside volumes too */
|
|
|
|
flag |= SD_HAS_TRANSPARENT_SHADOW;
|
|
|
|
}
|
2014-04-03 20:04:39 +00:00
|
|
|
if(shader->heterogeneous_volume && shader->has_heterogeneous_volume)
|
2013-12-29 21:19:38 +00:00
|
|
|
flag |= SD_HETEROGENEOUS_VOLUME;
|
2013-08-18 14:15:57 +00:00
|
|
|
if(shader->has_bssrdf_bump)
|
|
|
|
flag |= SD_HAS_BSSRDF_BUMP;
|
2013-07-31 20:56:32 +00:00
|
|
|
if(shader->has_converter_blackbody)
|
|
|
|
has_converter_blackbody = true;
|
2014-10-22 14:17:03 +00:00
|
|
|
if(shader->volume_sampling_method == VOLUME_SAMPLING_EQUIANGULAR)
|
2014-06-07 16:47:14 +00:00
|
|
|
flag |= SD_VOLUME_EQUIANGULAR;
|
2014-10-22 14:17:03 +00:00
|
|
|
if(shader->volume_sampling_method == VOLUME_SAMPLING_MULTIPLE_IMPORTANCE)
|
2014-06-07 16:47:14 +00:00
|
|
|
flag |= SD_VOLUME_MIS;
|
2014-10-22 14:17:03 +00:00
|
|
|
if(shader->volume_interpolation_method == VOLUME_INTERPOLATION_CUBIC)
|
2014-10-22 13:23:45 +00:00
|
|
|
flag |= SD_VOLUME_CUBIC;
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2013-08-18 14:15:57 +00:00
|
|
|
/* regular shader */
|
2011-09-27 20:37:24 +00:00
|
|
|
shader_flag[i++] = flag;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
shader_flag[i++] = shader->pass_id;
|
2013-08-18 14:15:57 +00:00
|
|
|
|
|
|
|
/* shader with bump mapping */
|
|
|
|
if(shader->graph_bump)
|
|
|
|
flag |= SD_HAS_BSSRDF_BUMP;
|
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
shader_flag[i++] = flag;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
shader_flag[i++] = shader->pass_id;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device->tex_alloc("__shader_flag", dscene->shader_flag);
|
2013-04-01 20:26:52 +00:00
|
|
|
|
2013-07-31 20:56:32 +00:00
|
|
|
/* blackbody lookup table */
|
2014-06-20 19:21:05 +00:00
|
|
|
KernelTables *ktables = &dscene->data.tables;
|
2013-07-31 20:56:32 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-06-20 19:21:05 +00:00
|
|
|
ktables->blackbody_offset = (int)blackbody_table_offset;
|
2013-07-31 20:56:32 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-20 19:21:05 +00:00
|
|
|
/* beckmann lookup table */
|
|
|
|
if(beckmann_table_offset == TABLE_OFFSET_INVALID) {
|
|
|
|
vector<float> table;
|
|
|
|
beckmann_table_build(table);
|
|
|
|
beckmann_table_offset = scene->lookup_tables->add_table(dscene, table);
|
|
|
|
|
|
|
|
ktables->beckmann_offset = (int)beckmann_table_offset;
|
|
|
|
}
|
|
|
|
|
2014-06-01 05:11:13 +00:00
|
|
|
/* integrator */
|
2013-12-28 01:27:48 +00:00
|
|
|
KernelIntegrator *kintegrator = &dscene->data.integrator;
|
|
|
|
kintegrator->use_volumes = has_volumes;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
void ShaderManager::device_free_common(Device *device, DeviceScene *dscene, Scene *scene)
|
2011-09-27 20:37:24 +00:00
|
|
|
{
|
2013-07-31 20:56:32 +00:00
|
|
|
if(blackbody_table_offset != TABLE_OFFSET_INVALID) {
|
|
|
|
scene->lookup_tables->remove_table(blackbody_table_offset);
|
|
|
|
blackbody_table_offset = TABLE_OFFSET_INVALID;
|
|
|
|
}
|
|
|
|
|
2014-06-20 19:21:05 +00:00
|
|
|
if(beckmann_table_offset != TABLE_OFFSET_INVALID) {
|
|
|
|
scene->lookup_tables->remove_table(beckmann_table_offset);
|
|
|
|
beckmann_table_offset = TABLE_OFFSET_INVALID;
|
|
|
|
}
|
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
device->tex_free(dscene->shader_flag);
|
|
|
|
dscene->shader_flag.clear();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void ShaderManager::add_default(Scene *scene)
|
|
|
|
{
|
|
|
|
Shader *shader;
|
|
|
|
ShaderGraph *graph;
|
|
|
|
ShaderNode *closure, *out;
|
|
|
|
|
|
|
|
/* default surface */
|
|
|
|
{
|
|
|
|
graph = new ShaderGraph();
|
|
|
|
|
|
|
|
closure = graph->add(new DiffuseBsdfNode());
|
|
|
|
closure->input("Color")->value = make_float3(0.8f, 0.8f, 0.8f);
|
|
|
|
out = graph->output();
|
|
|
|
|
2011-10-12 23:03:12 +00:00
|
|
|
graph->connect(closure->output("BSDF"), out->input("Surface"));
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
shader = new Shader();
|
|
|
|
shader->name = "default_surface";
|
|
|
|
shader->graph = graph;
|
|
|
|
scene->shaders.push_back(shader);
|
|
|
|
scene->default_surface = scene->shaders.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default light */
|
|
|
|
{
|
|
|
|
graph = new ShaderGraph();
|
|
|
|
|
|
|
|
closure = graph->add(new EmissionNode());
|
|
|
|
closure->input("Color")->value = make_float3(0.8f, 0.8f, 0.8f);
|
|
|
|
closure->input("Strength")->value.x = 0.0f;
|
|
|
|
out = graph->output();
|
|
|
|
|
2011-10-12 23:03:12 +00:00
|
|
|
graph->connect(closure->output("Emission"), out->input("Surface"));
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
shader = new Shader();
|
|
|
|
shader->name = "default_light";
|
|
|
|
shader->graph = graph;
|
|
|
|
scene->shaders.push_back(shader);
|
|
|
|
scene->default_light = scene->shaders.size() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default background */
|
|
|
|
{
|
|
|
|
graph = new ShaderGraph();
|
|
|
|
|
|
|
|
shader = new Shader();
|
|
|
|
shader->name = "default_background";
|
|
|
|
shader->graph = graph;
|
|
|
|
scene->shaders.push_back(shader);
|
|
|
|
scene->default_background = scene->shaders.size() - 1;
|
|
|
|
}
|
2012-02-28 16:44:45 +00:00
|
|
|
|
2012-04-13 12:58:12 +00:00
|
|
|
/* default empty */
|
|
|
|
{
|
|
|
|
graph = new ShaderGraph();
|
|
|
|
|
|
|
|
shader = new Shader();
|
|
|
|
shader->name = "default_empty";
|
|
|
|
shader->graph = graph;
|
|
|
|
scene->shaders.push_back(shader);
|
|
|
|
scene->default_empty = scene->shaders.size() - 1;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|