[Bf-blender-cvs] [d8fa169] cycles_disney_brdf: added vessel for disney diffuse shader

Pascal Schoen noreply at git.blender.org
Mon May 30 09:08:51 CEST 2016


Commit: d8fa169bf3caf71c40a124101b33dee6c510188e
Author: Pascal Schoen
Date:   Mon Apr 18 08:41:53 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rBd8fa169bf3caf71c40a124101b33dee6c510188e

added vessel for disney diffuse shader

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

M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/closure/bsdf.h
A	intern/cycles/kernel/closure/bsdf_disney_diffuse.h
M	intern/cycles/kernel/osl/CMakeLists.txt
A	intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp
M	intern/cycles/kernel/osl/osl_closures.cpp
M	intern/cycles/kernel/osl/osl_closures.h
M	intern/cycles/kernel/shaders/CMakeLists.txt
A	intern/cycles/kernel/shaders/node_disney_bsdf.osl
M	intern/cycles/kernel/shaders/stdosl.h
M	intern/cycles/kernel/svm/svm_types.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_shader.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c

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

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index f734d01..1165db7 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -514,6 +514,9 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
 		else if(string_iequals(node.name(), "diffuse_bsdf")) {
 			snode = new DiffuseBsdfNode();
 		}
+		/*else if(string_iequals(node.name(), "disney_bsdf")) {
+			snode = new DisneyBsdfNode();
+		}*/
 		else if(string_iequals(node.name(), "translucent_bsdf")) {
 			snode = new TranslucentBsdfNode();
 		}
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index a56c2e7..908cdb0 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -522,6 +522,9 @@ static ShaderNode *add_node(Scene *scene,
 		}
 		node = hair;
 	}
+	/*else if(b_node.is_a(&RNA_ShaderNodeBsdfDisney)) {
+		node = new DisneyBsdfNode();
+    }*/
 	else if(b_node.is_a(&RNA_ShaderNodeBsdfTranslucent)) {
 		node = new TranslucentBsdfNode();
 	}
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 7c2fc1e..ba5c06a 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -88,6 +88,7 @@ set(SRC_CLOSURE_HEADERS
 	closure/bssrdf.h
 	closure/emissive.h
 	closure/volume.h
+    closure/bsdf_disney_diffuse.h
 )
 
 set(SRC_SVM_HEADERS
diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h
index f0add80..f40ed38 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -26,6 +26,7 @@
 #include "../closure/bsdf_ashikhmin_shirley.h"
 #include "../closure/bsdf_toon.h"
 #include "../closure/bsdf_hair.h"
+#include "../closure/bsdf_disney_diffuse.h"
 #ifdef __SUBSURFACE__
 #  include "../closure/bssrdf.h"
 #endif
diff --git a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
new file mode 100644
index 0000000..2b927c5
--- /dev/null
+++ b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
@@ -0,0 +1,89 @@
+/*
+ * Adapted from Open Shading Language with this license:
+ *
+ * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
+ * All Rights Reserved.
+ *
+ * Modifications Copyright 2011, Blender Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sony Pictures Imageworks nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __BSDF_DISNEY_DIFFUSE_
+#define __BSDF_DISNEY_DIFFUSE_H__
+
+CCL_NAMESPACE_BEGIN
+
+/* DIFFUSE */
+
+ccl_device int bsdf_disney_diffuse_setup(ShaderClosure *sc)
+{
+	sc->type = CLOSURE_BSDF_DISNEY_DIFFUSE_ID;
+	return SD_BSDF|SD_BSDF_HAS_EVAL;
+}
+
+ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc,
+        float3 color, const float3 I, const float3 omega_in, float *pdf)
+{
+	float3 N = sc->N;
+
+	float cos_pi = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
+	*pdf = cos_pi;
+	return make_float3(cos_pi * color[0], cos_pi * color[1], cos_pi * color[2]);
+}
+
+ccl_device float3 bsdf_disney_diffuse_eval_transmit(const ShaderClosure *sc,
+        float3 color, const float3 I, const float3 omega_in, float *pdf)
+{
+	return make_float3(0.0f, 0.0f, 0.0f);
+}
+
+ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, float3 color,
+        float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv,
+        float3 *eval, float3 *omega_in, float3 *domega_in_dx,
+        float3 *domega_in_dy, float *pdf)
+{
+	float3 N = sc->N;
+
+	// distribution over the hemisphere
+	sample_cos_hemisphere(N, randu, randv, omega_in, pdf);
+
+	if(dot(Ng, *omega_in) > 0.0f) {
+		*eval = make_float3(*pdf * color[0], *pdf * color[1], *pdf * color[2]);
+#ifdef __RAY_DIFFERENTIALS__
+		// TODO: find a better approximation for the diffuse bounce
+		*domega_in_dx = (2 * dot(N, dIdx)) * N - dIdx;
+		*domega_in_dy = (2 * dot(N, dIdy)) * N - dIdy;
+#endif
+	}
+	else
+		*pdf = 0.0f;
+
+	return LABEL_REFLECT|LABEL_DIFFUSE;
+}
+
+CCL_NAMESPACE_END
+
+#endif /* __BSDF_DISNEY_DIFFUSE_H__ */
+
diff --git a/intern/cycles/kernel/osl/CMakeLists.txt b/intern/cycles/kernel/osl/CMakeLists.txt
index 9cf4f2d..2c41fdf 100644
--- a/intern/cycles/kernel/osl/CMakeLists.txt
+++ b/intern/cycles/kernel/osl/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRC
 	osl_closures.cpp
 	osl_services.cpp
 	osl_shader.cpp
