Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2016-05-08 01:18:32 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2016-05-22 18:29:25 +0300
commit9b9921b765bca2dacc7ec0633dcf0ab1ab68be68 (patch)
tree0eb5a3745a9eeb6596ba230a2de941fc5b0baa31
parente7d13b8a1da046d7bb78a3c0e21bbb575ed6074e (diff)
Code refactor: nodify Cycles shader and lights.
Differential Revision: https://developer.blender.org/D2016
-rw-r--r--intern/cycles/app/cycles_xml.cpp74
-rw-r--r--intern/cycles/render/background.cpp3
-rw-r--r--intern/cycles/render/background.h2
-rw-r--r--intern/cycles/render/light.cpp61
-rw-r--r--intern/cycles/render/light.h8
-rw-r--r--intern/cycles/render/shader.cpp30
-rw-r--r--intern/cycles/render/shader.h8
7 files changed, 82 insertions, 104 deletions
diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 7f262c709e0..dc0c4f68898 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -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");
+ light->shader = state.shader;
+ xml_read_node(state, light, node);
state.scene->lights.push_back(light);
}
diff --git a/intern/cycles/render/background.cpp b/intern/cycles/render/background.cpp
index 28ca04fe615..6f8d1d1d461 100644
--- a/intern/cycles/render/background.cpp
+++ b/intern/cycles/render/background.cpp
@@ -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;
}
diff --git a/intern/cycles/render/background.h b/intern/cycles/render/background.h
index ae2ffe2b078..843655b00a1 100644
--- a/intern/cycles/render/background.h
+++ b/intern/cycles/render/background.h
@@ -25,8 +25,8 @@ CCL_NAMESPACE_BEGIN
class Device;
class DeviceScene;
-class Shader;
class Scene;
+class Shader;
class Background : public Node {
public:
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 91a9f22276f..c20bf6b5e9e 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -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);
+
+ 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);
+
+ SOCKET_POINT(co, "Co", make_float3(0.0f, 0.0f, 0.0f));
+
+ SOCKET_VECTOR(dir, "Dir", make_float3(0.0f, 0.0f, 0.0f));
+ SOCKET_FLOAT(size, "Size", 0.0f);
- co = make_float3(0.0f, 0.0f, 0.0f);
+ 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);
- dir = make_float3(0.0f, 0.0f, 0.0f);
- size = 0.0f;
+ SOCKET_INT(map_resolution, "Map Resolution", 512);
- 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_FLOAT(spot_angle, "Spot Angle", M_PI_4_F);
+ SOCKET_FLOAT(spot_smooth, "Spot Smooth", 0.0f);
- map_resolution = 512;
+ 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);
- spot_angle = M_PI_4_F;
- spot_smooth = 0.0f;
+ SOCKET_INT(samples, "Samples", 1);
+ SOCKET_INT(max_bounces, "Max Bounces", 1024);
- cast_shadow = true;
- use_mis = false;
- use_diffuse = true;
- use_glossy = true;
- use_transmission = true;
- use_scatter = true;
+ SOCKET_BOOLEAN(is_portal, "Is Portal", false);
+ SOCKET_BOOLEAN(is_enabled, "Is Enabled", true);
- shader = NULL;
- samples = 1;
- max_bounces = 1024;
+ SOCKET_NODE(shader, "Shader", &Shader::node_type);
- is_portal = false;
- is_enabled = true;
+ return type;
+}
+
+Light::Light()
+: Node(node_type)
+{
}
void Light::tag_update(Scene *scene)
diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h
index 24ca0157eba..2f1df1c9417 100644
--- a/intern/cycles/render/light.h
+++ b/intern/cycles/render/light.h
@@ -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;
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index 1453958a0aa..b140af66b5b 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -131,20 +131,36 @@ static void beckmann_table_build(vector<float>& table)
/* 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;
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index 4a1502cb86d..dc57ed4e4eb 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -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 */