Code refactor: nodify Cycles shader and lights.
Differential Revision: https://developer.blender.org/D2016
This commit is contained in:
@@ -341,8 +341,10 @@ static string xml_socket_name(const char *name)
|
||||
return sname;
|
||||
}
|
||||
|
||||
static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pugi::xml_node graph_node)
|
||||
static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml_node graph_node)
|
||||
{
|
||||
xml_read_node(state, shader, graph_node);
|
||||
|
||||
ShaderGraph *graph = new ShaderGraph();
|
||||
|
||||
map<string, ShaderNode*> nodemap;
|
||||
@@ -802,25 +804,9 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
|
||||
shader->tag_update(state.scene);
|
||||
}
|
||||
|
||||
static void xml_read_shader(const XMLReadState& state, pugi::xml_node node)
|
||||
static void xml_read_shader(XMLReadState& state, pugi::xml_node node)
|
||||
{
|
||||
Shader *shader = new Shader();
|
||||
|
||||
xml_read_string(&shader->name, node, "name");
|
||||
xml_read_bool(&shader->use_mis, node, "use_mis");
|
||||
xml_read_bool(&shader->use_transparent_shadow, node, "use_transparent_shadow");
|
||||
|
||||
/* Volume */
|
||||
xml_read_bool(&shader->heterogeneous_volume, node, "heterogeneous_volume");
|
||||
xml_read_int(&shader->volume_interpolation_method, node, "volume_interpolation_method");
|
||||
|
||||
if(xml_equal_string(node, "volume_sampling_method", "distance"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_DISTANCE;
|
||||
else if(xml_equal_string(node, "volume_sampling_method", "equiangular"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_EQUIANGULAR;
|
||||
else if(xml_equal_string(node, "volume_sampling_method", "multiple_importance"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_MULTIPLE_IMPORTANCE;
|
||||
|
||||
xml_read_shader_graph(state, shader, node);
|
||||
state.scene->shaders.push_back(shader);
|
||||
}
|
||||
@@ -834,17 +820,6 @@ static void xml_read_background(XMLReadState& state, pugi::xml_node node)
|
||||
|
||||
/* Background Shader */
|
||||
Shader *shader = state.scene->default_background;
|
||||
|
||||
xml_read_bool(&shader->heterogeneous_volume, node, "heterogeneous_volume");
|
||||
xml_read_int(&shader->volume_interpolation_method, node, "volume_interpolation_method");
|
||||
|
||||
if(xml_equal_string(node, "volume_sampling_method", "distance"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_DISTANCE;
|
||||
else if(xml_equal_string(node, "volume_sampling_method", "equiangular"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_EQUIANGULAR;
|
||||
else if(xml_equal_string(node, "volume_sampling_method", "multiple_importance"))
|
||||
shader->volume_sampling_method = VOLUME_SAMPLING_MULTIPLE_IMPORTANCE;
|
||||
|
||||
xml_read_shader_graph(state, shader, node);
|
||||
}
|
||||
|
||||
@@ -1047,47 +1022,12 @@ static void xml_read_patch(const XMLReadState& state, pugi::xml_node node)
|
||||
|
||||
/* Light */
|
||||
|
||||
static void xml_read_light(const XMLReadState& state, pugi::xml_node node)
|
||||
static void xml_read_light(XMLReadState& state, pugi::xml_node node)
|
||||
{
|
||||
Light *light = new Light();
|
||||
|
||||
light->shader = state.shader;
|
||||
|
||||
/* Light Type
|
||||
* 0: Point, 1: Sun, 3: Area, 5: Spot */
|
||||
int type = 0;
|
||||
xml_read_int(&type, node, "type");
|
||||
light->type = (LightType)type;
|
||||
|
||||
/* Spot Light */
|
||||
xml_read_float(&light->spot_angle, node, "spot_angle");
|
||||
xml_read_float(&light->spot_smooth, node, "spot_smooth");
|
||||
|
||||
/* Area Light */
|
||||
xml_read_float(&light->sizeu, node, "sizeu");
|
||||
xml_read_float(&light->sizev, node, "sizev");
|
||||
xml_read_float3(&light->axisu, node, "axisu");
|
||||
xml_read_float3(&light->axisv, node, "axisv");
|
||||
|
||||
/* Portal? (Area light only) */
|
||||
xml_read_bool(&light->is_portal, node, "is_portal");
|
||||
|
||||
/* Generic */
|
||||
xml_read_float(&light->size, node, "size");
|
||||
xml_read_float3(&light->dir, node, "dir");
|
||||
xml_read_float3(&light->co, node, "P");
|
||||
light->co = transform_point(&state.tfm, light->co);
|
||||
|
||||
/* Settings */
|
||||
xml_read_bool(&light->cast_shadow, node, "cast_shadow");
|
||||
xml_read_bool(&light->use_mis, node, "use_mis");
|
||||
xml_read_int(&light->samples, node, "samples");
|
||||
xml_read_int(&light->max_bounces, node, "max_bounces");
|
||||
|
||||
/* Ray Visibility */
|
||||
xml_read_bool(&light->use_diffuse, node, "use_diffuse");
|
||||
xml_read_bool(&light->use_glossy, node, "use_glossy");
|
||||
xml_read_bool(&light->use_transmission, node, "use_transmission");
|
||||
xml_read_bool(&light->use_scatter, node, "use_scatter");
|
||||
xml_read_node(state, light, node);
|
||||
|
||||
state.scene->lights.push_back(light);
|
||||
}
|
||||
|
||||
@@ -40,13 +40,14 @@ NODE_DEFINE(Background)
|
||||
SOCKET_INT(visibility, "Visibility", PATH_RAY_ALL_VISIBILITY);
|
||||
SOCKET_BOOLEAN(transparent, "Transparent", false);
|
||||
|
||||
SOCKET_NODE(shader, "Shader", &Shader::node_type);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
Background::Background()
|
||||
: Node(node_type)
|
||||
{
|
||||
shader = NULL;
|
||||
need_update = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ CCL_NAMESPACE_BEGIN
|
||||
|
||||
class Device;
|
||||
class DeviceScene;
|
||||
class Shader;
|
||||
class Scene;
|
||||
class Shader;
|
||||
|
||||
class Background : public Node {
|
||||
public:
|
||||
|
||||
@@ -100,38 +100,53 @@ static void shade_background_pixels(Device *device, DeviceScene *dscene, int res
|
||||
|
||||
/* Light */
|
||||
|
||||
Light::Light()
|
||||
NODE_DEFINE(Light)
|
||||
{
|
||||
type = LIGHT_POINT;
|
||||
NodeType* type = NodeType::add("light", create);
|
||||
|
||||
co = make_float3(0.0f, 0.0f, 0.0f);
|
||||
static NodeEnum type_enum;
|
||||
type_enum.insert("point", LIGHT_POINT);
|
||||
type_enum.insert("background", LIGHT_BACKGROUND);
|
||||
type_enum.insert("area", LIGHT_AREA);
|
||||
type_enum.insert("spot", LIGHT_SPOT);
|
||||
SOCKET_ENUM(type, "Type", type_enum, LIGHT_POINT);
|
||||
|
||||
dir = make_float3(0.0f, 0.0f, 0.0f);
|
||||
size = 0.0f;
|
||||
SOCKET_POINT(co, "Co", make_float3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
axisu = make_float3(0.0f, 0.0f, 0.0f);
|
||||
sizeu = 1.0f;
|
||||
axisv = make_float3(0.0f, 0.0f, 0.0f);
|
||||
sizev = 1.0f;
|
||||
SOCKET_VECTOR(dir, "Dir", make_float3(0.0f, 0.0f, 0.0f));
|
||||
SOCKET_FLOAT(size, "Size", 0.0f);
|
||||
|
||||
map_resolution = 512;
|
||||
SOCKET_VECTOR(axisu, "Axis U", make_float3(0.0f, 0.0f, 0.0f));
|
||||
SOCKET_FLOAT(sizeu, "Size U", 1.0f);
|
||||
SOCKET_VECTOR(axisv, "Axis V", make_float3(0.0f, 0.0f, 0.0f));
|
||||
SOCKET_FLOAT(sizev, "Size V", 1.0f);
|
||||
|
||||
spot_angle = M_PI_4_F;
|
||||
spot_smooth = 0.0f;
|
||||
SOCKET_INT(map_resolution, "Map Resolution", 512);
|
||||
|
||||
cast_shadow = true;
|
||||
use_mis = false;
|
||||
use_diffuse = true;
|
||||
use_glossy = true;
|
||||
use_transmission = true;
|
||||
use_scatter = true;
|
||||
SOCKET_FLOAT(spot_angle, "Spot Angle", M_PI_4_F);
|
||||
SOCKET_FLOAT(spot_smooth, "Spot Smooth", 0.0f);
|
||||
|
||||
shader = NULL;
|
||||
samples = 1;
|
||||
max_bounces = 1024;
|
||||
SOCKET_BOOLEAN(cast_shadow, "Cast Shadow", true);
|
||||
SOCKET_BOOLEAN(use_mis, "Use Mis", false);
|
||||
SOCKET_BOOLEAN(use_diffuse, "Use Diffuse", true);
|
||||
SOCKET_BOOLEAN(use_glossy, "Use Glossy", true);
|
||||
SOCKET_BOOLEAN(use_transmission, "Use Transmission", true);
|
||||
SOCKET_BOOLEAN(use_scatter, "Use Scatter", true);
|
||||
|
||||
is_portal = false;
|
||||
is_enabled = true;
|
||||
SOCKET_INT(samples, "Samples", 1);
|
||||
SOCKET_INT(max_bounces, "Max Bounces", 1024);
|
||||
|
||||
SOCKET_BOOLEAN(is_portal, "Is Portal", false);
|
||||
SOCKET_BOOLEAN(is_enabled, "Is Enabled", true);
|
||||
|
||||
SOCKET_NODE(shader, "Shader", &Shader::node_type);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
Light::Light()
|
||||
: Node(node_type)
|
||||
{
|
||||
}
|
||||
|
||||
void Light::tag_update(Scene *scene)
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "kernel_types.h"
|
||||
|
||||
#include "node.h"
|
||||
|
||||
#include "util_types.h"
|
||||
#include "util_vector.h"
|
||||
|
||||
@@ -27,11 +29,13 @@ CCL_NAMESPACE_BEGIN
|
||||
class Device;
|
||||
class DeviceScene;
|
||||
class Progress;
|
||||
class Shader;
|
||||
class Scene;
|
||||
class Shader;
|
||||
|
||||
class Light {
|
||||
class Light : public Node {
|
||||
public:
|
||||
NODE_DECLARE;
|
||||
|
||||
Light();
|
||||
|
||||
LightType type;
|
||||
|
||||
@@ -131,20 +131,36 @@ static void beckmann_table_build(vector<float>& table)
|
||||
|
||||
/* Shader */
|
||||
|
||||
Shader::Shader()
|
||||
NODE_DEFINE(Shader)
|
||||
{
|
||||
NodeType* type = NodeType::add("shader", create);
|
||||
|
||||
SOCKET_BOOLEAN(use_mis, "Use MIS", true);
|
||||
SOCKET_BOOLEAN(use_transparent_shadow, "Use Transparent Shadow", true);
|
||||
SOCKET_BOOLEAN(heterogeneous_volume, "Heterogeneous Volume", true);
|
||||
|
||||
static NodeEnum volume_sampling_method_enum;
|
||||
volume_sampling_method_enum.insert("distance", VOLUME_SAMPLING_DISTANCE);
|
||||
volume_sampling_method_enum.insert("equiangular", VOLUME_SAMPLING_EQUIANGULAR);
|
||||
volume_sampling_method_enum.insert("multiple_importance", VOLUME_SAMPLING_MULTIPLE_IMPORTANCE);
|
||||
SOCKET_ENUM(volume_sampling_method, "Volume Sampling Method", volume_sampling_method_enum, VOLUME_SAMPLING_DISTANCE);
|
||||
|
||||
static NodeEnum volume_interpolation_method_enum;
|
||||
volume_interpolation_method_enum.insert("linear", VOLUME_INTERPOLATION_LINEAR);
|
||||
volume_interpolation_method_enum.insert("cubic", VOLUME_INTERPOLATION_CUBIC);
|
||||
SOCKET_ENUM(volume_interpolation_method, "Volume Interpolation Method", volume_interpolation_method_enum, VOLUME_INTERPOLATION_LINEAR);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
Shader::Shader()
|
||||
: Node(node_type)
|
||||
{
|
||||
name = "";
|
||||
pass_id = 0;
|
||||
|
||||
graph = NULL;
|
||||
graph_bump = NULL;
|
||||
|
||||
use_mis = true;
|
||||
use_transparent_shadow = true;
|
||||
heterogeneous_volume = true;
|
||||
volume_sampling_method = VOLUME_SAMPLING_DISTANCE;
|
||||
volume_interpolation_method = VOLUME_INTERPOLATION_LINEAR;
|
||||
|
||||
has_surface = false;
|
||||
has_surface_transparent = false;
|
||||
has_surface_emission = false;
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "attribute.h"
|
||||
#include "kernel_types.h"
|
||||
|
||||
#include "node.h"
|
||||
|
||||
#include "util_map.h"
|
||||
#include "util_param.h"
|
||||
#include "util_string.h"
|
||||
@@ -70,10 +72,10 @@ enum VolumeInterpolation {
|
||||
* volume and displacement, that the shader manager will compile and execute
|
||||
* separately. */
|
||||
|
||||
class Shader {
|
||||
class Shader : public Node {
|
||||
public:
|
||||
/* name */
|
||||
string name;
|
||||
NODE_DECLARE;
|
||||
|
||||
int pass_id;
|
||||
|
||||
/* shader graph */
|
||||
|
||||
Reference in New Issue
Block a user