[Bf-blender-cvs] [3f3f672] bake-cycles: Cycles-Bake: basic structure to run different baking routines depending on the pass_type

Dalai Felinto noreply at git.blender.org
Wed Apr 23 02:46:30 CEST 2014


Commit: 3f3f6727607279c44dea62a59ebef2e37dd6a0ab
Author: Dalai Felinto
Date:   Tue Jan 14 16:17:43 2014 -0200
https://developer.blender.org/rB3f3f6727607279c44dea62a59ebef2e37dd6a0ab

Cycles-Bake: basic structure to run different baking routines depending on the
pass_type

I'm failing to have this in bake.cpp by the way. Notes in
blender_session.cpp

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

M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_session.h
M	intern/cycles/render/CMakeLists.txt
M	intern/cycles/render/bake.cpp
A	intern/cycles/render/bake.h

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

diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index ea0af5e..3de3fb6 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -14,6 +14,8 @@
  * limitations under the License
  */
 
+#include <stdlib.h>
+
 #include "background.h"
 #include "buffers.h"
 #include "camera.h"
@@ -270,6 +272,77 @@ static PassType get_pass_type(BL::RenderPass b_pass)
 	return PASS_NONE;
 }
 
+static PassType get_pass_type(const string& s_pass_type)
+{
+	const char *pass_type = s_pass_type.c_str();
+
+	if (strcmp(pass_type, "COMBINED")==0)
+		return PASS_COMBINED;
+	else if (strcmp(pass_type, "Z")==0)
+		return PASS_DEPTH;
+
+	else if (strcmp(pass_type, "Z")==0)
+		return PASS_DEPTH;
+	else if (strcmp(pass_type, "MIST")==0)
+		return PASS_MIST;
+	else if (strcmp(pass_type, "NORMAL")==0)
+		return PASS_NORMAL;
+	else if (strcmp(pass_type, "OBJECT_INDEX")==0)
+		return PASS_OBJECT_ID;
+	else if (strcmp(pass_type, "UV")==0)
+		return PASS_UV;
+	else if (strcmp(pass_type, "VECTOR")==0)
+		return PASS_MOTION;
+	else if (strcmp(pass_type, "MATERIAL_INDEX")==0)
+		return PASS_MATERIAL_ID;
+
+	else if (strcmp(pass_type, "DIFFUSE_DIRECT")==0)
+		return PASS_DIFFUSE_DIRECT;
+	else if (strcmp(pass_type, "GLOSSY_DIRECT")==0)
+		return PASS_GLOSSY_DIRECT;
+	else if (strcmp(pass_type, "TRANSMISSION_DIRECT")==0)
+		return PASS_TRANSMISSION_DIRECT;
+	else if (strcmp(pass_type, "SUBSURFACE_DIRECT")==0)
+		return PASS_SUBSURFACE_DIRECT;
+
+	else if (strcmp(pass_type, "DIFFUSE_INDIRECT")==0)
+		return PASS_DIFFUSE_INDIRECT;
+	else if (strcmp(pass_type, "GLOSSY_INDIRECT")==0)
+		return PASS_GLOSSY_INDIRECT;
+	else if (strcmp(pass_type, "TRANSMISSION_INDIRECT")==0)
+		return PASS_TRANSMISSION_INDIRECT;
+	else if (strcmp(pass_type, "SUBSURFACE_INDIRECT")==0)
+		return PASS_SUBSURFACE_INDIRECT;
+
+	else if (strcmp(pass_type, "DIFFUSE_COLOR")==0)
+		return PASS_DIFFUSE_COLOR;
+	else if (strcmp(pass_type, "GLOSSY_COLOR")==0)
+		return PASS_GLOSSY_COLOR;
+	else if (strcmp(pass_type, "TRANSMISSION_COLOR")==0)
+		return PASS_TRANSMISSION_COLOR;
+	else if (strcmp(pass_type, "SUBSURFACE_COLOR")==0)
+		return PASS_SUBSURFACE_COLOR;
+
+	else if (strcmp(pass_type, "EMIT")==0)
+		return PASS_EMISSION;
+	else if (strcmp(pass_type, "ENVIRONMENT")==0)
+		return PASS_BACKGROUND;
+	else if (strcmp(pass_type, "AO")==0)
+		return PASS_AO;
+	else if (strcmp(pass_type, "SHADOW")==0)
+		return PASS_SHADOW;
+
+	/*
+	else if (strcmp(pass_type, "DIFFUSE")==0)
+	else if (strcmp(pass_type, "COLOR")==0)
+	else if (strcmp(pass_type, "REFRACTION")==0)
+	else if (strcmp(pass_type, "SPECULAR")==0)
+	else if (strcmp(pass_type, "REFLECTION")==0)
+		*/
+	else
+		return PASS_NONE;
+}
+
 static BL::RenderResult begin_render_result(BL::RenderEngine b_engine, int x, int y, int w, int h, const char *layername)
 {
 	return b_engine.begin_result(x, y, w, h, layername);
@@ -436,7 +509,14 @@ void BlenderSession::render()
 	sync = NULL;
 }
 
