[Bf-blender-cvs] [9f3d397] cycles_disney_brdf: disney diffuse und specular implemented
Pascal Schoen
noreply at git.blender.org
Tue May 17 10:46:48 CEST 2016
Commit: 9f3d39744b85619750c79c901f678b8c07fe0ee2
Author: Pascal Schoen
Date: Fri Apr 29 22:56:49 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rB9f3d39744b85619750c79c901f678b8c07fe0ee2
disney diffuse und specular implemented
===================================================================
M intern/cycles/kernel/CMakeLists.txt
M intern/cycles/kernel/closure/bsdf.h
M intern/cycles/kernel/closure/bsdf_disney_diffuse.h
A intern/cycles/kernel/closure/bsdf_disney_specular.h
M intern/cycles/kernel/osl/CMakeLists.txt
A intern/cycles/kernel/osl/bsdf_disney_specular.cpp
M intern/cycles/kernel/osl/osl_closures.cpp
M intern/cycles/kernel/osl/osl_closures.h
M intern/cycles/kernel/shaders/stdosl.h
M intern/cycles/kernel/svm/svm_types.h
===================================================================
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index bf99b5c..35e6c4f 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -88,6 +88,7 @@ set(SRC_CLOSURE_HEADERS
closure/emissive.h
closure/volume.h
closure/bsdf_disney_diffuse.h
+ closure/bsdf_disney_specular.h
)
set(SRC_SVM_HEADERS
diff --git a/intern/cycles/kernel/closure/bsdf.h b/intern/cycles/kernel/closure/bsdf.h
index f40ed38..b92a864 100644
--- a/intern/cycles/kernel/closure/bsdf.h
+++ b/intern/cycles/kernel/closure/bsdf.h
@@ -27,6 +27,7 @@
#include "../closure/bsdf_toon.h"
#include "../closure/bsdf_hair.h"
#include "../closure/bsdf_disney_diffuse.h"
+#include "../closure/bsdf_disney_specular.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
index ff69a7a..a35585d 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
@@ -127,8 +127,8 @@ struct DisneyDiffuseBRDFParams {
m_ctint = m_cdlum > 0.0f ? m_cdlin / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
m_csheen = diff_mix(make_float3(1.0f, 1.0f, 1.0f), m_ctint, m_sheen_tint);
- m_gamma = clamp(m_gamma, 0.0f, 5.0f);
- m_exposure = clamp(m_exposure, -6.0f, 6.0f);
+ //m_gamma = clamp(m_gamma, 0.0f, 5.0f);
+ //m_exposure = clamp(m_exposure, -6.0f, 6.0f);
m_withNdotL_b = (m_withNdotL > 0.5f);
}
};
@@ -138,7 +138,7 @@ typedef struct DisneyDiffuseBRDFParams DisneyDiffuseBRDFParams;
/* brdf */
ccl_device float3 calculate_disney_diffuse_brdf(const ShaderClosure *sc,
const DisneyDiffuseBRDFParams *params, float3 N, float3 V, float3 L,
- float3 H, float *pdf)
+ float3 H, float *pdf, bool withNdotL = true)
{
float NdotL = dot(N, L);
float NdotV = dot(N, V);
@@ -166,16 +166,47 @@ ccl_device float3 calculate_disney_diffuse_brdf(const ShaderClosure *sc,
}
float3 value = M_1_PI_F * Fd * params->m_cdlin;
- *pdf = NdotL * M_1_PI_F * params->m_cdlum;
+
+ //if (params->m_gamma > 0.5f)
+ *pdf = M_1_PI_F;
+
+ /*if (params->m_exposure > 0.95f)
+ *pdf *= params->m_cdlum;
+ else if (params->m_exposure > 0.85f)
+ *pdf *= params->m_cdlum * NdotL;
+ else if (params->m_exposure > 0.75f)
+ *pdf *= params->m_cdlum * 0.5f;
+ else if (params->m_exposure > 0.65f)
+ *pdf *= params->m_cdlum * NdotL * 0.5f;
+ else if (params->m_exposure > 0.55f)
+ *pdf *= NdotL;
+ else if (params->m_exposure > 0.45f)
+ *pdf *= NdotL * 0.5f;
+ else if (params->m_exposure > 0.35f)*/
+ *pdf *= 0.5f;
// sheen component
if (params->m_sheen != 0.0f) {
float FH = diff_SchlickFresnel(LdotH);
value += FH * params->m_sheen * params->m_csheen;
- *pdf += (1.0f / M_2PI_F) * params->m_sheen;
+ //*pdf += 0.5f * M_1_PI_F * params->m_sheen;
}
+ if (withNdotL)
+ value *= NdotL;
+
+ // brightness
+ //value *= params->m_brightness;
+
+ // exposure
+ //value *= pow(2.0f, params->m_exposure);
+
+ // gamma
+ /*value[0] = pow(value[0], 1.0f / params->m_gamma);
+ value[1] = pow(value[1], 1.0f / params->m_gamma);
+ value[2] = pow(value[2], 1.0f / params->m_gamma);*/
+
return value;
}
@@ -197,19 +228,6 @@ ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc,
if (dot(sc->N, omega_in) > 0.0f) {
float3 value = calculate_disney_diffuse_brdf(sc, params, N, V, L, H, pdf);
- value *= dot(N, L);
-
- // brightness
- value *= params->m_brightness;
-
- // exposure
- value *= pow(2.0f, params->m_exposure);
-
- // gamma
- value[0] = pow(value[0], 1.0f / params->m_gamma);
- value[1] = pow(value[1], 1.0f / params->m_gamma);
- value[2] = pow(value[2], 1.0f / params->m_gamma);
-
return value;
}
else {
@@ -230,30 +248,18 @@ ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, const DisneyD
{
float3 N = normalize(sc->N);
- sample_uniform_hemisphere(N, randu, randv, omega_in, pdf);
+ /*if (params->m_brightness > 0.5f)
+ sample_cos_hemisphere(N, randu, randv, omega_in, pdf);
+ else*/
+ sample_uniform_hemisphere(N, randu, randv, omega_in, pdf);
if (dot(Ng, *omega_in) > 0) {
float3 V = I; // outgoing
float3 L = *omega_in; // incoming
float3 H = normalize(L + V);
- float3 value = calculate_disney_diffuse_brdf(sc, params, N, V, L, H, pdf);
-
- if (params->m_withNdotL_b)
- value *= dot(N, L);
-
- // brightness
- value *= params->m_brightness;
-
- // exposure
- value *= pow(2.0f, params->m_exposure);
-
- // gamma
- value[0] = pow(value[0], 1.0f / params->m_gamma);
- value[1] = pow(value[1], 1.0f / params->m_gamma);
- value[2] = pow(value[2], 1.0f / params->m_gamma);
-
- *eval = make_float3(value[0], value[1], value[2]);
+ float pon;
+ *eval = calculate_disney_diffuse_brdf(sc, params, N, V, L, H, pdf, true);
#ifdef __RAY_DIFFERENTIALS__
// TODO: find a better approximation for the diffuse bounce
@@ -264,86 +270,7 @@ ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, const DisneyD
else {
*pdf = 0;
}
-
- /*// we are viewing the surface from the right side - send a ray out with cosine
- // distribution over the hemisphere
- sample_cos_hemisphere(-N, randu, randv, omega_in, pdf);
- if(dot(Ng, *omega_in) < 0) {
- float3 H = normalize(*omega_in - I);
- *eval = calculate_disney_diffuse_brdf(sc, params, -N, -I, *omega_in, H, pdf);
-
- // multiply with NdotL
- //if (params->m_withNdotL_b)
- // *eval *= dot(N, L);
-
- // brightness
- *eval *= params->m_brightness;
-
- // exposure
- *eval *= pow(2.0f, params->m_exposure);
-
- // gamma
- (*eval)[0] = pow((*eval)[0], 1.0f / params->m_gamma);
- (*eval)[1] = pow((*eval)[1], 1.0f / params->m_gamma);
- (*eval)[2] = pow((*eval)[2], 1.0f / params->m_gamma);
- //*eval = make_float3(*pdf, *pdf, *pdf);
-
-#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;
- }*/
- return LABEL_DIFFUSE;
-
- /*float3 N = normalize(sc->N);
- float3 T = normalize(sc->T);
- float3 X, Y;
-
- float cos_theta, phi, theta, sin_phi, cos_phi;
-
- make_orthonormals_tangent(N, T, &X, &Y);
-
- phi = 2.0f * M_PI_F * randu;
- theta = 2.0f * M_PI_F * randv;
- cos_theta = cosf(theta);
- sin_phi = sinf(phi);
- cos_phi = cosf(phi);
-
- float sin_theta = sqrtf(fmaxf(0.0f, 1.0f - cos_theta * cos_theta));
- float3 H = normalize(sin_theta * cos_phi * X + sin_theta * sin_phi * Y + cos_theta * N);
-
- *omega_in = 2.0f * dot(I, H) * H - I;
-
- float3 V = I; // outgoing
- float3 L = *omega_in; // incoming
-
- *eval = calculate_disney_diffuse_brdf(sc, params, N, V, L, H, pdf);
-
- // multiply with NdotL
- //if (params->m_withNdotL_b)
- // *eval *= dot(N, L);
-
- // brightness
- *eval *= params->m_brightness;
-
- // exposure
- *eval *= pow(2.0f, params->m_exposure);
-
- // gamma
- (*eval)[0] = pow((*eval)[0], 1.0f / params->m_gamma);
- (*eval)[1] = pow((*eval)[1], 1.0f / params->m_gamma);
- (*eval)[2] = pow((*eval)[2], 1.0f / params->m_gamma);
-
-#ifdef __RAY_DIFFERENTIALS__
- *domega_in_dx = 2 * dot(N, dIdx) * N - dIdx;
- *domega_in_dy = 2 * dot(N, dIdy) * N - dIdy;
-#endif
-
- return LABEL_REFLECT|LABEL_DIFFUSE;*/
+ return LABEL_REFLECT|LABEL_DIFFUSE;
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/closure/bsdf_disney_specular.h b/intern/cycles/kernel/closure/bsdf_disney_specular.h
new file mode 100644
index 0000000..5185bd5
--- /dev/null
+++ b/intern/cycles/kernel/closure/bsdf_disney_specular.h
@@ -0,0 +1,679 @@
+/*
+ * 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_SPECULAR_H__
+#define __BSDF_DISNEY_SPECULAR_H__
+
+#include <cmath>
+
+CCL_NAMESPACE_BEGIN
+
+/* DISNEY SPECULAR */
+
+ccl_device float spec_sqr(float a) {
+ return a * a;
+}
+
+ccl_device float3 spec_mon2lin(float3 x, float gamma) {
+ return make_float3(pow(x[0], gamma), pow(x[1], gamma), pow(x[2], gamma));
+}
+
+ccl_device float spec_GTR1(float NdotH, float a) {
+ if (a >= 1.0f) return 1.0f / M_PI_F;
+ float a2 = a*a;
+ float t = 1.0f + (a2 - 1.0f) * NdotH * NdotH;
+ return (a2 - 1.0f) / (M_PI_F * log(a2) * t);
+}
+
+ccl_device float spec_GTR2(float NdotH, float a) {
+ float a2 = a * a;
+ float t = 1.0f + (a2 - 1.0f) * NdotH * NdotH;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list