+	bsdf_disney_diffuse.cpp
 )
 
 set(HEADER_SRC
diff --git a/intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp b/intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp
new file mode 100644
index 0000000..ba7d233
--- /dev/null
+++ b/intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp
@@ -0,0 +1,101 @@
+/*
+ * Adapted from Open Shading Language with this license:
+ *
+ * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al.
+ * All Rights Reserved.
+ *
+ * Modifications Copyright 2011, Blender Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of Sony Pictures Imageworks nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <OpenImageIO/fmath.h>
+
+#include <OSL/genclosure.h>
+
+#include "kernel_compat_cpu.h"
+#include "osl_closures.h"
+
+#include "kernel_types.h"
+#include "kernel_montecarlo.h"
+#include "closure/bsdf_disney_diffuse.h"
+
+CCL_NAMESPACE_BEGIN
+
+using namespace OSL;
+
+class DisneyDiffuseClosure : public CBSDFClosure {
+public:
+    float3 color;
+
+	DisneyDiffuseClosure() : CBSDFClosure(LABEL_DIFFUSE)
+	{}
+
+	void setup()
+	{
+		sc.prim = this;
+		m_shaderdata_flag = bsdf_disney_diffuse_setup(&sc);
+	}
+
+	void blur(float roughness)
+	{
+		//bsdf_disney_diffuse_blur(&sc, roughness);
+	}
+
+	float3 eval_reflect(const float3 &omega_out, const float3 &omega_in, float& pdf) const
+	{
+		return bsdf_disney_diffuse_eval_reflect(&sc, color, omega_out, omega_in, &pdf);
+	}
+
+	float3 eval_transmit(const float3 &omega_out, const float3 &omega_in, float& pdf) const
+	{
+		return bsdf_disney_diffuse_eval_transmit(&sc, color, omega_out, omega_in, &pdf);
+	}
+
+	int sample(const float3 &Ng,
+	           const float3 &omega_out, const float3 &domega_out_dx, const float3 &domega_out_dy,
+	           float randu, float randv,
+	           float3 &omega_in, float3 &domega_in_dx, float3 &domega_in_dy,
+	           float &pdf, float3 &eval) const
+	{
+		return bsdf_disney_diffuse_sample(&sc, color, Ng, omega_out, domega_out_dx, domega_out_dy,
+			randu, randv, &eval, &omega_in, &domega_in_dx, &domega_in_dy, &pdf);
+	}
+};
+
+ClosureParam *closure_bsdf_disney_diffuse_params()
+{
+	static ClosureParam params[] = {
+		CLOSURE_FLOAT3_PARAM(DisneyDiffuseClosure, sc.N),
+		CLOSURE_FLOAT3_PARAM(DisneyDiffuseClosure, color),
+		CLOSURE_STRING_KEYPARAM(DisneyDiffuseClosure, label, "label"),
+		CLOSURE_FINISH_PARAM(DisneyDiffuseClosure)
+	};
+	return params;
+}
+
+CCLOSURE_PREPARE(closure_bsdf_disney_diffuse_prepare, DisneyDiffuseClosure)
+
+CCL_NAMESPACE_END
+
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index 95b8cea..5e311f7 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -238,6 +238,8 @@ void OSLShader::register_closures(OSLShadingSystem *ss_)
 		closure_bssrdf_gaussian_params(), closure_bssrdf_gaussian_prepare);
 	register_closure(ss, "bssrdf_burley", id++,
 		closure_bssrdf_burley_params(), closure_bssrdf_burley_prepare);
+	register

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list