-void BlenderSession::bake(BL::Object b_object, const string& pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[])
+
+/* XXX I would like those to be in bake.cpp, but I'm running into some namespace problems for that
+   (BL:: is nowhere defined) - I can move the bake to inside 'blender', but that doesn't sound correct
+   I believe the fix is to get the bare minimum to the _bake functions, and not to pass the entire blender
+   object there.
+ */
+#if 1
+void _bake_uv(BL::Object b_object, PassType pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[])
 {
 	/* just plots the internal uv back to the results for now */
 	for (int i=0; i < num_pixels; i++) {
@@ -445,6 +525,38 @@ void BlenderSession::bake(BL::Object b_object, const string& pass_type, BakePixe
 		result[offset + 1] = pixel_array[i].v;
 	}
 }
+#else
+void _bake_uv(BL::Object b_object, PassType pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[]) {}
+#endif
+
+void _bake_background(BL::Object b_object, PassType pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[]) {}
+
+void _bake_combined(BL::Object b_object, PassType pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[]) {}
+
+void _bake_depth(BL::Object b_object, PassType pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[]) {}
+
+void BlenderSession::bake(BL::Object b_object, const string& s_pass_type, BakePixel *pixel_array, int num_pixels, int depth, float result[])
+{
+	/* XXX temporary function until we get real pass_types (int) instead of strings */
+	PassType pass_type = get_pass_type(s_pass_type);
+
+	switch(pass_type) {
+		case PASS_UV:
+			_bake_uv(b_object, pass_type, pixel_array, num_pixels, depth, result);
+			break;
+		case PASS_BACKGROUND:
+			_bake_background(b_object, pass_type, pixel_array, num_pixels, depth, result);
+			break;
+		case PASS_COMBINED:
+			_bake_combined(b_object, pass_type, pixel_array, num_pixels, depth, result);
+			break;
+		case PASS_DEPTH:
+			_bake_depth(b_object, pass_type, pixel_array, num_pixels, depth, result);
+			break;
+		default:
+			break;
+	}
+}
 
 void BlenderSession::do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only)
 {
diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h
index c1f69c2..640d29a 100644
--- a/intern/cycles/blender/blender_session.h
+++ b/intern/cycles/blender/blender_session.h
@@ -20,6 +20,7 @@
 #include "device.h"
 #include "scene.h"
 #include "session.h"
+#include "bake.h"
 
 #include "util_vector.h"
 
@@ -30,16 +31,6 @@ class Session;
 class RenderBuffers;
 class RenderTile;
 
-struct BakePixel;
-
-/* plain copy from Blender */
-typedef struct BakePixel {
-	int primitive_id;
-	float u, v;
-	float dudx, dudy;
-	float dvdx, dvdy;
-} BakePixel;
-
 class BlenderSession {
 public:
 	BlenderSession(BL::RenderEngine b_engine, BL::UserPreferences b_userpref,
diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt
index 7d00ed9..449c139 100644
--- a/intern/cycles/render/CMakeLists.txt
+++ b/intern/cycles/render/CMakeLists.txt
@@ -16,6 +16,7 @@ set(INC_SYS
 set(SRC
 	attribute.cpp
 	background.cpp
+	bake.cpp
 	blackbody.cpp
 	buffers.cpp
 	camera.cpp
@@ -43,6 +44,7 @@ set(SRC
 
 set(SRC_HEADERS
 	attribute.h
+	bake.h
 	background.h
 	blackbody.h
 	buffers.h
diff --git a/intern/cycles/render/bake.cpp b/intern/cycles/render/bake.cpp
index 8b13789..ef16a41 100644
--- a/intern/cycles/render/bake.cpp
+++ b/intern/cycles/render/bake.cpp
@@ -1 +1,22 @@
+/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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
+ */
+
+#include "bake.h"
+
+CCL_NAMESPACE_BEGIN
+
+CCL_NAMESPACE_END
 
diff --git a/intern/cycles/render/bake.h b/intern/cycles/render/bake.h
new file mode 100644
index 0000000..a9d05e2
--- /dev/null
+++ b/intern/cycles/render/bake.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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
+ */
+
+#ifndef __BAKE_H__
+#define __BAKE_H__
+
+#include "util_vector.h"
+#include "device.h"
+#include "scene.h"
+#include "session.h"
+#include "bake.h"
+
+CCL_NAMESPACE_BEGIN
+
+struct BakePixel;
+
+/* plain copy from Blender */
+typedef struct BakePixel {
+	int primitive_id;
+	float u, v;
+	float dudx, dudy;
+	float dvdx, dvdy;
+} BakePixel;
+
+//void do_bake(BL::Object b_object, const string& pass_type, BakePixel pixel_array[], int num_pixels, int depth, float pixels[]);
+
+CCL_NAMESPACE_END
+
+#endif /* __BAKE_H__ */
+




More information about the Bf-blender-cvs mailing list