[Bf-blender-cvs] [9b9921b] master: Code refactor: nodify Cycles shader and lights.

Brecht Van Lommel noreply at git.blender.org
Sun May 22 18:16:16 CEST 2016


Commit: 9b9921b765bca2dacc7ec0633dcf0ab1ab68be68
Author: Brecht Van Lommel
Date:   Sun May 8 00:18:32 2016 +0200
Branches: master
https://developer.blender.org/rB9b9921b765bca2dacc7ec0633dcf0ab1ab68be68

Code refactor: nodify Cycles shader and lights.

Differential Revision: https://developer.blender.org/D2016

===================================================================

M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/render/background.cpp
M	intern/cycles/render/background.h
M	intern/cycles/render/light.cpp
M	intern/cycles/render/light.h
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h

===================================================================

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 7f262c7..dc0c4f6 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 28ca04f..6f8d1d1 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 ae2ffe2..843655b 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 91a9f22..c20bf6b 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 24ca015..2f1df1c 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 1453958..b140af6 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 4a1502c..dc57ed4 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_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list