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:
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/kernel_accumulate.h4
-rw-r--r--intern/cycles/kernel/kernel_bvh.h6
-rw-r--r--intern/cycles/kernel/kernel_compat_cpu.h12
-rw-r--r--intern/cycles/kernel/kernel_differential.h6
-rw-r--r--intern/cycles/kernel/kernel_emission.h13
-rw-r--r--intern/cycles/kernel/kernel_globals.h14
-rw-r--r--intern/cycles/kernel/kernel_light.h49
-rw-r--r--intern/cycles/kernel/kernel_montecarlo.h2
-rw-r--r--intern/cycles/kernel/kernel_object.h25
-rw-r--r--intern/cycles/kernel/kernel_optimized.cpp4
-rw-r--r--intern/cycles/kernel/kernel_path.h29
-rw-r--r--intern/cycles/kernel/kernel_projection.h2
-rw-r--r--intern/cycles/kernel/kernel_random.h8
-rw-r--r--intern/cycles/kernel/kernel_shader.h4
-rw-r--r--intern/cycles/kernel/kernel_textures.h3
-rw-r--r--intern/cycles/kernel/kernel_triangle.h4
-rw-r--r--intern/cycles/kernel/kernel_types.h9
-rw-r--r--intern/cycles/kernel/osl/background.cpp36
-rw-r--r--intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp242
-rw-r--r--intern/cycles/kernel/osl/bsdf_diffuse.cpp246
-rw-r--r--intern/cycles/kernel/osl/bsdf_microfacet.cpp779
-rw-r--r--intern/cycles/kernel/osl/bsdf_oren_nayar.cpp43
-rw-r--r--intern/cycles/kernel/osl/bsdf_reflection.cpp113
-rw-r--r--intern/cycles/kernel/osl/bsdf_refraction.cpp119
-rw-r--r--intern/cycles/kernel/osl/bsdf_transparent.cpp87
-rw-r--r--intern/cycles/kernel/osl/bsdf_ward.cpp312
-rw-r--r--intern/cycles/kernel/osl/bsdf_westin.cpp346
-rw-r--r--intern/cycles/kernel/osl/bssrdf.cpp103
-rw-r--r--intern/cycles/kernel/osl/debug.cpp31
-rw-r--r--intern/cycles/kernel/osl/emissive.cpp93
-rw-r--r--intern/cycles/kernel/osl/nodes/node_checker_texture.osl18
-rw-r--r--intern/cycles/kernel/osl/nodes/node_color.h50
-rw-r--r--intern/cycles/kernel/osl/nodes/node_fresnel.h27
-rw-r--r--intern/cycles/kernel/osl/nodes/node_texture.h100
-rw-r--r--intern/cycles/kernel/osl/nodes/stdosl.h397
-rw-r--r--intern/cycles/kernel/osl/osl_closures.cpp8
-rw-r--r--intern/cycles/kernel/osl/osl_services.cpp174
-rw-r--r--intern/cycles/kernel/osl/osl_services.h23
-rw-r--r--intern/cycles/kernel/osl/osl_shader.cpp159
-rw-r--r--intern/cycles/kernel/osl/osl_shader.h8
-rw-r--r--intern/cycles/kernel/osl/vol_subsurface.cpp156
-rw-r--r--intern/cycles/kernel/svm/bsdf.h90
-rw-r--r--intern/cycles/kernel/svm/bsdf_ashikhmin_velvet.h2
-rw-r--r--intern/cycles/kernel/svm/bsdf_diffuse.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_microfacet.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_reflection.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_refraction.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_transparent.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_ward.h62
-rw-r--r--intern/cycles/kernel/svm/bsdf_westin.h62
-rw-r--r--intern/cycles/kernel/svm/emissive.h77
-rw-r--r--intern/cycles/kernel/svm/svm.h3
-rw-r--r--intern/cycles/kernel/svm/svm_closure.h10
-rw-r--r--intern/cycles/kernel/svm/svm_geometry.h22
-rw-r--r--intern/cycles/kernel/svm/svm_gradient.h12
-rw-r--r--intern/cycles/kernel/svm/svm_image.h14
-rw-r--r--intern/cycles/kernel/svm/svm_magic.h18
-rw-r--r--intern/cycles/kernel/svm/svm_mix.h16
-rw-r--r--intern/cycles/kernel/svm/svm_musgrave.h8
-rw-r--r--intern/cycles/kernel/svm/svm_noise.h10
-rw-r--r--intern/cycles/kernel/svm/svm_texture.h10
-rw-r--r--intern/cycles/kernel/svm/svm_types.h154
-rw-r--r--intern/cycles/kernel/svm/svm_voronoi.h2
-rw-r--r--intern/cycles/kernel/svm/svm_wave.h10
-rw-r--r--intern/cycles/kernel/svm/volume.h2
65 files changed, 2450 insertions, 2308 deletions
diff --git a/intern/cycles/kernel/kernel_accumulate.h b/intern/cycles/kernel/kernel_accumulate.h
index 6c3ade1c531..d99beb8905a 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -271,8 +271,8 @@ __device_inline float3 path_radiance_sum(KernelGlobals *kg, PathRadiance *L)
#ifdef __PASSES__
if(L->use_light_pass) {
/* this division is a bit ugly, but means we only have to keep track of
- only a single throughput further along the path, here we recover just
- the indirect parth that is not influenced by any particular BSDF type */
+ * only a single throughput further along the path, here we recover just
+ * the indirect parth that is not influenced by any particular BSDF type */
L->direct_emission = safe_divide_color(L->direct_emission, L->direct_throughput);
L->direct_diffuse += L->indirect_diffuse*L->direct_emission;
L->direct_glossy += L->indirect_glossy*L->direct_emission;
diff --git a/intern/cycles/kernel/kernel_bvh.h b/intern/cycles/kernel/kernel_bvh.h
index 522f9861c35..34a44af8b8d 100644
--- a/intern/cycles/kernel/kernel_bvh.h
+++ b/intern/cycles/kernel/kernel_bvh.h
@@ -34,8 +34,8 @@ CCL_NAMESPACE_BEGIN
#define TRI_NODE_SIZE 3
/* silly workaround for float extended precision that happens when compiling
- without sse support on x86, it results in different results for float ops
- that you would otherwise expect to compare correctly */
+ * without sse support on x86, it results in different results for float ops
+ * that you would otherwise expect to compare correctly */
#if !defined(__i386__) || defined(__SSE__)
#define NO_EXTENDED_PRECISION
#else
@@ -160,7 +160,7 @@ __device_inline void bvh_triangle_intersect(KernelGlobals *kg, Intersection *ise
if(v >= 0.0f && u + v <= 1.0f) {
#ifdef __VISIBILITY_FLAG__
/* visibility flag test. we do it here under the assumption
- that most triangles are culled by node flags */
+ * that most triangles are culled by node flags */
if(kernel_tex_fetch(__prim_visibility, triAddr) & visibility)
#endif
{
diff --git a/intern/cycles/kernel/kernel_compat_cpu.h b/intern/cycles/kernel/kernel_compat_cpu.h
index 2bd0b61b4fa..cc8f1f3323b 100644
--- a/intern/cycles/kernel/kernel_compat_cpu.h
+++ b/intern/cycles/kernel/kernel_compat_cpu.h
@@ -28,13 +28,13 @@
CCL_NAMESPACE_BEGIN
/* Assertions inside the kernel only work for the CPU device, so we wrap it in
- a macro which is empty for other devices */
+ * a macro which is empty for other devices */
#define kernel_assert(cond) assert(cond)
/* Texture types to be compatible with CUDA textures. These are really just
- simple arrays and after inlining fetch hopefully revert to being a simple
- pointer lookup. */
+ * simple arrays and after inlining fetch hopefully revert to being a simple
+ * pointer lookup. */
template<typename T> struct texture {
T fetch(int index)
@@ -43,7 +43,8 @@ template<typename T> struct texture {
return data[index];
}
- /*__m128 fetch_m128(int index)
+#if 0
+ __m128 fetch_m128(int index)
{
kernel_assert(index >= 0 && index < width);
return ((__m128*)data)[index];
@@ -53,7 +54,8 @@ template<typename T> struct texture {
{
kernel_assert(index >= 0 && index < width);
return ((__m128i*)data)[index];
- }*/
+ }
+#endif
float interp(float x, int size)
{
diff --git a/intern/cycles/kernel/kernel_differential.h b/intern/cycles/kernel/kernel_differential.h
index 5b4290a7722..04027523ea5 100644
--- a/intern/cycles/kernel/kernel_differential.h
+++ b/intern/cycles/kernel/kernel_differential.h
@@ -49,9 +49,9 @@ __device void differential_dudv(differential *du, differential *dv, float3 dPdu,
* mainly used for differentials of arbitrary mesh attributes. */
/* find most stable axis to project to 2D */
- float xn= fabsf(Ng.x);
- float yn= fabsf(Ng.y);
- float zn= fabsf(Ng.z);
+ float xn = fabsf(Ng.x);
+ float yn = fabsf(Ng.y);
+ float zn = fabsf(Ng.z);
if(zn < xn || zn < yn) {
if(yn < xn || yn < zn) {
diff --git a/intern/cycles/kernel/kernel_emission.h b/intern/cycles/kernel/kernel_emission.h
index 0ef1425e68a..f582ace69f0 100644
--- a/intern/cycles/kernel/kernel_emission.h
+++ b/intern/cycles/kernel/kernel_emission.h
@@ -44,7 +44,7 @@ __device float3 direct_emissive_eval(KernelGlobals *kg, float rando,
ls->Ng = sd.Ng;
/* no path flag, we're evaluating this for all closures. that's weak but
- we'd have to do multiple evaluations otherwise */
+ * we'd have to do multiple evaluations otherwise */
shader_eval_surface(kg, &sd, rando, 0);
/* evaluate emissive closure */
@@ -104,13 +104,8 @@ __device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
float mis_weight = power_heuristic(pdf, bsdf_pdf);
light_eval *= mis_weight;
}
- /* todo: clean up these weights */
- else if(ls.shader & SHADER_AREA_LIGHT)
- light_eval *= 0.25f; /* area lamp */
- else if(ls.t != FLT_MAX)
- light_eval *= 0.25f*M_1_PI_F; /* point lamp */
- bsdf_eval_mul(eval, light_eval/pdf);
+ bsdf_eval_mul(eval, light_eval*(ls.eval_fac/pdf));
if(bsdf_eval_is_zero(eval))
return false;
@@ -150,7 +145,7 @@ __device float3 indirect_emission(KernelGlobals *kg, ShaderData *sd, float t, in
if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT)) {
/* multiple importance sampling, get triangle light pdf,
- and compute weight with respect to BSDF pdf */
+ * and compute weight with respect to BSDF pdf */
float pdf = triangle_light_pdf(kg, sd->Ng, sd->I, t);
float mis_weight = power_heuristic(bsdf_pdf, pdf);
@@ -177,7 +172,7 @@ __device float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag,
if(!(path_flag & PATH_RAY_MIS_SKIP) && res) {
/* multiple importance sampling, get background light pdf for ray
- direction, and compute weight with respect to BSDF pdf */
+ * direction, and compute weight with respect to BSDF pdf */
float pdf = background_light_pdf(kg, ray->D);
float mis_weight = power_heuristic(bsdf_pdf, pdf);
diff --git a/intern/cycles/kernel/kernel_globals.h b/intern/cycles/kernel/kernel_globals.h
index 1f2fc97e685..a99fffbc519 100644
--- a/intern/cycles/kernel/kernel_globals.h
+++ b/intern/cycles/kernel/kernel_globals.h
@@ -29,9 +29,9 @@
CCL_NAMESPACE_BEGIN
/* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
- the kernel, to access constant data. These are all stored as "textures", but
- these are really just standard arrays. We can't use actually globals because
- multiple renders may be running inside the same process. */
+ * the kernel, to access constant data. These are all stored as "textures", but
+ * these are really just standard arrays. We can't use actually globals because
+ * multiple renders may be running inside the same process. */
#ifdef __KERNEL_CPU__
@@ -45,7 +45,7 @@ typedef struct KernelGlobals {
#ifdef __OSL__
/* On the CPU, we also have the OSL globals here. Most data structures are shared
- with SVM, the difference is in the shaders and object/mesh attributes. */
+ * with SVM, the difference is in the shaders and object/mesh attributes. */
OSLGlobals osl;
#endif
@@ -54,9 +54,9 @@ typedef struct KernelGlobals {
#endif
/* For CUDA, constant memory textures must be globals, so we can't put them
- into a struct. As a result we don't actually use this struct and use actual
- globals and simply pass along a NULL pointer everywhere, which we hope gets
- optimized out. */
+ * into a struct. As a result we don't actually use this struct and use actual
+ * globals and simply pass along a NULL pointer everywhere, which we hope gets
+ * optimized out. */
#ifdef __KERNEL_CUDA__
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index e9e7fbd4ca1..edc302cd6e3 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -23,6 +23,7 @@ typedef struct LightSample {
float3 D;
float3 Ng;
float t;
+ float eval_fac;
int object;
int prim;
int shader;
@@ -63,8 +64,8 @@ __device float3 area_light_sample(float3 axisu, float3 axisv, float randu, float
__device float3 background_light_sample(KernelGlobals *kg, float randu, float randv, float *pdf)
{
/* for the following, the CDF values are actually a pair of floats, with the
- function value as X and the actual CDF as Y. The last entry's function
- value is the CDF total. */
+ * function value as X and the actual CDF as Y. The last entry's function
+ * value is the CDF total. */
int res = kernel_data.integrator.pdf_background_res;
int cdf_count = res + 1;
@@ -189,6 +190,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point,
ls->Ng = D;
ls->D = -D;
ls->t = FLT_MAX;
+ ls->eval_fac = 1.0f;
}
#ifdef __BACKGROUND_MIS__
else if(type == LIGHT_BACKGROUND) {
@@ -199,6 +201,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point,
ls->Ng = D;
ls->D = -D;
ls->t = FLT_MAX;
+ ls->eval_fac = 1.0f;
}
#endif
else {
@@ -212,6 +215,36 @@ __device void regular_light_sample(KernelGlobals *kg, int point,
ls->P += sphere_light_sample(P, ls->P, size, randu, randv);
ls->Ng = normalize(P - ls->P);
+ ls->eval_fac = 0.25f*M_1_PI_F;
+ }
+ else if(type == LIGHT_SPOT) {
+ float4 data2 = kernel_tex_fetch(__light_data, point*LIGHT_SIZE + 2);
+ float size = data1.y;
+
+ /* spot light */
+ if(size > 0.0f)
+ ls->P += sphere_light_sample(P, ls->P, size, randu, randv);
+
+ float3 dir = make_float3(data1.z, data1.w, data2.x);
+ float3 I = normalize(P - ls->P);
+
+ float spot_angle = data2.y;
+ float spot_smooth = data2.z;
+
+ float eval_fac = dot(dir, I);
+
+ if(eval_fac <= spot_angle) {
+ eval_fac = 0.0f;
+ }
+ else {
+ float t = eval_fac - spot_angle;
+
+ if(t < spot_smooth && spot_smooth != 0.0f)
+ eval_fac *= smoothstepf(t/spot_smooth);
+ }
+
+ ls->Ng = I;
+ ls->eval_fac = eval_fac*0.25f*M_1_PI_F;
}
else {
/* area light */
@@ -224,6 +257,7 @@ __device void regular_light_sample(KernelGlobals *kg, int point,
ls->P += area_light_sample(axisu, axisv, randu, randv);
ls->Ng = D;
+ ls->eval_fac = 0.25f;
}
ls->t = 0.0f;
@@ -262,6 +296,7 @@ __device void triangle_light_sample(KernelGlobals *kg, int prim, int object,
ls->prim = prim;
ls->t = 0.0f;
ls->type = LIGHT_AREA;
+ ls->eval_fac = 1.0f;
#ifdef __INSTANCING__
/* instance transform */
@@ -291,9 +326,9 @@ __device float triangle_light_pdf(KernelGlobals *kg,
__device int light_distribution_sample(KernelGlobals *kg, float randt)
{
/* this is basically std::upper_bound as used by pbrt, to find a point light or
- triangle to emit from, proportional to area. a good improvement would be to
- also sample proportional to power, though it's not so well defined with
- OSL shaders. */
+ * triangle to emit from, proportional to area. a good improvement would be to
+ * also sample proportional to power, though it's not so well defined with
+ * OSL shaders. */
int first = 0;
int len = kernel_data.integrator.num_distribution + 1;
@@ -356,6 +391,10 @@ __device float light_sample_pdf(KernelGlobals *kg, LightSample *ls, float3 I, fl
__device void light_select(KernelGlobals *kg, int index, float randu, float randv, float3 P, LightSample *ls, float *pdf)
{
regular_light_sample(kg, index, randu, randv, P, ls, pdf);
+
+ /* compute incoming direction and distance */
+ if(ls->t != FLT_MAX)
+ ls->D = normalize_len(ls->P - P, &ls->t);
}
__device float light_select_pdf(KernelGlobals *kg, LightSample *ls, float3 I, float t)
diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h
index bdd147f83d3..939f3915b6c 100644
--- a/intern/cycles/kernel/kernel_montecarlo.h
+++ b/intern/cycles/kernel/kernel_montecarlo.h
@@ -28,7 +28,7 @@
* 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 __KERNEL_MONTECARLO_CL__
#define __KERNEL_MONTECARLO_CL__
diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h
index 05c45c490d8..18e0b1e8a87 100644
--- a/intern/cycles/kernel/kernel_object.h
+++ b/intern/cycles/kernel/kernel_object.h
@@ -154,10 +154,35 @@ __device_inline float object_random_number(KernelGlobals *kg, int object)
return f.z;
}
+__device_inline uint object_particle_id(KernelGlobals *kg, int object)
+{
+ if(object == ~0)
+ return 0.0f;
+
+ int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES;
+ float4 f = kernel_tex_fetch(__objects, offset);
+ return __float_as_int(f.w);
+}
+
__device int shader_pass_id(KernelGlobals *kg, ShaderData *sd)
{
return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1);
}
+__device float particle_age(KernelGlobals *kg, int particle)
+{
+ int offset = particle*PARTICLE_SIZE;
+ float4 f = kernel_tex_fetch(__particles, offset);
+ return f.x;
+}
+
+__device float particle_lifetime(KernelGlobals *kg, int particle)
+{
+ int offset = particle*PARTICLE_SIZE;
+ float4 f = kernel_tex_fetch(__particles, offset);
+ return f.y;
+}
+
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/kernel_optimized.cpp b/intern/cycles/kernel/kernel_optimized.cpp
index 393686bb203..0b662095133 100644
--- a/intern/cycles/kernel/kernel_optimized.cpp
+++ b/intern/cycles/kernel/kernel_optimized.cpp
@@ -17,8 +17,8 @@
*/
/* Optimized CPU kernel entry points. This file is compiled with SSE3
- optimization flags and nearly all functions inlined, while kernel.cpp
- is compiled without for other CPU's. */
+ * optimization flags and nearly all functions inlined, while kernel.cpp
+ * is compiled without for other CPU's. */
#ifdef WITH_OPTIMIZED_KERNEL
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index e0e17ee57dc..8dbf66c108c 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -59,7 +59,7 @@ __device_inline void path_state_init(PathState *state)
__device_inline void path_state_next(KernelGlobals *kg, PathState *state, int label)
{
/* ray through transparent keeps same flags from previous ray and is
- not counted as a regular bounce, transparent has separate max */
+ * not counted as a regular bounce, transparent has separate max */
if(label & LABEL_TRANSPARENT) {
state->flag |= PATH_RAY_TRANSPARENT;
state->transparent_bounce++;
@@ -137,9 +137,12 @@ __device_inline float path_state_terminate_probability(KernelGlobals *kg, PathSt
(state->diffuse_bounce >= kernel_data.integrator.max_diffuse_bounce) ||
(state->glossy_bounce >= kernel_data.integrator.max_glossy_bounce) ||
(state->transmission_bounce >= kernel_data.integrator.max_transmission_bounce))
+ {
return 0.0f;
- else if(state->bounce <= kernel_data.integrator.min_bounce)
+ }
+ else if(state->bounce <= kernel_data.integrator.min_bounce) {
return 1.0f;
+ }
}
/* probalistic termination */
@@ -159,13 +162,13 @@ __device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ra
#ifdef __TRANSPARENT_SHADOWS__
if(result && kernel_data.integrator.transparent_shadows) {
/* transparent shadows work in such a way to try to minimize overhead
- in cases where we don't need them. after a regular shadow ray is
- cast we check if the hit primitive was potentially transparent, and
- only in that case start marching. this gives on extra ray cast for
- the cases were we do want transparency.
-
- also note that for this to work correct, multi close sampling must
- be used, since we don't pass a random number to shader_eval_surface */
+ * in cases where we don't need them. after a regular shadow ray is
+ * cast we check if the hit primitive was potentially transparent, and
+ * only in that case start marching. this gives on extra ray cast for
+ * the cases were we do want transparency.
+ *
+ * also note that for this to work correct, multi close sampling must
+ * be used, since we don't pass a random number to shader_eval_surface */
if(shader_transparent_shadow(kg, &isect)) {
float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
float3 Pend = ray->P + ray->D*ray->t;
@@ -266,7 +269,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
kernel_write_data_passes(kg, buffer, &L, &sd, sample, state.flag, throughput);
/* blurring of bsdf after bounces, for rays that have a small likelihood
- of following this particular path (diffuse, rough glossy) */
+ * of following this particular path (diffuse, rough glossy) */
if(kernel_data.integrator.filter_glossy != FLT_MAX) {
float blur_pdf = kernel_data.integrator.filter_glossy*min_ray_pdf;
@@ -305,8 +308,8 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
#endif
/* path termination. this is a strange place to put the termination, it's
- mainly due to the mixed in MIS that we use. gives too many unneeded
- shader evaluations, only need emission if we are going to terminate */
+ * mainly due to the mixed in MIS that we use. gives too many unneeded
+ * shader evaluations, only need emission if we are going to terminate */
float probability = path_state_terminate_probability(kg, &state, throughput);
float terminate = path_rng(kg, rng, sample, rng_offset + PRNG_TERMINATE);
@@ -365,7 +368,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R
#ifdef __MULTI_LIGHT__
/* index -1 means randomly sample from distribution */
- int i = (kernel_data.integrator.num_distribution)? -1: 0;
+ int i = (kernel_data.integrator.num_all_lights)? 0: -1;
for(; i < kernel_data.integrator.num_all_lights; i++) {
#else
diff --git a/intern/cycles/kernel/kernel_projection.h b/intern/cycles/kernel/kernel_projection.h
index 72d36811626..64747bcb42e 100644
--- a/intern/cycles/kernel/kernel_projection.h
+++ b/intern/cycles/kernel/kernel_projection.h
@@ -28,7 +28,7 @@
* 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 __KERNEL_PROJECTION_CL__
#define __KERNEL_PROJECTION_CL__
diff --git a/intern/cycles/kernel/kernel_random.h b/intern/cycles/kernel/kernel_random.h
index 6d15100f8a3..9083b7cbfd7 100644
--- a/intern/cycles/kernel/kernel_random.h
+++ b/intern/cycles/kernel/kernel_random.h
@@ -23,8 +23,8 @@ typedef uint RNG;
#ifdef __SOBOL__
/* skip initial numbers that are not as well distributed, especially the
- first sequence is just 0 everywhere, which can be problematic for e.g.
- path termination */
+ * first sequence is just 0 everywhere, which can be problematic for e.g.
+ * path termination */
#define SOBOL_SKIP 64
/* High Dimensional Sobol */
@@ -66,7 +66,7 @@ __device uint sobol_inverse(uint i)
}
/* multidimensional sobol with generator matrices
- dimension 0 and 1 are equal to van_der_corput() and sobol() respectively */
+ * dimension 0 and 1 are equal to van_der_corput() and sobol() respectively */
__device uint sobol_dimension(KernelGlobals *kg, int index, int dimension)
{
uint result = 0;
@@ -119,7 +119,7 @@ __device_inline float path_rng(KernelGlobals *kg, RNG *rng, int sample, int dime
else
shift = (*rng & 0xFFFF)/((float)0xFFFF);
- return r + shift - floor(r + shift);
+ return r + shift - floorf(r + shift);
#endif
}
diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h
index 8e0d36705ad..53a41d58e20 100644
--- a/intern/cycles/kernel/kernel_shader.h
+++ b/intern/cycles/kernel/kernel_shader.h
@@ -520,7 +520,7 @@ __device float3 shader_emissive_eval(KernelGlobals *kg, ShaderData *sd)
if(CLOSURE_IS_EMISSION(sc->type)) {
#ifdef __OSL__
- eval += OSLShader::emissive_eval(sd)*sc->weight;
+ eval += OSLShader::emissive_eval(sd, sc)*sc->weight;
#else
eval += svm_emissive_eval(sd, sc)*sc->weight;
#endif
@@ -624,7 +624,7 @@ __device float3 shader_volume_eval_phase(KernelGlobals *kg, ShaderData *sd,
if(CLOSURE_IS_VOLUME(sc->type)) {
#ifdef __OSL__
- eval += OSLShader::volume_eval_phase(sd, omega_in, omega_out);
+ eval += OSLShader::volume_eval_phase(sd, sc, omega_in, omega_out);
#else
eval += volume_eval_phase(sd, sc, omega_in, omega_out);
#endif
diff --git a/intern/cycles/kernel/kernel_textures.h b/intern/cycles/kernel/kernel_textures.h
index 482f886df3e..c1b8eed3dff 100644
--- a/intern/cycles/kernel/kernel_textures.h
+++ b/intern/cycles/kernel/kernel_textures.h
@@ -52,6 +52,9 @@ KERNEL_TEX(float4, texture_float4, __light_data)
KERNEL_TEX(float2, texture_float2, __light_background_marginal_cdf)
KERNEL_TEX(float2, texture_float2, __light_background_conditional_cdf)
+/* particles */
+KERNEL_TEX(float4, texture_float4, __particles)
+
/* shaders */
KERNEL_TEX(uint4, texture_uint4, __svm_nodes)
KERNEL_TEX(uint, texture_uint, __shader_flag)
diff --git a/intern/cycles/kernel/kernel_triangle.h b/intern/cycles/kernel/kernel_triangle.h
index 674c3b52539..384c3a8a506 100644
--- a/intern/cycles/kernel/kernel_triangle.h
+++ b/intern/cycles/kernel/kernel_triangle.h
@@ -208,7 +208,7 @@ __device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd)
motion_post = triangle_attribute_float3(kg, sd, ATTR_ELEMENT_VERTEX, offset_post, NULL, NULL);
/* object motion. note that depending on the mesh having motion vectors, this
- transformation was set match the world/object space of motion_pre/post */
+ * transformation was set match the world/object space of motion_pre/post */
Transform tfm;
tfm = object_fetch_transform(kg, sd->object, TIME_INVALID, OBJECT_TRANSFORM_MOTION_PRE);
@@ -220,7 +220,7 @@ __device float4 triangle_motion_vector(KernelGlobals *kg, ShaderData *sd)
float3 P;
/* camera motion, for perspective/orthographic motion.pre/post will be a
- world-to-raster matrix, for panorama it's world-to-camera */
+ * world-to-raster matrix, for panorama it's world-to-camera */
if (kernel_data.cam.type != CAMERA_PANORAMA) {
tfm = kernel_data.cam.worldtoraster;
P = transform_perspective(&tfm, sd->P);
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index a64c850d35a..77a800b0e67 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -33,12 +33,16 @@ CCL_NAMESPACE_BEGIN
#define LIGHT_SIZE 4
#define FILTER_TABLE_SIZE 256
#define RAMP_TABLE_SIZE 256
+#define PARTICLE_SIZE 1
#define TIME_INVALID FLT_MAX
/* device capabilities */
#ifdef __KERNEL_CPU__
#define __KERNEL_SHADING__
#define __KERNEL_ADV_SHADING__
+#ifdef WITH_OSL
+#define __OSL__
+#endif
#endif
#ifdef __KERNEL_CUDA__
@@ -107,7 +111,6 @@ CCL_NAMESPACE_BEGIN
#endif
//#define __MULTI_LIGHT__
-//#define __OSL__
//#define __SOBOL_FULL_SCREEN__
//#define __QBVH__
@@ -283,7 +286,8 @@ typedef enum LightType {
LIGHT_DISTANT,
LIGHT_BACKGROUND,
LIGHT_AREA,
- LIGHT_AO
+ LIGHT_AO,
+ LIGHT_SPOT
} LightType;
/* Camera Type */
@@ -356,6 +360,7 @@ typedef enum AttributeStandard {
ATTR_STD_POSITION_UNDISPLACED,
ATTR_STD_MOTION_PRE,
ATTR_STD_MOTION_POST,
+ ATTR_STD_PARTICLE,
ATTR_STD_NUM,
ATTR_STD_NOT_FOUND = ~0
diff --git a/intern/cycles/kernel/osl/background.cpp b/intern/cycles/kernel/osl/background.cpp
index c35119ae9cf..81812a46b6c 100644
--- a/intern/cycles/kernel/osl/background.cpp
+++ b/intern/cycles/kernel/osl/background.cpp
@@ -48,17 +48,17 @@ using namespace OSL;
///
class GenericBackgroundClosure : public BackgroundClosure {
public:
- GenericBackgroundClosure() { }
+ GenericBackgroundClosure() {}
- void setup() {};
+ void setup() {};
- size_t memsize () const { return sizeof(*this); }
+ size_t memsize() const { return sizeof(*this); }
- const char *name () const { return "background"; }
+ const char *name() const { return "background"; }
- void print_on (std::ostream &out) const {
- out << name() << " ()";
- }
+ void print_on(std::ostream &out) const {
+ out << name() << " ()";
+ }
};
@@ -72,27 +72,29 @@ public:
///
class HoldoutClosure : ClosurePrimitive {
public:
- HoldoutClosure () : ClosurePrimitive (Holdout) { }
+ HoldoutClosure () : ClosurePrimitive(Holdout) {}
- void setup() {};
+ void setup() {};
- size_t memsize () const { return sizeof(*this); }
+ size_t memsize() const { return sizeof(*this); }
- const char *name () const { return "holdout"; }
+ const char *name() const { return "holdout"; }
- void print_on (std::ostream &out) const {
- out << name() << " ()";
- }
+ void print_on(std::ostream &out) const {
+ out << name() << " ()";
+ }
};
ClosureParam closure_background_params[] = {
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(GenericBackgroundClosure) };
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(GenericBackgroundClosure)
+};
CLOSURE_PREPARE(closure_background_prepare, GenericBackgroundClosure)
ClosureParam closure_holdout_params[] = {
- CLOSURE_FINISH_PARAM(HoldoutClosure) };
+ CLOSURE_FINISH_PARAM(HoldoutClosure)
+};
CLOSURE_PREPARE(closure_holdout_prepare, HoldoutClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp b/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp
index a38c5b55cf5..cb6be6959f5 100644
--- a/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp
+++ b/intern/cycles/kernel/osl/bsdf_ashikhmin_velvet.cpp
@@ -36,138 +36,142 @@
#include "osl_closures.h"
+#include "util_math.h"
+
CCL_NAMESPACE_BEGIN
using namespace OSL;
class AshikhminVelvetClosure : public BSDFClosure {
public:
- Vec3 m_N;
- float m_sigma;
- float m_invsigma2;
-
- AshikhminVelvetClosure() : BSDFClosure(Labels::DIFFUSE) { }
-
- void setup()
- {
- m_sigma = std::max(m_sigma, 0.01f);
- m_invsigma2 = 1.0f/(m_sigma * m_sigma);
- }
-
- bool mergeable (const ClosurePrimitive *other) const {
- const AshikhminVelvetClosure *comp = (const AshikhminVelvetClosure *)other;
- return m_N == comp->m_N && m_sigma == comp->m_sigma &&
- BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "ashikhmin_velvet"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_sigma;
- out << ")";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
+ Vec3 m_N;
+ float m_sigma;
+ float m_invsigma2;
+
+ AshikhminVelvetClosure() : BSDFClosure(Labels::DIFFUSE) {}
+
+ void setup()
+ {
+ m_sigma = max(m_sigma, 0.01f);
+ m_invsigma2 = 1.0f / (m_sigma * m_sigma);
+ }
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const AshikhminVelvetClosure *comp = (const AshikhminVelvetClosure *)other;
+ return m_N == comp->m_N && m_sigma == comp->m_sigma &&
+ BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "ashikhmin_velvet"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_sigma;
+ out << ")";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO > 0 && cosNI > 0) {
- Vec3 H = omega_in + omega_out;
- H.normalize();
-
- float cosNH = m_N.dot(H);
- float cosHO = fabsf(omega_out.dot(H));
-
- float cosNHdivHO = cosNH / cosHO;
- cosNHdivHO = std::max(cosNHdivHO, 0.00001f);
-
- float fac1 = 2 * fabsf(cosNHdivHO * cosNO);
- float fac2 = 2 * fabsf(cosNHdivHO * cosNI);
-
- float sinNH2 = 1 - cosNH * cosNH;
- float sinNH4 = sinNH2 * sinNH2;
- float cotangent2 = (cosNH * cosNH) / sinNH2;
-
- float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4;
- float G = std::min(1.0f, std::min(fac1, fac2)); // TODO: derive G from D analytically
-
- float out = 0.25f * (D * G) / cosNO;
-
- pdf = 0.5f * (float) M_1_PI;
- return Color3 (out, out, out);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // we are viewing the surface from above - send a ray out with uniform
- // distribution over the hemisphere
- sample_uniform_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf);
- if (Ng.dot(omega_in) > 0) {
- Vec3 H = omega_in + omega_out;
- H.normalize();
-
- float cosNI = m_N.dot(omega_in);
- float cosNO = m_N.dot(omega_out);
- float cosNH = m_N.dot(H);
- float cosHO = fabsf(omega_out.dot(H));
-
- float cosNHdivHO = cosNH / cosHO;
- cosNHdivHO = std::max(cosNHdivHO, 0.00001f);
-
- float fac1 = 2 * fabsf(cosNHdivHO * cosNO);
- float fac2 = 2 * fabsf(cosNHdivHO * cosNI);
-
- float sinNH2 = 1 - cosNH * cosNH;
- float sinNH4 = sinNH2 * sinNH2;
- float cotangent2 = (cosNH * cosNH) / sinNH2;
-
- float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4;
- float G = std::min(1.0f, std::min(fac1, fac2)); // TODO: derive G from D analytically
-
- float power = 0.25f * (D * G) / cosNO;
-
- eval.setValue(power, power, power);
-
- // TODO: find a better approximation for the retroreflective bounce
- domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
- domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
- domega_in_dx *= 125;
- domega_in_dy *= 125;
- } else
- pdf = 0;
- return Labels::REFLECT;
- }
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO > 0 && cosNI > 0) {
+ Vec3 H = omega_in + omega_out;
+ H.normalize();
+
+ float cosNH = m_N.dot(H);
+ float cosHO = fabsf(omega_out.dot(H));
+
+ float cosNHdivHO = cosNH / cosHO;
+ cosNHdivHO = max(cosNHdivHO, 0.00001f);
+
+ float fac1 = 2 * fabsf(cosNHdivHO * cosNO);
+ float fac2 = 2 * fabsf(cosNHdivHO * cosNI);
+
+ float sinNH2 = 1 - cosNH * cosNH;
+ float sinNH4 = sinNH2 * sinNH2;
+ float cotangent2 = (cosNH * cosNH) / sinNH2;
+
+ float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4;
+ float G = min(1.0f, min(fac1, fac2)); // TODO: derive G from D analytically
+
+ float out = 0.25f * (D * G) / cosNO;
+
+ pdf = 0.5f * (float) M_1_PI;
+ return Color3(out, out, out);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // we are viewing the surface from above - send a ray out with uniform
+ // distribution over the hemisphere
+ sample_uniform_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf);
+ if (Ng.dot(omega_in) > 0) {
+ Vec3 H = omega_in + omega_out;
+ H.normalize();
+
+ float cosNI = m_N.dot(omega_in);
+ float cosNO = m_N.dot(omega_out);
+ float cosNH = m_N.dot(H);
+ float cosHO = fabsf(omega_out.dot(H));
+
+ float cosNHdivHO = cosNH / cosHO;
+ cosNHdivHO = max(cosNHdivHO, 0.00001f);
+
+ float fac1 = 2 * fabsf(cosNHdivHO * cosNO);
+ float fac2 = 2 * fabsf(cosNHdivHO * cosNI);
+
+ float sinNH2 = 1 - cosNH * cosNH;
+ float sinNH4 = sinNH2 * sinNH2;
+ float cotangent2 = (cosNH * cosNH) / sinNH2;
+
+ float D = expf(-cotangent2 * m_invsigma2) * m_invsigma2 * float(M_1_PI) / sinNH4;
+ float G = min(1.0f, min(fac1, fac2)); // TODO: derive G from D analytically
+
+ float power = 0.25f * (D * G) / cosNO;
+
+ eval.setValue(power, power, power);
+
+ // TODO: find a better approximation for the retroreflective bounce
+ domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
+ domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
+ domega_in_dx *= 125;
+ domega_in_dy *= 125;
+ }
+ else
+ pdf = 0;
+ return Labels::REFLECT;
+ }
};
ClosureParam bsdf_ashikhmin_velvet_params[] = {
- CLOSURE_VECTOR_PARAM(AshikhminVelvetClosure, m_N),
- CLOSURE_FLOAT_PARAM (AshikhminVelvetClosure, m_sigma),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(AshikhminVelvetClosure) };
+ CLOSURE_VECTOR_PARAM(AshikhminVelvetClosure, m_N),
+ CLOSURE_FLOAT_PARAM(AshikhminVelvetClosure, m_sigma),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(AshikhminVelvetClosure)
+};
CLOSURE_PREPARE(bsdf_ashikhmin_velvet_prepare, AshikhminVelvetClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_diffuse.cpp b/intern/cycles/kernel/osl/bsdf_diffuse.cpp
index 0d4b3fa471f..582ac01d959 100644
--- a/intern/cycles/kernel/osl/bsdf_diffuse.cpp
+++ b/intern/cycles/kernel/osl/bsdf_diffuse.cpp
@@ -36,143 +36,149 @@
#include "osl_closures.h"
+#include "util_math.h"
+
CCL_NAMESPACE_BEGIN
using namespace OSL;
class DiffuseClosure : public BSDFClosure {
public:
- Vec3 m_N;
-
- DiffuseClosure() : BSDFClosure(Labels::DIFFUSE) { }
-
- void setup() {};
-
- bool mergeable (const ClosurePrimitive *other) const {
- const DiffuseClosure *comp = (const DiffuseClosure *)other;
- return m_N == comp->m_N && BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "diffuse"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- float cos_pi = std::max(m_N.dot(omega_in),0.0f) * (float) M_1_PI;
- pdf = cos_pi;
- return Color3 (cos_pi, cos_pi, cos_pi);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // we are viewing the surface from the right side - send a ray out with cosine
- // distribution over the hemisphere
- sample_cos_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf);
- if (Ng.dot(omega_in) > 0) {
- eval.setValue(pdf, pdf, pdf);
- // TODO: find a better approximation for the diffuse bounce
- domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
- domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
- domega_in_dx *= 125;
- domega_in_dy *= 125;
- } else
- pdf = 0;
- return Labels::REFLECT;
- }
+ Vec3 m_N;
+
+ DiffuseClosure() : BSDFClosure(Labels::DIFFUSE) {}
+
+ void setup() {};
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const DiffuseClosure *comp = (const DiffuseClosure *)other;
+ return m_N == comp->m_N && BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "diffuse"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ float cos_pi = max(m_N.dot(omega_in), 0.0f) * (float) M_1_PI;
+ pdf = cos_pi;
+ return Color3(cos_pi, cos_pi, cos_pi);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // we are viewing the surface from the right side - send a ray out with cosine
+ // distribution over the hemisphere
+ sample_cos_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf);
+ if (Ng.dot(omega_in) > 0) {
+ eval.setValue(pdf, pdf, pdf);
+ // TODO: find a better approximation for the diffuse bounce
+ domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
+ domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
+ domega_in_dx *= 125;
+ domega_in_dy *= 125;
+ }
+ else
+ pdf = 0;
+ return Labels::REFLECT;
+ }
};
class TranslucentClosure : public BSDFClosure {
public:
- Vec3 m_N;
-
- TranslucentClosure() : BSDFClosure(Labels::DIFFUSE, Back) { }
-
- void setup() {};
-
- bool mergeable (const ClosurePrimitive *other) const {
- const TranslucentClosure *comp = (const TranslucentClosure *)other;
- return m_N == comp->m_N && BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "translucent"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- float cos_pi = std::max(-m_N.dot(omega_in), 0.0f) * (float) M_1_PI;
- pdf = cos_pi;
- return Color3 (cos_pi, cos_pi, cos_pi);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // we are viewing the surface from the right side - send a ray out with cosine
- // distribution over the hemisphere
- sample_cos_hemisphere (-m_N, omega_out, randu, randv, omega_in, pdf);
- if (Ng.dot(omega_in) < 0) {
- eval.setValue(pdf, pdf, pdf);
- // TODO: find a better approximation for the diffuse bounce
- domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
- domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
- domega_in_dx *= -125;
- domega_in_dy *= -125;
- } else
- pdf = 0;
- return Labels::TRANSMIT;
- }
+ Vec3 m_N;
+
+ TranslucentClosure() : BSDFClosure(Labels::DIFFUSE, Back) {}
+
+ void setup() {};
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const TranslucentClosure *comp = (const TranslucentClosure *)other;
+ return m_N == comp->m_N && BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "translucent"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " ((" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ float cos_pi = max(-m_N.dot(omega_in), 0.0f) * (float) M_1_PI;
+ pdf = cos_pi;
+ return Color3(cos_pi, cos_pi, cos_pi);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // we are viewing the surface from the right side - send a ray out with cosine
+ // distribution over the hemisphere
+ sample_cos_hemisphere(-m_N, omega_out, randu, randv, omega_in, pdf);
+ if (Ng.dot(omega_in) < 0) {
+ eval.setValue(pdf, pdf, pdf);
+ // TODO: find a better approximation for the diffuse bounce
+ domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
+ domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
+ domega_in_dx *= -125;
+ domega_in_dy *= -125;
+ }
+ else
+ pdf = 0;
+ return Labels::TRANSMIT;
+ }
};
ClosureParam bsdf_diffuse_params[] = {
- CLOSURE_VECTOR_PARAM (DiffuseClosure, m_N),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM (DiffuseClosure) };
+ CLOSURE_VECTOR_PARAM(DiffuseClosure, m_N),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(DiffuseClosure)
+};
ClosureParam bsdf_translucent_params[] = {
- CLOSURE_VECTOR_PARAM (TranslucentClosure, m_N),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM (TranslucentClosure) };
+ CLOSURE_VECTOR_PARAM(TranslucentClosure, m_N),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(TranslucentClosure)
+};
CLOSURE_PREPARE(bsdf_diffuse_prepare, DiffuseClosure)
CLOSURE_PREPARE(bsdf_translucent_prepare, TranslucentClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_microfacet.cpp b/intern/cycles/kernel/osl/bsdf_microfacet.cpp
index d87268da81e..09730d8c3e1 100644
--- a/intern/cycles/kernel/osl/bsdf_microfacet.cpp
+++ b/intern/cycles/kernel/osl/bsdf_microfacet.cpp
@@ -52,85 +52,85 @@ CCL_NAMESPACE_BEGIN
template <int Refractive = 0>
class MicrofacetGGXClosure : public BSDFClosure {
public:
- Vec3 m_N;
- float m_ag; // width parameter (roughness)
- float m_eta; // index of refraction (for fresnel term)
- MicrofacetGGXClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { m_eta = 1.0f; }
+ Vec3 m_N;
+ float m_ag; // width parameter (roughness)
+ float m_eta; // index of refraction (for fresnel term)
+ MicrofacetGGXClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { m_eta = 1.0f; }
- void setup()
+ void setup()
{
m_ag = clamp(m_ag, 1e-5f, 1.0f);
}
- bool mergeable (const ClosurePrimitive *other) const {
- const MicrofacetGGXClosure *comp = (const MicrofacetGGXClosure *)other;
- return m_N == comp->m_N && m_ag == comp->m_ag &&
- m_eta == comp->m_eta && BSDFClosure::mergeable(other);
- }
+ bool mergeable(const ClosurePrimitive *other) const {
+ const MicrofacetGGXClosure *comp = (const MicrofacetGGXClosure *)other;
+ return m_N == comp->m_N && m_ag == comp->m_ag &&
+ m_eta == comp->m_eta && BSDFClosure::mergeable(other);
+ }
- size_t memsize () const { return sizeof(*this); }
+ size_t memsize() const { return sizeof(*this); }
- const char *name () const {
- return Refractive ? "microfacet_ggx_refraction" : "microfacet_ggx";
- }
+ const char *name() const {
+ return Refractive ? "microfacet_ggx_refraction" : "microfacet_ggx";
+ }
- void print_on (std::ostream &out) const {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_ag << ", ";
- out << m_eta;
- out << ")";
- }
+ void print_on(std::ostream &out) const {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_ag << ", ";
+ out << m_eta;
+ out << ")";
+ }
- float albedo (const Vec3 &omega_out) const
- {
+ float albedo(const Vec3 &omega_out) const
+ {
return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- if (Refractive == 1) return Color3 (0, 0, 0);
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNI > 0 && cosNO > 0) {
- // get half vector
- Vec3 Hr = omega_in + omega_out;
- Hr.normalize();
- // eq. 20: (F*G*D)/(4*in*on)
- // eq. 33: first we calculate D(m) with m=Hr:
- float alpha2 = m_ag * m_ag;
- float cosThetaM = m_N.dot(Hr);
- float cosThetaM2 = cosThetaM * cosThetaM;
- float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = alpha2 / ((float) M_PI * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
- // eq. 34: now calculate G1(i,m) and G1(o,m)
- float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
- float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G = G1o * G1i;
- float out = (G * D) * 0.25f / cosNO;
- // eq. 24
- float pm = D * cosThetaM;
- // convert into pdf of the sampled direction
- // eq. 38 - but see also:
- // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
- pdf = pm * 0.25f / Hr.dot(omega_out);
- return Color3 (out, out, out);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- if (Refractive == 0) return Color3 (0, 0, 0);
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO <= 0 || cosNI >= 0)
- return Color3 (0, 0, 0); // vectors on same side -- not possible
- // compute half-vector of the refraction (eq. 16)
- Vec3 ht = -(m_eta * omega_in + omega_out);
- Vec3 Ht = ht; Ht.normalize();
- float cosHO = Ht.dot(omega_out);
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ if (Refractive == 1) return Color3(0, 0, 0);
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNI > 0 && cosNO > 0) {
+ // get half vector
+ Vec3 Hr = omega_in + omega_out;
+ Hr.normalize();
+ // eq. 20: (F*G*D)/(4*in*on)
+ // eq. 33: first we calculate D(m) with m=Hr:
+ float alpha2 = m_ag * m_ag;
+ float cosThetaM = m_N.dot(Hr);
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = alpha2 / ((float) M_PI * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
+ // eq. 34: now calculate G1(i,m) and G1(o,m)
+ float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G = G1o * G1i;
+ float out = (G * D) * 0.25f / cosNO;
+ // eq. 24
+ float pm = D * cosThetaM;
+ // convert into pdf of the sampled direction
+ // eq. 38 - but see also:
+ // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
+ pdf = pm * 0.25f / Hr.dot(omega_out);
+ return Color3(out, out, out);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ if (Refractive == 0) return Color3(0, 0, 0);
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO <= 0 || cosNI >= 0)
+ return Color3(0, 0, 0); // vectors on same side -- not possible
+ // compute half-vector of the refraction (eq. 16)
+ Vec3 ht = -(m_eta * omega_in + omega_out);
+ Vec3 Ht = ht; Ht.normalize();
+ float cosHO = Ht.dot(omega_out);
float cosHI = Ht.dot(omega_in);
// eq. 33: first we calculate D(m) with m=Ht:
@@ -148,122 +148,123 @@ public:
float invHt2 = 1 / ht.dot(ht);
pdf = D * fabsf(cosThetaM) * (fabsf(cosHI) * (m_eta * m_eta)) * invHt2;
float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D) * invHt2) / cosNO;
- return Color3 (out, out, out);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- float cosNO = m_N.dot(omega_out);
- if (cosNO > 0) {
- Vec3 X, Y, Z = m_N;
- make_orthonormals(Z, X, Y);
- // generate a random microfacet normal m
- // eq. 35,36:
- // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
- // and sin(atan(x)) == x/sqrt(1+x^2)
- float alpha2 = m_ag * m_ag;
- float tanThetaM2 = alpha2 * randu / (1 - randu);
- float cosThetaM = 1 / sqrtf(1 + tanThetaM2);
- float sinThetaM = cosThetaM * sqrtf(tanThetaM2);
- float phiM = 2 * float(M_PI) * randv;
- Vec3 m = (cosf(phiM) * sinThetaM) * X +
- (sinf(phiM) * sinThetaM) * Y +
- cosThetaM * Z;
- if (Refractive == 0) {
- float cosMO = m.dot(omega_out);
- if (cosMO > 0) {
- // eq. 39 - compute actual reflected direction
- omega_in = 2 * cosMO * m - omega_out;
- if (Ng.dot(omega_in) > 0) {
- // microfacet normal is visible to this ray
- // eq. 33
- float cosThetaM2 = cosThetaM * cosThetaM;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
- // eq. 24
- float pm = D * cosThetaM;
- // convert into pdf of the sampled direction
- // eq. 38 - but see also:
- // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
- pdf = pm * 0.25f / cosMO;
- // eval BRDF*cosNI
- float cosNI = m_N.dot(omega_in);
- // eq. 34: now calculate G1(i,m) and G1(o,m)
- float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
- float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G = G1o * G1i;
- // eq. 20: (F*G*D)/(4*in*on)
- float out = (G * D) * 0.25f / cosNO;
- eval.setValue(out, out, out);
- domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx;
- domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy;
+ return Color3(out, out, out);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ if (cosNO > 0) {
+ Vec3 X, Y, Z = m_N;
+ make_orthonormals(Z, X, Y);
+ // generate a random microfacet normal m
+ // eq. 35,36:
+ // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
+ // and sin(atan(x)) == x/sqrt(1+x^2)
+ float alpha2 = m_ag * m_ag;
+ float tanThetaM2 = alpha2 * randu / (1 - randu);
+ float cosThetaM = 1 / sqrtf(1 + tanThetaM2);
+ float sinThetaM = cosThetaM * sqrtf(tanThetaM2);
+ float phiM = 2 * float(M_PI) * randv;
+ Vec3 m = (cosf(phiM) * sinThetaM) * X +
+ (sinf(phiM) * sinThetaM) * Y +
+ cosThetaM * Z;
+ if (Refractive == 0) {
+ float cosMO = m.dot(omega_out);
+ if (cosMO > 0) {
+ // eq. 39 - compute actual reflected direction
+ omega_in = 2 * cosMO * m - omega_out;
+ if (Ng.dot(omega_in) > 0) {
+ // microfacet normal is visible to this ray
+ // eq. 33
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
+ // eq. 24
+ float pm = D * cosThetaM;
+ // convert into pdf of the sampled direction
+ // eq. 38 - but see also:
+ // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
+ pdf = pm * 0.25f / cosMO;
+ // eval BRDF*cosNI
+ float cosNI = m_N.dot(omega_in);
+ // eq. 34: now calculate G1(i,m) and G1(o,m)
+ float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G = G1o * G1i;
+ // eq. 20: (F*G*D)/(4*in*on)
+ float out = (G * D) * 0.25f / cosNO;
+ eval.setValue(out, out, out);
+ domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx;
+ domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy;
/* disabled for now - gives texture filtering problems */
#if 0
- // Since there is some blur to this reflection, make the
- // derivatives a bit bigger. In theory this varies with the
- // roughness but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
+ // Since there is some blur to this reflection, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // roughness but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
#endif
- }
- }
- } else {
- // CAUTION: the i and o variables are inverted relative to the paper
- // eq. 39 - compute actual refractive direction
- Vec3 R, dRdx, dRdy;
- Vec3 T, dTdx, dTdy;
- bool inside;
- fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy,
- R, dRdx, dRdy,
- T, dTdx, dTdy,
- inside);
-
- if (!inside) {
- omega_in = T;
- domega_in_dx = dTdx;
- domega_in_dy = dTdy;
- // eq. 33
- float cosThetaM2 = cosThetaM * cosThetaM;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
- // eq. 24
- float pm = D * cosThetaM;
- // eval BRDF*cosNI
- float cosNI = m_N.dot(omega_in);
- // eq. 34: now calculate G1(i,m) and G1(o,m)
- float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
- float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G = G1o * G1i;
- // eq. 21
- float cosHI = m.dot(omega_in);
- float cosHO = m.dot(omega_out);
- float Ht2 = m_eta * cosHI + cosHO;
- Ht2 *= Ht2;
- float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2);
- // eq. 38 and eq. 17
- pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2;
- eval.setValue(out, out, out);
+ }
+ }
+ }
+ else {
+ // CAUTION: the i and o variables are inverted relative to the paper
+ // eq. 39 - compute actual refractive direction
+ Vec3 R, dRdx, dRdy;
+ Vec3 T, dTdx, dTdy;
+ bool inside;
+ fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy,
+ R, dRdx, dRdy,
+ T, dTdx, dTdy,
+ inside);
+
+ if (!inside) {
+ omega_in = T;
+ domega_in_dx = dTdx;
+ domega_in_dy = dTdy;
+ // eq. 33
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = alpha2 / (float(M_PI) * cosThetaM4 * (alpha2 + tanThetaM2) * (alpha2 + tanThetaM2));
+ // eq. 24
+ float pm = D * cosThetaM;
+ // eval BRDF*cosNI
+ float cosNI = m_N.dot(omega_in);
+ // eq. 34: now calculate G1(i,m) and G1(o,m)
+ float G1o = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float G1i = 2 / (1 + sqrtf(1 + alpha2 * (1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G = G1o * G1i;
+ // eq. 21
+ float cosHI = m.dot(omega_in);
+ float cosHO = m.dot(omega_out);
+ float Ht2 = m_eta * cosHI + cosHO;
+ Ht2 *= Ht2;
+ float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2);
+ // eq. 38 and eq. 17
+ pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2;
+ eval.setValue(out, out, out);
/* disabled for now - gives texture filtering problems */
#if 0
- // Since there is some blur to this refraction, make the
- // derivatives a bit bigger. In theory this varies with the
- // roughness but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
+ // Since there is some blur to this refraction, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // roughness but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
#endif
- }
- }
- }
- return Refractive ? Labels::TRANSMIT : Labels::REFLECT;
- }
+ }
+ }
+ }
+ return Refractive ? Labels::TRANSMIT : Labels::REFLECT;
+ }
};
// microfacet model with Beckmann facet distribution
@@ -271,89 +272,92 @@ public:
template <int Refractive = 0>
class MicrofacetBeckmannClosure : public BSDFClosure {
public:
- Vec3 m_N;
- float m_ab; // width parameter (roughness)
- float m_eta; // index of refraction (for fresnel term)
- MicrofacetBeckmannClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) { }
+ Vec3 m_N;
+ float m_ab; // width parameter (roughness)
+ float m_eta; // index of refraction (for fresnel term)
+ MicrofacetBeckmannClosure() : BSDFClosure(Labels::GLOSSY, Refractive ? Back : Front) {
+ }
- void setup()
+ void setup()
{
m_ab = clamp(m_ab, 1e-5f, 1.0f);
}
- bool mergeable (const ClosurePrimitive *other) const {
- const MicrofacetBeckmannClosure *comp = (const MicrofacetBeckmannClosure *)other;
- return m_N == comp->m_N && m_ab == comp->m_ab &&
- m_eta == comp->m_eta && BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char * name () const {
- return Refractive ? "microfacet_beckmann_refraction"
- : "microfacet_beckmann";
- }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_ab << ", ";
- out << m_eta;
- out << ")";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
+ bool mergeable(const ClosurePrimitive *other) const {
+ const MicrofacetBeckmannClosure *comp = (const MicrofacetBeckmannClosure *)other;
+ return m_N == comp->m_N && m_ab == comp->m_ab &&
+ m_eta == comp->m_eta && BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const {
+ return sizeof(*this);
+ }
+
+ const char *name() const {
+ return Refractive ? "microfacet_beckmann_refraction"
+ : "microfacet_beckmann";
+ }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_ab << ", ";
+ out << m_eta;
+ out << ")";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- if (Refractive == 1) return Color3 (0, 0, 0);
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO > 0 && cosNI > 0) {
- // get half vector
- Vec3 Hr = omega_in + omega_out;
- Hr.normalize();
- // eq. 20: (F*G*D)/(4*in*on)
- // eq. 25: first we calculate D(m) with m=Hr:
- float alpha2 = m_ab * m_ab;
- float cosThetaM = m_N.dot(Hr);
- float cosThetaM2 = cosThetaM * cosThetaM;
- float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
- // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
- float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
- float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
- float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
- float G = G1o * G1i;
- float out = (G * D) * 0.25f / cosNO;
- // eq. 24
- float pm = D * cosThetaM;
- // convert into pdf of the sampled direction
- // eq. 38 - but see also:
- // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
- pdf = pm * 0.25f / Hr.dot(omega_out);
- return Color3 (out, out, out);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- if (Refractive == 0) return Color3 (0, 0, 0);
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO <= 0 || cosNI >= 0)
- return Color3 (0, 0, 0);
- // compute half-vector of the refraction (eq. 16)
- Vec3 ht = -(m_eta * omega_in + omega_out);
- Vec3 Ht = ht; Ht.normalize();
- float cosHO = Ht.dot(omega_out);
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ if (Refractive == 1) return Color3(0, 0, 0);
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO > 0 && cosNI > 0) {
+ // get half vector
+ Vec3 Hr = omega_in + omega_out;
+ Hr.normalize();
+ // eq. 20: (F*G*D)/(4*in*on)
+ // eq. 25: first we calculate D(m) with m=Hr:
+ float alpha2 = m_ab * m_ab;
+ float cosThetaM = m_N.dot(Hr);
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float tanThetaM2 = (1 - cosThetaM2) / cosThetaM2;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
+ // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
+ float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
+ float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
+ float G = G1o * G1i;
+ float out = (G * D) * 0.25f / cosNO;
+ // eq. 24
+ float pm = D * cosThetaM;
+ // convert into pdf of the sampled direction
+ // eq. 38 - but see also:
+ // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
+ pdf = pm * 0.25f / Hr.dot(omega_out);
+ return Color3(out, out, out);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ if (Refractive == 0) return Color3(0, 0, 0);
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO <= 0 || cosNI >= 0)
+ return Color3(0, 0, 0);
+ // compute half-vector of the refraction (eq. 16)
+ Vec3 ht = -(m_eta * omega_in + omega_out);
+ Vec3 Ht = ht; Ht.normalize();
+ float cosHO = Ht.dot(omega_out);
float cosHI = Ht.dot(omega_in);
// eq. 33: first we calculate D(m) with m=Ht:
@@ -373,156 +377,161 @@ public:
float invHt2 = 1 / ht.dot(ht);
pdf = D * fabsf(cosThetaM) * (fabsf(cosHI) * (m_eta * m_eta)) * invHt2;
float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D) * invHt2) / cosNO;
- return Color3 (out, out, out);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- float cosNO = m_N.dot(omega_out);
- if (cosNO > 0) {
- Vec3 X, Y, Z = m_N;
- make_orthonormals(Z, X, Y);
- // generate a random microfacet normal m
- // eq. 35,36:
- // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
- // and sin(atan(x)) == x/sqrt(1+x^2)
- float alpha2 = m_ab * m_ab;
- float tanThetaM = sqrtf(-alpha2 * logf(1 - randu));
- float cosThetaM = 1 / sqrtf(1 + tanThetaM * tanThetaM);
- float sinThetaM = cosThetaM * tanThetaM;
- float phiM = 2 * float(M_PI) * randv;
- Vec3 m = (cosf(phiM) * sinThetaM) * X +
- (sinf(phiM) * sinThetaM) * Y +
- cosThetaM * Z;
- if (Refractive == 0) {
- float cosMO = m.dot(omega_out);
- if (cosMO > 0) {
- // eq. 39 - compute actual reflected direction
- omega_in = 2 * cosMO * m - omega_out;
- if (Ng.dot(omega_in) > 0) {
- // microfacet normal is visible to this ray
- // eq. 25
- float cosThetaM2 = cosThetaM * cosThetaM;
- float tanThetaM2 = tanThetaM * tanThetaM;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
- // eq. 24
- float pm = D * cosThetaM;
- // convert into pdf of the sampled direction
- // eq. 38 - but see also:
- // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
- pdf = pm * 0.25f / cosMO;
- // Eval BRDF*cosNI
- float cosNI = m_N.dot(omega_in);
- // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
- float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
- float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
- float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
- float G = G1o * G1i;
- // eq. 20: (F*G*D)/(4*in*on)
- float out = (G * D) * 0.25f / cosNO;
- eval.setValue(out, out, out);
- domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx;
- domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy;
+ return Color3(out, out, out);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ if (cosNO > 0) {
+ Vec3 X, Y, Z = m_N;
+ make_orthonormals(Z, X, Y);
+ // generate a random microfacet normal m
+ // eq. 35,36:
+ // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
+ // and sin(atan(x)) == x/sqrt(1+x^2)
+ float alpha2 = m_ab * m_ab;
+ float tanThetaM = sqrtf(-alpha2 * logf(1 - randu));
+ float cosThetaM = 1 / sqrtf(1 + tanThetaM * tanThetaM);
+ float sinThetaM = cosThetaM * tanThetaM;
+ float phiM = 2 * float(M_PI) * randv;
+ Vec3 m = (cosf(phiM) * sinThetaM) * X +
+ (sinf(phiM) * sinThetaM) * Y +
+ cosThetaM * Z;
+ if (Refractive == 0) {
+ float cosMO = m.dot(omega_out);
+ if (cosMO > 0) {
+ // eq. 39 - compute actual reflected direction
+ omega_in = 2 * cosMO * m - omega_out;
+ if (Ng.dot(omega_in) > 0) {
+ // microfacet normal is visible to this ray
+ // eq. 25
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float tanThetaM2 = tanThetaM * tanThetaM;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
+ // eq. 24
+ float pm = D * cosThetaM;
+ // convert into pdf of the sampled direction
+ // eq. 38 - but see also:
+ // eq. 17 in http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
+ pdf = pm * 0.25f / cosMO;
+ // Eval BRDF*cosNI
+ float cosNI = m_N.dot(omega_in);
+ // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
+ float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
+ float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
+ float G = G1o * G1i;
+ // eq. 20: (F*G*D)/(4*in*on)
+ float out = (G * D) * 0.25f / cosNO;
+ eval.setValue(out, out, out);
+ domega_in_dx = (2 * m.dot(domega_out_dx)) * m - domega_out_dx;
+ domega_in_dy = (2 * m.dot(domega_out_dy)) * m - domega_out_dy;
/* disabled for now - gives texture filtering problems */
#if 0
- // Since there is some blur to this reflection, make the
- // derivatives a bit bigger. In theory this varies with the
- // roughness but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
+ // Since there is some blur to this reflection, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // roughness but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
#endif
- }
- }
- } else {
- // CAUTION: the i and o variables are inverted relative to the paper
- // eq. 39 - compute actual refractive direction
- Vec3 R, dRdx, dRdy;
- Vec3 T, dTdx, dTdy;
- bool inside;
- fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy,
- R, dRdx, dRdy,
- T, dTdx, dTdy,
- inside);
- if (!inside) {
- omega_in = T;
- domega_in_dx = dTdx;
- domega_in_dy = dTdy;
- // eq. 33
- float cosThetaM2 = cosThetaM * cosThetaM;
- float tanThetaM2 = tanThetaM * tanThetaM;
- float cosThetaM4 = cosThetaM2 * cosThetaM2;
- float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
- // eq. 24
- float pm = D * cosThetaM;
- // eval BRDF*cosNI
- float cosNI = m_N.dot(omega_in);
- // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
- float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
- float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
- float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
- float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
- float G = G1o * G1i;
- // eq. 21
- float cosHI = m.dot(omega_in);
- float cosHO = m.dot(omega_out);
- float Ht2 = m_eta * cosHI + cosHO;
- Ht2 *= Ht2;
- float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2);
- // eq. 38 and eq. 17
- pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2;
- eval.setValue(out, out, out);
+ }
+ }
+ }
+ else {
+ // CAUTION: the i and o variables are inverted relative to the paper
+ // eq. 39 - compute actual refractive direction
+ Vec3 R, dRdx, dRdy;
+ Vec3 T, dTdx, dTdy;
+ bool inside;
+ fresnel_dielectric(m_eta, m, omega_out, domega_out_dx, domega_out_dy,
+ R, dRdx, dRdy,
+ T, dTdx, dTdy,
+ inside);
+ if (!inside) {
+ omega_in = T;
+ domega_in_dx = dTdx;
+ domega_in_dy = dTdy;
+ // eq. 33
+ float cosThetaM2 = cosThetaM * cosThetaM;
+ float tanThetaM2 = tanThetaM * tanThetaM;
+ float cosThetaM4 = cosThetaM2 * cosThetaM2;
+ float D = expf(-tanThetaM2 / alpha2) / (float(M_PI) * alpha2 * cosThetaM4);
+ // eq. 24
+ float pm = D * cosThetaM;
+ // eval BRDF*cosNI
+ float cosNI = m_N.dot(omega_in);
+ // eq. 26, 27: now calculate G1(i,m) and G1(o,m)
+ float ao = 1 / (m_ab * sqrtf((1 - cosNO * cosNO) / (cosNO * cosNO)));
+ float ai = 1 / (m_ab * sqrtf((1 - cosNI * cosNI) / (cosNI * cosNI)));
+ float G1o = ao < 1.6f ? (3.535f * ao + 2.181f * ao * ao) / (1 + 2.276f * ao + 2.577f * ao * ao) : 1.0f;
+ float G1i = ai < 1.6f ? (3.535f * ai + 2.181f * ai * ai) / (1 + 2.276f * ai + 2.577f * ai * ai) : 1.0f;
+ float G = G1o * G1i;
+ // eq. 21
+ float cosHI = m.dot(omega_in);
+ float cosHO = m.dot(omega_out);
+ float Ht2 = m_eta * cosHI + cosHO;
+ Ht2 *= Ht2;
+ float out = (fabsf(cosHI * cosHO) * (m_eta * m_eta) * (G * D)) / (cosNO * Ht2);
+ // eq. 38 and eq. 17
+ pdf = pm * (m_eta * m_eta) * fabsf(cosHI) / Ht2;
+ eval.setValue(out, out, out);
/* disabled for now - gives texture filtering problems */
#if 0
- // Since there is some blur to this refraction, make the
- // derivatives a bit bigger. In theory this varies with the
- // roughness but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
+ // Since there is some blur to this refraction, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // roughness but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
#endif
- }
- }
- }
- return Refractive ? Labels::TRANSMIT : Labels::REFLECT;
- }
+ }
+ }
+ }
+ return Refractive ? Labels::TRANSMIT : Labels::REFLECT;
+ }
};
ClosureParam bsdf_microfacet_ggx_params[] = {
- CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<0>, m_N),
- CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<0>, m_ag),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<0>) };
+ CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<0>, m_N),
+ CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<0>, m_ag),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<0>)
+};
ClosureParam bsdf_microfacet_ggx_refraction_params[] = {
- CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<1>, m_N),
- CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<1>, m_ag),
- CLOSURE_FLOAT_PARAM (MicrofacetGGXClosure<1>, m_eta),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<1>) };
+ CLOSURE_VECTOR_PARAM(MicrofacetGGXClosure<1>, m_N),
+ CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<1>, m_ag),
+ CLOSURE_FLOAT_PARAM(MicrofacetGGXClosure<1>, m_eta),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(MicrofacetGGXClosure<1>)
+};
ClosureParam bsdf_microfacet_beckmann_params[] = {
- CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<0>, m_N),
- CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<0>, m_ab),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<0>) };
+ CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<0>, m_N),
+ CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<0>, m_ab),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<0>)
+};
ClosureParam bsdf_microfacet_beckmann_refraction_params[] = {
- CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<1>, m_N),
- CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<1>, m_ab),
- CLOSURE_FLOAT_PARAM (MicrofacetBeckmannClosure<1>, m_eta),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<1>) };
+ CLOSURE_VECTOR_PARAM(MicrofacetBeckmannClosure<1>, m_N),
+ CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<1>, m_ab),
+ CLOSURE_FLOAT_PARAM(MicrofacetBeckmannClosure<1>, m_eta),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(MicrofacetBeckmannClosure<1>)
+};
CLOSURE_PREPARE(bsdf_microfacet_ggx_prepare, MicrofacetGGXClosure<0>)
CLOSURE_PREPARE(bsdf_microfacet_ggx_refraction_prepare, MicrofacetGGXClosure<1>)
diff --git a/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp b/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp
index 5d2ca909f93..83d0e583695 100644
--- a/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp
+++ b/intern/cycles/kernel/osl/bsdf_oren_nayar.cpp
@@ -19,19 +19,20 @@
#include <OpenImageIO/fmath.h>
#include <OSL/genclosure.h>
#include "osl_closures.h"
+#include "util_math.h"
CCL_NAMESPACE_BEGIN
using namespace OSL;
-class OrenNayarClosure: public BSDFClosure {
+class OrenNayarClosure : public BSDFClosure {
public:
Vec3 m_N;
float m_sigma;
float m_a, m_b;
- OrenNayarClosure(): BSDFClosure(Labels::DIFFUSE) {}
+ OrenNayarClosure() : BSDFClosure(Labels::DIFFUSE) {}
void setup() {
m_sigma = clamp(m_sigma, 0.0f, 1.0f);
@@ -42,19 +43,19 @@ public:
m_b = m_sigma * div;
}
- bool mergeable(const ClosurePrimitive* other) const {
- const OrenNayarClosure* comp = static_cast<const OrenNayarClosure*>(other);
+ bool mergeable(const ClosurePrimitive *other) const {
+ const OrenNayarClosure *comp = static_cast<const OrenNayarClosure *>(other);
return
- m_N == comp->m_N &&
- m_sigma == comp->m_sigma &&
- BSDFClosure::mergeable(other);
+ m_N == comp->m_N &&
+ m_sigma == comp->m_sigma &&
+ BSDFClosure::mergeable(other);
}
size_t memsize() const {
return sizeof(*this);
}
- const char* name() const {
+ const char *name() const {
return "oren_nayar";
}
@@ -86,13 +87,13 @@ public:
}
ustring sample(
- const Vec3& Ng,
- const Vec3& omega_out, const Vec3& domega_out_dx, const Vec3& domega_out_dy,
- float randu, float randv,
- Vec3& omega_in, Vec3& domega_in_dx, Vec3& domega_in_dy,
- float& pdf, Color3& eval
- ) const {
- sample_uniform_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf);
+ const Vec3& Ng,
+ const Vec3& omega_out, const Vec3& domega_out_dx, const Vec3& domega_out_dy,
+ float randu, float randv,
+ Vec3& omega_in, Vec3& domega_in_dx, Vec3& domega_in_dy,
+ float& pdf, Color3& eval
+ ) const {
+ sample_uniform_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf);
if (Ng.dot(omega_in) > 0.0f) {
float is = get_intensity(m_N, omega_out, omega_in);
@@ -117,18 +118,18 @@ private:
float nv = max(n.dot(v), 0.0f);
float t = l.dot(v) - nl * nv;
- if(t > 0.0f) {
- t /= max(nl, vl) + 1e-8f;
+ if (t > 0.0f) {
+ t /= max(nl, nv) + 1e-8f;
}
return nl * (m_a + m_b * t);
}
};
ClosureParam bsdf_oren_nayar_params[] = {
- CLOSURE_VECTOR_PARAM (OrenNayarClosure, m_N),
- CLOSURE_FLOAT_PARAM (OrenNayarClosure, m_sigma),
- CLOSURE_STRING_KEYPARAM ("label"),
- CLOSURE_FINISH_PARAM (OrenNayarClosure)
+ CLOSURE_VECTOR_PARAM(OrenNayarClosure, m_N),
+ CLOSURE_FLOAT_PARAM(OrenNayarClosure, m_sigma),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(OrenNayarClosure)
};
CLOSURE_PREPARE(bsdf_oren_nayar_prepare, OrenNayarClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_reflection.cpp b/intern/cycles/kernel/osl/bsdf_reflection.cpp
index b0caff6df44..7041b4ced6f 100644
--- a/intern/cycles/kernel/osl/bsdf_reflection.cpp
+++ b/intern/cycles/kernel/osl/bsdf_reflection.cpp
@@ -42,65 +42,66 @@ using namespace OSL;
class ReflectionClosure : public BSDFClosure {
public:
- Vec3 m_N; // shading normal
- ReflectionClosure() : BSDFClosure(Labels::SINGULAR) { }
-
- void setup() {};
-
- bool mergeable (const ClosurePrimitive *other) const {
- const ReflectionClosure *comp = (const ReflectionClosure *)other;
- return m_N == comp->m_N && BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "reflection"; }
-
- void print_on (std::ostream &out) const {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // only one direction is possible
- float cosNO = m_N.dot(omega_out);
- if (cosNO > 0) {
- omega_in = (2 * cosNO) * m_N - omega_out;
- if (Ng.dot(omega_in) > 0) {
- domega_in_dx = 2 * m_N.dot(domega_out_dx) * m_N - domega_out_dx;
- domega_in_dy = 2 * m_N.dot(domega_out_dy) * m_N - domega_out_dy;
- pdf = 1;
- eval.setValue(1, 1, 1);
- }
- }
- return Labels::REFLECT;
- }
+ Vec3 m_N; // shading normal
+ ReflectionClosure() : BSDFClosure(Labels::SINGULAR) {}
+
+ void setup() {};
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const ReflectionClosure *comp = (const ReflectionClosure *)other;
+ return m_N == comp->m_N && BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "reflection"; }
+
+ void print_on(std::ostream &out) const {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "))";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // only one direction is possible
+ float cosNO = m_N.dot(omega_out);
+ if (cosNO > 0) {
+ omega_in = (2 * cosNO) * m_N - omega_out;
+ if (Ng.dot(omega_in) > 0) {
+ domega_in_dx = 2 * m_N.dot(domega_out_dx) * m_N - domega_out_dx;
+ domega_in_dy = 2 * m_N.dot(domega_out_dy) * m_N - domega_out_dy;
+ pdf = 1;
+ eval.setValue(1, 1, 1);
+ }
+ }
+ return Labels::REFLECT;
+ }
};
ClosureParam bsdf_reflection_params[] = {
- CLOSURE_VECTOR_PARAM(ReflectionClosure, m_N),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(ReflectionClosure) };
+ CLOSURE_VECTOR_PARAM(ReflectionClosure, m_N),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(ReflectionClosure)
+};
CLOSURE_PREPARE(bsdf_reflection_prepare, ReflectionClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_refraction.cpp b/intern/cycles/kernel/osl/bsdf_refraction.cpp
index 3ae7a3811b4..f56ad7b127c 100644
--- a/intern/cycles/kernel/osl/bsdf_refraction.cpp
+++ b/intern/cycles/kernel/osl/bsdf_refraction.cpp
@@ -42,77 +42,78 @@ using namespace OSL;
class RefractionClosure : public BSDFClosure {
public:
- Vec3 m_N; // shading normal
- float m_eta; // ratio of indices of refraction (inside / outside)
- RefractionClosure() : BSDFClosure(Labels::SINGULAR, Back) { }
+ Vec3 m_N; // shading normal
+ float m_eta; // ratio of indices of refraction (inside / outside)
+ RefractionClosure() : BSDFClosure(Labels::SINGULAR, Back) {}
- void setup() {}
+ void setup() {}
- bool mergeable (const ClosurePrimitive *other) const {
- const RefractionClosure *comp = (const RefractionClosure *)other;
- return m_N == comp->m_N && m_eta == comp->m_eta &&
- BSDFClosure::mergeable(other);
- }
+ bool mergeable(const ClosurePrimitive *other) const {
+ const RefractionClosure *comp = (const RefractionClosure *)other;
+ return m_N == comp->m_N && m_eta == comp->m_eta &&
+ BSDFClosure::mergeable(other);
+ }
- size_t memsize () const { return sizeof(*this); }
+ size_t memsize() const { return sizeof(*this); }
- const char *name () const { return "refraction"; }
+ const char *name() const { return "refraction"; }
- void print_on (std::ostream &out) const {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_eta;
- out << ")";
- }
+ void print_on(std::ostream &out) const {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_eta;
+ out << ")";
+ }
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
- float albedo (const Vec3 &omega_out) const
- {
+ float albedo(const Vec3 &omega_out) const
+ {
return 1.0f;
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- Vec3 R, dRdx, dRdy;
- Vec3 T, dTdx, dTdy;
- bool inside;
-
- fresnel_dielectric(m_eta, m_N,
- omega_out, domega_out_dx, domega_out_dy,
- R, dRdx, dRdy,
- T, dTdx, dTdy,
- inside);
-
- if (!inside) {
- pdf = 1;
- eval.setValue(1.0f, 1.0f, 1.0f);
- omega_in = T;
- domega_in_dx = dTdx;
- domega_in_dy = dTdy;
- }
-
- return Labels::TRANSMIT;
- }
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ Vec3 R, dRdx, dRdy;
+ Vec3 T, dTdx, dTdy;
+ bool inside;
+
+ fresnel_dielectric(m_eta, m_N,
+ omega_out, domega_out_dx, domega_out_dy,
+ R, dRdx, dRdy,
+ T, dTdx, dTdy,
+ inside);
+
+ if (!inside) {
+ pdf = 1;
+ eval.setValue(1.0f, 1.0f, 1.0f);
+ omega_in = T;
+ domega_in_dx = dTdx;
+ domega_in_dy = dTdy;
+ }
+
+ return Labels::TRANSMIT;
+ }
};
ClosureParam bsdf_refraction_params[] = {
- CLOSURE_VECTOR_PARAM(RefractionClosure, m_N),
- CLOSURE_FLOAT_PARAM (RefractionClosure, m_eta),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(RefractionClosure) };
+ CLOSURE_VECTOR_PARAM(RefractionClosure, m_N),
+ CLOSURE_FLOAT_PARAM(RefractionClosure, m_eta),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(RefractionClosure)
+};
CLOSURE_PREPARE(bsdf_refraction_prepare, RefractionClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_transparent.cpp b/intern/cycles/kernel/osl/bsdf_transparent.cpp
index 941abd6a483..acde92530a2 100644
--- a/intern/cycles/kernel/osl/bsdf_transparent.cpp
+++ b/intern/cycles/kernel/osl/bsdf_transparent.cpp
@@ -42,54 +42,55 @@ using namespace OSL;
class TransparentClosure : public BSDFClosure {
public:
- TransparentClosure() : BSDFClosure(Labels::STRAIGHT, Back) { }
-
- void setup() {}
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "transparent"; }
-
- void print_on (std::ostream &out) const {
- out << name() << " ()";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // only one direction is possible
- omega_in = -omega_out;
- domega_in_dx = -domega_out_dx;
- domega_in_dy = -domega_out_dy;
- pdf = 1;
- eval.setValue(1, 1, 1);
- return Labels::TRANSMIT;
- }
+ TransparentClosure() : BSDFClosure(Labels::STRAIGHT, Back) {}
+
+ void setup() {}
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "transparent"; }
+
+ void print_on(std::ostream &out) const {
+ out << name() << " ()";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // only one direction is possible
+ omega_in = -omega_out;
+ domega_in_dx = -domega_out_dx;
+ domega_in_dy = -domega_out_dy;
+ pdf = 1;
+ eval.setValue(1, 1, 1);
+ return Labels::TRANSMIT;
+ }
};
ClosureParam bsdf_transparent_params[] = {
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(TransparentClosure) };
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(TransparentClosure)
+};
CLOSURE_PREPARE(bsdf_transparent_prepare, TransparentClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_ward.cpp b/intern/cycles/kernel/osl/bsdf_ward.cpp
index a7742a04d13..4aacbc4ffc3 100644
--- a/intern/cycles/kernel/osl/bsdf_ward.cpp
+++ b/intern/cycles/kernel/osl/bsdf_ward.cpp
@@ -46,175 +46,179 @@ using namespace OSL;
// see http://www.graphics.cornell.edu/~bjw/wardnotes.pdf
class WardClosure : public BSDFClosure {
public:
- Vec3 m_N;
- Vec3 m_T;
- float m_ax, m_ay;
- WardClosure() : BSDFClosure(Labels::GLOSSY) { }
+ Vec3 m_N;
+ Vec3 m_T;
+ float m_ax, m_ay;
+ WardClosure() : BSDFClosure(Labels::GLOSSY) {}
- void setup()
+ void setup()
{
m_ax = clamp(m_ax, 1e-5f, 1.0f);
m_ay = clamp(m_ay, 1e-5f, 1.0f);
}
- bool mergeable (const ClosurePrimitive *other) const {
- const WardClosure *comp = (const WardClosure *)other;
- return m_N == comp->m_N && m_T == comp->m_T &&
- m_ax == comp->m_ax && m_ay == comp->m_ay &&
- BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "ward"; }
-
- void print_on (std::ostream &out) const {
- out << name() << " ((";
- out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), (";
- out << m_T[0] << ", " << m_T[1] << ", " << m_T[2] << "), ";
- out << m_ax << ", " << m_ay << ")";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNI > 0 && cosNO > 0) {
- // get half vector and get x,y basis on the surface for anisotropy
- Vec3 H = omega_in + omega_out;
- H.normalize(); // normalize needed for pdf
- Vec3 X, Y;
- make_orthonormals(m_N, m_T, X, Y);
- // eq. 4
- float dotx = H.dot(X) / m_ax;
- float doty = H.dot(Y) / m_ay;
- float dotn = H.dot(m_N);
- float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
- float denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI));
- float exp_val = expf(-exp_arg);
- float out = cosNI * exp_val / denom;
- float oh = H.dot(omega_out);
- denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn;
- pdf = exp_val / denom;
- return Color3 (out, out, out);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- float cosNO = m_N.dot(omega_out);
- if (cosNO > 0) {
- // get x,y basis on the surface for anisotropy
- Vec3 X, Y;
- make_orthonormals(m_N, m_T, X, Y);
- // generate random angles for the half vector
- // eq. 7 (taking care around discontinuities to keep
- // output angle in the right quadrant)
- // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
- // and sin(atan(x)) == x/sqrt(1+x^2)
- float alphaRatio = m_ay / m_ax;
- float cosPhi, sinPhi;
- if (randu < 0.25f) {
- float val = 4 * randu;
- float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
- cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi);
- sinPhi = tanPhi * cosPhi;
- } else if (randu < 0.5) {
- float val = 1 - 4 * (0.5f - randu);
- float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
- // phi = (float) M_PI - phi;
- cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi);
- sinPhi = -tanPhi * cosPhi;
- } else if (randu < 0.75f) {
- float val = 4 * (randu - 0.5f);
- float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
- //phi = (float) M_PI + phi;
- cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi);
- sinPhi = tanPhi * cosPhi;
- } else {
- float val = 1 - 4 * (1 - randu);
- float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
- // phi = 2 * (float) M_PI - phi;
- cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi);
- sinPhi = -tanPhi * cosPhi;
- }
- // eq. 6
- // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
- // and sin(atan(x)) == x/sqrt(1+x^2)
- float thetaDenom = (cosPhi * cosPhi) / (m_ax * m_ax) + (sinPhi * sinPhi) / (m_ay * m_ay);
- float tanTheta2 = -logf(1 - randv) / thetaDenom;
- float cosTheta = 1 / sqrtf(1 + tanTheta2);
- float sinTheta = cosTheta * sqrtf(tanTheta2);
-
- Vec3 h; // already normalized becaused expressed from spherical coordinates
- h.x = sinTheta * cosPhi;
- h.y = sinTheta * sinPhi;
- h.z = cosTheta;
- // compute terms that are easier in local space
- float dotx = h.x / m_ax;
- float doty = h.y / m_ay;
- float dotn = h.z;
- // transform to world space
- h = h.x * X + h.y * Y + h.z * m_N;
- // generate the final sample
- float oh = h.dot(omega_out);
- omega_in.x = 2 * oh * h.x - omega_out.x;
- omega_in.y = 2 * oh * h.y - omega_out.y;
- omega_in.z = 2 * oh * h.z - omega_out.z;
- if (Ng.dot(omega_in) > 0) {
- float cosNI = m_N.dot(omega_in);
- if (cosNI > 0) {
- // eq. 9
- float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
- float denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn;
- pdf = expf(-exp_arg) / denom;
- // compiler will reuse expressions already computed
- denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI));
- float power = cosNI * expf(-exp_arg) / denom;
- eval.setValue(power, power, power);
- domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
- domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
+ bool mergeable(const ClosurePrimitive *other) const {
+ const WardClosure *comp = (const WardClosure *)other;
+ return m_N == comp->m_N && m_T == comp->m_T &&
+ m_ax == comp->m_ax && m_ay == comp->m_ay &&
+ BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "ward"; }
+
+ void print_on(std::ostream &out) const {
+ out << name() << " ((";
+ out << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), (";
+ out << m_T[0] << ", " << m_T[1] << ", " << m_T[2] << "), ";
+ out << m_ax << ", " << m_ay << ")";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNI > 0 && cosNO > 0) {
+ // get half vector and get x,y basis on the surface for anisotropy
+ Vec3 H = omega_in + omega_out;
+ H.normalize(); // normalize needed for pdf
+ Vec3 X, Y;
+ make_orthonormals(m_N, m_T, X, Y);
+ // eq. 4
+ float dotx = H.dot(X) / m_ax;
+ float doty = H.dot(Y) / m_ay;
+ float dotn = H.dot(m_N);
+ float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
+ float denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI));
+ float exp_val = expf(-exp_arg);
+ float out = cosNI * exp_val / denom;
+ float oh = H.dot(omega_out);
+ denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn;
+ pdf = exp_val / denom;
+ return Color3(out, out, out);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float& pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ if (cosNO > 0) {
+ // get x,y basis on the surface for anisotropy
+ Vec3 X, Y;
+ make_orthonormals(m_N, m_T, X, Y);
+ // generate random angles for the half vector
+ // eq. 7 (taking care around discontinuities to keep
+ // output angle in the right quadrant)
+ // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
+ // and sin(atan(x)) == x/sqrt(1+x^2)
+ float alphaRatio = m_ay / m_ax;
+ float cosPhi, sinPhi;
+ if (randu < 0.25f) {
+ float val = 4 * randu;
+ float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
+ cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi);
+ sinPhi = tanPhi * cosPhi;
+ }
+ else if (randu < 0.5) {
+ float val = 1 - 4 * (0.5f - randu);
+ float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
+ // phi = (float) M_PI - phi;
+ cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi);
+ sinPhi = -tanPhi * cosPhi;
+ }
+ else if (randu < 0.75f) {
+ float val = 4 * (randu - 0.5f);
+ float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
+ //phi = (float) M_PI + phi;
+ cosPhi = -1 / sqrtf(1 + tanPhi * tanPhi);
+ sinPhi = tanPhi * cosPhi;
+ }
+ else {
+ float val = 1 - 4 * (1 - randu);
+ float tanPhi = alphaRatio * tanf((float) M_PI_2 * val);
+ // phi = 2 * (float) M_PI - phi;
+ cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi);
+ sinPhi = -tanPhi * cosPhi;
+ }
+ // eq. 6
+ // we take advantage of cos(atan(x)) == 1/sqrt(1+x^2)
+ // and sin(atan(x)) == x/sqrt(1+x^2)
+ float thetaDenom = (cosPhi * cosPhi) / (m_ax * m_ax) + (sinPhi * sinPhi) / (m_ay * m_ay);
+ float tanTheta2 = -logf(1 - randv) / thetaDenom;
+ float cosTheta = 1 / sqrtf(1 + tanTheta2);
+ float sinTheta = cosTheta * sqrtf(tanTheta2);
+
+ Vec3 h; // already normalized becaused expressed from spherical coordinates
+ h.x = sinTheta * cosPhi;
+ h.y = sinTheta * sinPhi;
+ h.z = cosTheta;
+ // compute terms that are easier in local space
+ float dotx = h.x / m_ax;
+ float doty = h.y / m_ay;
+ float dotn = h.z;
+ // transform to world space
+ h = h.x * X + h.y * Y + h.z * m_N;
+ // generate the final sample
+ float oh = h.dot(omega_out);
+ omega_in.x = 2 * oh * h.x - omega_out.x;
+ omega_in.y = 2 * oh * h.y - omega_out.y;
+ omega_in.z = 2 * oh * h.z - omega_out.z;
+ if (Ng.dot(omega_in) > 0) {
+ float cosNI = m_N.dot(omega_in);
+ if (cosNI > 0) {
+ // eq. 9
+ float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
+ float denom = 4 * (float) M_PI * m_ax * m_ay * oh * dotn * dotn * dotn;
+ pdf = expf(-exp_arg) / denom;
+ // compiler will reuse expressions already computed
+ denom = (4 * (float) M_PI * m_ax * m_ay * sqrtf(cosNO * cosNI));
+ float power = cosNI * expf(-exp_arg) / denom;
+ eval.setValue(power, power, power);
+ domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
+ domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
/* disabled for now - gives texture filtering problems */
#if 0
- // Since there is some blur to this reflection, make the
- // derivatives a bit bigger. In theory this varies with the
- // roughness but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
+ // Since there is some blur to this reflection, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // roughness but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
#endif
- }
- }
- }
- return Labels::REFLECT;
- }
+ }
+ }
+ }
+ return Labels::REFLECT;
+ }
};
ClosureParam bsdf_ward_params[] = {
- CLOSURE_VECTOR_PARAM(WardClosure, m_N),
- CLOSURE_VECTOR_PARAM(WardClosure, m_T),
- CLOSURE_FLOAT_PARAM (WardClosure, m_ax),
- CLOSURE_FLOAT_PARAM (WardClosure, m_ay),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(WardClosure) };
+ CLOSURE_VECTOR_PARAM(WardClosure, m_N),
+ CLOSURE_VECTOR_PARAM(WardClosure, m_T),
+ CLOSURE_FLOAT_PARAM(WardClosure, m_ax),
+ CLOSURE_FLOAT_PARAM(WardClosure, m_ay),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(WardClosure)
+};
CLOSURE_PREPARE(bsdf_ward_prepare, WardClosure)
diff --git a/intern/cycles/kernel/osl/bsdf_westin.cpp b/intern/cycles/kernel/osl/bsdf_westin.cpp
index d322f6a7f7e..a476e8045f7 100644
--- a/intern/cycles/kernel/osl/bsdf_westin.cpp
+++ b/intern/cycles/kernel/osl/bsdf_westin.cpp
@@ -44,193 +44,197 @@ using namespace OSL;
class WestinBackscatterClosure : public BSDFClosure {
public:
- Vec3 m_N;
- float m_roughness;
- float m_invroughness;
- WestinBackscatterClosure() : BSDFClosure(Labels::GLOSSY) { }
+ Vec3 m_N;
+ float m_roughness;
+ float m_invroughness;
+ WestinBackscatterClosure() : BSDFClosure(Labels::GLOSSY) {}
- void setup()
- {
+ void setup()
+ {
m_roughness = clamp(m_roughness, 1e-5f, 1.0f);
- m_invroughness = m_roughness > 0 ? 1 / m_roughness : 0;
- }
-
- bool mergeable (const ClosurePrimitive *other) const {
- const WestinBackscatterClosure *comp = (const WestinBackscatterClosure *)other;
- return m_N == comp->m_N && m_roughness == comp->m_roughness &&
- BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "westin_backscatter"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_roughness;
- out << ")";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
- {
- // pdf is implicitly 0 (no indirect sampling)
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO > 0 && cosNI > 0) {
- float cosine = omega_out.dot(omega_in);
- pdf = cosine > 0 ? (m_invroughness + 1) * powf(cosine, m_invroughness) : 0;
- pdf *= 0.5f * float(M_1_PI);
- return Color3 (pdf, pdf, pdf);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- float cosNO = m_N.dot(omega_out);
- if (cosNO > 0) {
- domega_in_dx = domega_out_dx;
- domega_in_dy = domega_out_dy;
- Vec3 T, B;
- make_orthonormals (omega_out, T, B);
- float phi = 2 * (float) M_PI * randu;
- float cosTheta = powf(randv, 1 / (m_invroughness + 1));
- float sinTheta2 = 1 - cosTheta * cosTheta;
- float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0;
- omega_in = (cosf(phi) * sinTheta) * T +
- (sinf(phi) * sinTheta) * B +
- ( cosTheta) * omega_out;
- if (Ng.dot(omega_in) > 0)
- {
- // common terms for pdf and eval
- float cosNI = m_N.dot(omega_in);
- // make sure the direction we chose is still in the right hemisphere
- if (cosNI > 0)
- {
- pdf = 0.5f * (float) M_1_PI * powf(cosTheta, m_invroughness);
- pdf = (m_invroughness + 1) * pdf;
- eval.setValue(pdf, pdf, pdf);
- // Since there is some blur to this reflection, make the
- // derivatives a bit bigger. In theory this varies with the
- // exponent but the exact relationship is complex and
- // requires more ops than are practical.
- domega_in_dx *= 10;
- domega_in_dy *= 10;
- }
- }
- }
- return Labels::REFLECT;
- }
+ m_invroughness = m_roughness > 0 ? 1 / m_roughness : 0;
+ }
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const WestinBackscatterClosure *comp = (const WestinBackscatterClosure *)other;
+ return m_N == comp->m_N && m_roughness == comp->m_roughness &&
+ BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "westin_backscatter"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_roughness;
+ out << ")";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
+ {
+ // pdf is implicitly 0 (no indirect sampling)
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO > 0 && cosNI > 0) {
+ float cosine = omega_out.dot(omega_in);
+ pdf = cosine > 0 ? (m_invroughness + 1) * powf(cosine, m_invroughness) : 0;
+ pdf *= 0.5f * float(M_1_PI);
+ return Color3(pdf, pdf, pdf);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ float cosNO = m_N.dot(omega_out);
+ if (cosNO > 0) {
+ domega_in_dx = domega_out_dx;
+ domega_in_dy = domega_out_dy;
+ Vec3 T, B;
+ make_orthonormals(omega_out, T, B);
+ float phi = 2 * (float) M_PI * randu;
+ float cosTheta = powf(randv, 1 / (m_invroughness + 1));
+ float sinTheta2 = 1 - cosTheta * cosTheta;
+ float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0;
+ omega_in = (cosf(phi) * sinTheta) * T +
+ (sinf(phi) * sinTheta) * B +
+ (cosTheta) * omega_out;
+ if (Ng.dot(omega_in) > 0)
+ {
+ // common terms for pdf and eval
+ float cosNI = m_N.dot(omega_in);
+ // make sure the direction we chose is still in the right hemisphere
+ if (cosNI > 0)
+ {
+ pdf = 0.5f * (float) M_1_PI * powf(cosTheta, m_invroughness);
+ pdf = (m_invroughness + 1) * pdf;
+ eval.setValue(pdf, pdf, pdf);
+ // Since there is some blur to this reflection, make the
+ // derivatives a bit bigger. In theory this varies with the
+ // exponent but the exact relationship is complex and
+ // requires more ops than are practical.
+ domega_in_dx *= 10;
+ domega_in_dy *= 10;
+ }
+ }
+ }
+ return Labels::REFLECT;
+ }
};
class WestinSheenClosure : public BSDFClosure {
public:
- Vec3 m_N;
- float m_edginess;
+ Vec3 m_N;
+ float m_edginess;
// float m_normalization;
- WestinSheenClosure() : BSDFClosure(Labels::DIFFUSE) { }
-
- void setup() {};
-
- bool mergeable (const ClosurePrimitive *other) const {
- const WestinSheenClosure *comp = (const WestinSheenClosure *)other;
- return m_N == comp->m_N && m_edginess == comp->m_edginess &&
- BSDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "westin_sheen"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " (";
- out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
- out << m_edginess;
- out << ")";
- }
-
- float albedo (const Vec3 &omega_out) const
- {
- return 1.0f;
- }
-
- Color3 eval_reflect (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
- {
- // pdf is implicitly 0 (no indirect sampling)
- float cosNO = m_N.dot(omega_out);
- float cosNI = m_N.dot(omega_in);
- if (cosNO > 0 && cosNI > 0) {
- float sinNO2 = 1 - cosNO * cosNO;
- pdf = cosNI * float(M_1_PI);
- float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0;
- return Color3 (westin, westin, westin);
- }
- return Color3 (0, 0, 0);
- }
-
- Color3 eval_transmit (const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
- {
- return Color3 (0, 0, 0);
- }
-
- ustring sample (const Vec3 &Ng,
- const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
- float randu, float randv,
- Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
- float &pdf, Color3 &eval) const
- {
- // we are viewing the surface from the right side - send a ray out with cosine
- // distribution over the hemisphere
- sample_cos_hemisphere (m_N, omega_out, randu, randv, omega_in, pdf);
- if (Ng.dot(omega_in) > 0) {
- // TODO: account for sheen when sampling
- float cosNO = m_N.dot(omega_out);
- float sinNO2 = 1 - cosNO * cosNO;
- float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0;
- eval.setValue(westin, westin, westin);
- // TODO: find a better approximation for the diffuse bounce
- domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
- domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
- domega_in_dx *= 125;
- domega_in_dy *= 125;
- } else
- pdf = 0;
- return Labels::REFLECT;
- }
+ WestinSheenClosure() : BSDFClosure(Labels::DIFFUSE) {}
+
+ void setup() {};
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const WestinSheenClosure *comp = (const WestinSheenClosure *)other;
+ return m_N == comp->m_N && m_edginess == comp->m_edginess &&
+ BSDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "westin_sheen"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " (";
+ out << "(" << m_N[0] << ", " << m_N[1] << ", " << m_N[2] << "), ";
+ out << m_edginess;
+ out << ")";
+ }
+
+ float albedo(const Vec3 &omega_out) const
+ {
+ return 1.0f;
+ }
+
+ Color3 eval_reflect(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
+ {
+ // pdf is implicitly 0 (no indirect sampling)
+ float cosNO = m_N.dot(omega_out);
+ float cosNI = m_N.dot(omega_in);
+ if (cosNO > 0 && cosNI > 0) {
+ float sinNO2 = 1 - cosNO * cosNO;
+ pdf = cosNI * float(M_1_PI);
+ float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0;
+ return Color3(westin, westin, westin);
+ }
+ return Color3(0, 0, 0);
+ }
+
+ Color3 eval_transmit(const Vec3 &omega_out, const Vec3 &omega_in, float &pdf) const
+ {
+ return Color3(0, 0, 0);
+ }
+
+ ustring sample(const Vec3 &Ng,
+ const Vec3 &omega_out, const Vec3 &domega_out_dx, const Vec3 &domega_out_dy,
+ float randu, float randv,
+ Vec3 &omega_in, Vec3 &domega_in_dx, Vec3 &domega_in_dy,
+ float &pdf, Color3 &eval) const
+ {
+ // we are viewing the surface from the right side - send a ray out with cosine
+ // distribution over the hemisphere
+ sample_cos_hemisphere(m_N, omega_out, randu, randv, omega_in, pdf);
+ if (Ng.dot(omega_in) > 0) {
+ // TODO: account for sheen when sampling
+ float cosNO = m_N.dot(omega_out);
+ float sinNO2 = 1 - cosNO * cosNO;
+ float westin = sinNO2 > 0 ? powf(sinNO2, 0.5f * m_edginess) * pdf : 0;
+ eval.setValue(westin, westin, westin);
+ // TODO: find a better approximation for the diffuse bounce
+ domega_in_dx = (2 * m_N.dot(domega_out_dx)) * m_N - domega_out_dx;
+ domega_in_dy = (2 * m_N.dot(domega_out_dy)) * m_N - domega_out_dy;
+ domega_in_dx *= 125;
+ domega_in_dy *= 125;
+ }
+ else {
+ pdf = 0;
+ }
+ return Labels::REFLECT;
+ }
};
ClosureParam bsdf_westin_backscatter_params[] = {
- CLOSURE_VECTOR_PARAM(WestinBackscatterClosure, m_N),
- CLOSURE_FLOAT_PARAM (WestinBackscatterClosure, m_roughness),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(WestinBackscatterClosure) };
+ CLOSURE_VECTOR_PARAM(WestinBackscatterClosure, m_N),
+ CLOSURE_FLOAT_PARAM(WestinBackscatterClosure, m_roughness),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(WestinBackscatterClosure)
+};
ClosureParam bsdf_westin_sheen_params[] = {
- CLOSURE_VECTOR_PARAM(WestinSheenClosure, m_N),
- CLOSURE_FLOAT_PARAM (WestinSheenClosure, m_edginess),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(WestinSheenClosure) };
+ CLOSURE_VECTOR_PARAM(WestinSheenClosure, m_N),
+ CLOSURE_FLOAT_PARAM(WestinSheenClosure, m_edginess),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(WestinSheenClosure)
+};
CLOSURE_PREPARE(bsdf_westin_backscatter_prepare, WestinBackscatterClosure)
CLOSURE_PREPARE(bsdf_westin_sheen_prepare, WestinSheenClosure)
diff --git a/intern/cycles/kernel/osl/bssrdf.cpp b/intern/cycles/kernel/osl/bssrdf.cpp
index 66d7818e677..b195cf513cd 100644
--- a/intern/cycles/kernel/osl/bssrdf.cpp
+++ b/intern/cycles/kernel/osl/bssrdf.cpp
@@ -42,62 +42,63 @@ using namespace OSL;
class BSSRDFCubicClosure : public BSSRDFClosure {
public:
- Color3 m_radius;
- Color3 m_scale;
- float m_max_radius;
-
- template <typename T>
- static inline T pow3 (const T &x) { return x * x * x; }
-
- template <typename T>
- static inline T pow5 (const T &x) { T x2 = x * x; return x2 * x2 * x; }
-
- BSSRDFCubicClosure() { }
-
- void setup()
- {
- // pre-compute some terms
- m_max_radius = 0;
- for (int i = 0; i < 3; i++) {
- m_scale[i] = m_radius[i] > 0 ? 4 / pow5 (m_radius[i]) : 0;
- m_max_radius = std::max (m_max_radius, m_radius[i]);
- }
- }
-
- bool mergeable (const ClosurePrimitive *other) const {
- const BSSRDFCubicClosure *comp = (const BSSRDFCubicClosure *)other;
- return m_radius == comp->m_radius && BSSRDFClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "bssrdf_cubic"; }
-
- void print_on (std::ostream &out) const
- {
- out << name() << " ((" << m_radius[0] << ", " << m_radius[1] << ", " << m_radius[2] << "), ("
- << m_scale[0] << ", " << m_scale[1] << ", " << m_scale[2] << "))";
- }
-
- Color3 eval (float r) const
- {
- return Color3 ((r < m_radius.x) ? pow3 (m_radius.x - r) * m_scale.x : 0,
- (r < m_radius.y) ? pow3 (m_radius.y - r) * m_scale.y : 0,
- (r < m_radius.z) ? pow3 (m_radius.z - r) * m_scale.z : 0);
- }
-
- float max_radius() const
- {
- return m_max_radius;
- }
+ Color3 m_radius;
+ Color3 m_scale;
+ float m_max_radius;
+
+ template <typename T>
+ static inline T pow3(const T &x) { return x * x * x; }
+
+ template <typename T>
+ static inline T pow5(const T &x) { T x2 = x * x; return x2 * x2 * x; }
+
+ BSSRDFCubicClosure() {}
+
+ void setup()
+ {
+ // pre-compute some terms
+ m_max_radius = 0;
+ for (int i = 0; i < 3; i++) {
+ m_scale[i] = m_radius[i] > 0 ? 4 / pow5(m_radius[i]) : 0;
+ m_max_radius = std::max(m_max_radius, m_radius[i]);
+ }
+ }
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const BSSRDFCubicClosure *comp = (const BSSRDFCubicClosure *)other;
+ return m_radius == comp->m_radius && BSSRDFClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "bssrdf_cubic"; }
+
+ void print_on(std::ostream &out) const
+ {
+ out << name() << " ((" << m_radius[0] << ", " << m_radius[1] << ", " << m_radius[2] << "), ("
+ << m_scale[0] << ", " << m_scale[1] << ", " << m_scale[2] << "))";
+ }
+
+ Color3 eval(float r) const
+ {
+ return Color3((r < m_radius.x) ? pow3(m_radius.x - r) * m_scale.x : 0,
+ (r < m_radius.y) ? pow3(m_radius.y - r) * m_scale.y : 0,
+ (r < m_radius.z) ? pow3(m_radius.z - r) * m_scale.z : 0);
+ }
+
+ float max_radius() const
+ {
+ return m_max_radius;
+ }
};
ClosureParam closure_bssrdf_cubic_params[] = {
- CLOSURE_COLOR_PARAM (BSSRDFCubicClosure, m_radius),
- CLOSURE_STRING_KEYPARAM ("label"),
- CLOSURE_FINISH_PARAM(BSSRDFCubicClosure) };
+ CLOSURE_COLOR_PARAM(BSSRDFCubicClosure, m_radius),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(BSSRDFCubicClosure)
+};
CLOSURE_PREPARE(closure_bssrdf_cubic_prepare, BSSRDFCubicClosure)
diff --git a/intern/cycles/kernel/osl/debug.cpp b/intern/cycles/kernel/osl/debug.cpp
index 8c3f8b2b323..768a9100e8a 100644
--- a/intern/cycles/kernel/osl/debug.cpp
+++ b/intern/cycles/kernel/osl/debug.cpp
@@ -49,30 +49,31 @@ using namespace OSL;
class DebugClosure : public ClosurePrimitive {
public:
- ustring m_tag;
+ ustring m_tag;
- DebugClosure () : ClosurePrimitive (Debug) { }
+ DebugClosure () : ClosurePrimitive(Debug) {}
- bool mergeable (const ClosurePrimitive *other) const {
- const DebugClosure *comp = (const DebugClosure *)other;
- return m_tag == comp->m_tag &&
- ClosurePrimitive::mergeable(other);
- }
+ bool mergeable(const ClosurePrimitive *other) const {
+ const DebugClosure *comp = (const DebugClosure *)other;
+ return m_tag == comp->m_tag &&
+ ClosurePrimitive::mergeable(other);
+ }
- size_t memsize () const { return sizeof(*this); }
+ size_t memsize() const { return sizeof(*this); }
- const char *name () const { return "debug"; }
+ const char *name() const { return "debug"; }
- void print_on (std::ostream &out) const {
- out << name() << " (\"" << m_tag.c_str() << "\")";
- }
+ void print_on(std::ostream &out) const {
+ out << name() << " (\"" << m_tag.c_str() << "\")";
+ }
};
ClosureParam closure_debug_params[] = {
- CLOSURE_STRING_PARAM(DebugClosure, m_tag),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(DebugClosure) };
+ CLOSURE_STRING_PARAM(DebugClosure, m_tag),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(DebugClosure)
+};
CLOSURE_PREPARE(closure_debug_prepare, DebugClosure)
diff --git a/intern/cycles/kernel/osl/emissive.cpp b/intern/cycles/kernel/osl/emissive.cpp
index 2d2d6e1fdde..0a582c3f558 100644
--- a/intern/cycles/kernel/osl/emissive.cpp
+++ b/intern/cycles/kernel/osl/emissive.cpp
@@ -49,57 +49,58 @@ using namespace OSL;
///
class GenericEmissiveClosure : public EmissiveClosure {
public:
- GenericEmissiveClosure() { }
-
- void setup() { }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "emission"; }
-
- void print_on (std::ostream &out) const {
- out << name() << "()";
- }
-
- Color3 eval (const Vec3 &Ng, const Vec3 &omega_out) const
- {
- float cosNO = fabsf(Ng.dot(omega_out));
- float res = cosNO > 0 ? 1.0f: 0.0f;
- return Color3(res, res, res);
- }
-
- void sample (const Vec3 &Ng, float randu, float randv,
- Vec3 &omega_out, float &pdf) const
- {
- // We don't do anything sophisticated here for the step
- // We just sample the whole cone uniformly to the cosine
- Vec3 T, B;
- make_orthonormals(Ng, T, B);
- float phi = 2 * (float) M_PI * randu;
- float cosTheta = sqrtf(1.0f - 1.0f * randv);
- float sinTheta = sqrtf(1.0f - cosTheta * cosTheta);
- omega_out = (cosf(phi) * sinTheta) * T +
- (sinf(phi) * sinTheta) * B +
- cosTheta * Ng;
- pdf = 1.0f / float(M_PI);
- }
-
- /// Return the probability distribution function in the direction omega_out,
- /// given the parameters and the light's surface normal. This MUST match
- /// the PDF computed by sample().
- float pdf (const Vec3 &Ng,
- const Vec3 &omega_out) const
- {
- float cosNO = Ng.dot(omega_out);
- return cosNO > 0 ? 1.0f: 0.0f;
- }
+ GenericEmissiveClosure() { }
+
+ void setup() {}
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "emission"; }
+
+ void print_on(std::ostream &out) const {
+ out << name() << "()";
+ }
+
+ Color3 eval(const Vec3 &Ng, const Vec3 &omega_out) const
+ {
+ float cosNO = fabsf(Ng.dot(omega_out));
+ float res = cosNO > 0 ? 1.0f : 0.0f;
+ return Color3(res, res, res);
+ }
+
+ void sample(const Vec3 &Ng, float randu, float randv,
+ Vec3 &omega_out, float &pdf) const
+ {
+ // We don't do anything sophisticated here for the step
+ // We just sample the whole cone uniformly to the cosine
+ Vec3 T, B;
+ make_orthonormals(Ng, T, B);
+ float phi = 2 * (float) M_PI * randu;
+ float cosTheta = sqrtf(1.0f - 1.0f * randv);
+ float sinTheta = sqrtf(1.0f - cosTheta * cosTheta);
+ omega_out = (cosf(phi) * sinTheta) * T +
+ (sinf(phi) * sinTheta) * B +
+ cosTheta * Ng;
+ pdf = 1.0f / float(M_PI);
+ }
+
+ /// Return the probability distribution function in the direction omega_out,
+ /// given the parameters and the light's surface normal. This MUST match
+ /// the PDF computed by sample().
+ float pdf(const Vec3 &Ng,
+ const Vec3 &omega_out) const
+ {
+ float cosNO = Ng.dot(omega_out);
+ return cosNO > 0 ? 1.0f : 0.0f;
+ }
};
ClosureParam closure_emission_params[] = {
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(GenericEmissiveClosure) };
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(GenericEmissiveClosure)
+};
CLOSURE_PREPARE(closure_emission_prepare, GenericEmissiveClosure)
diff --git a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl
index 712d51333ad..306798b645f 100644
--- a/intern/cycles/kernel/osl/nodes/node_checker_texture.osl
+++ b/intern/cycles/kernel/osl/nodes/node_checker_texture.osl
@@ -23,13 +23,13 @@
float checker(point p)
{
- p[0] = (p[0] + 0.00001)*0.9999);
- p[1] = (p[1] + 0.00001)*0.9999);
- p[2] = (p[2] + 0.00001)*0.9999);
+ p[0] = (p[0] + 0.00001)*0.9999;
+ p[1] = (p[1] + 0.00001)*0.9999;
+ p[2] = (p[2] + 0.00001)*0.9999;
- int xi = fabs(floor(p[0]));
- int yi = fabs(floor(p[1]));
- int zi = fabs(floor(p[2]));
+ int xi = (int)fabs(floor(p[0]));
+ int yi = (int)fabs(floor(p[1]));
+ int zi = (int)fabs(floor(p[2]));
if((xi % 2 == yi % 2) == (zi % 2)) {
return 1.0;
@@ -42,9 +42,9 @@ float checker(point p)
shader node_checker_texture(
float Scale = 5.0,
point Vector = P,
- color Color1 = color(0.8, 0.8, 0.8);
- color Color2 = color(0.2, 0.2, 0.2);
- output float Fac = 0.0)
+ color Color1 = color(0.8, 0.8, 0.8),
+ color Color2 = color(0.2, 0.2, 0.2),
+ output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
Fac = checker(Vector*Scale);
diff --git a/intern/cycles/kernel/osl/nodes/node_color.h b/intern/cycles/kernel/osl/nodes/node_color.h
index 37d092eae78..80786e4e369 100644
--- a/intern/cycles/kernel/osl/nodes/node_color.h
+++ b/intern/cycles/kernel/osl/nodes/node_color.h
@@ -18,18 +18,18 @@
float color_srgb_to_scene_linear(float c)
{
- if(c < 0.04045)
- return (c < 0.0)? 0.0: c * (1.0/12.92);
+ if (c < 0.04045)
+ return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
else
- return pow((c + 0.055)*(1.0/1.055), 2.4);
+ return pow((c + 0.055) * (1.0 / 1.055), 2.4);
}
float color_scene_linear_to_srgb(float c)
{
- if(c < 0.0031308)
- return (c < 0.0)? 0.0: c * 12.92;
- else
- return 1.055 * pow(c, 1.0/2.4) - 0.055;
+ if (c < 0.0031308)
+ return (c < 0.0) ? 0.0 : c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
}
color color_srgb_to_scene_linear(color c)
@@ -61,27 +61,27 @@ color rgb_to_hsv(color rgb)
v = cmax;
- if(cmax != 0.0) {
- s = cdelta/cmax;
+ if (cmax != 0.0) {
+ s = cdelta / cmax;
}
else {
s = 0.0;
h = 0.0;
}
- if(s == 0.0) {
+ if (s == 0.0) {
h = 0.0;
}
else {
- c = (color(cmax, cmax, cmax) - rgb)/cdelta;
+ c = (color(cmax, cmax, cmax) - rgb) / cdelta;
- if(rgb[0] == cmax) h = c[2] - c[1];
- else if(rgb[1] == cmax) h = 2.0 + c[0] - c[2];
+ if (rgb[0] == cmax) h = c[2] - c[1];
+ else if (rgb[1] == cmax) h = 2.0 + c[0] - c[2];
else h = 4.0 + c[1] - c[0];
h /= 6.0;
- if(h < 0.0)
+ if (h < 0.0)
h += 1.0;
}
@@ -97,26 +97,26 @@ color hsv_to_rgb(color hsv)
s = hsv[1];
v = hsv[2];
- if(s==0.0) {
+ if (s == 0.0) {
rgb = color(v, v, v);
}
else {
- if(h==1.0)
+ if (h == 1.0)
h = 0.0;
h *= 6.0;
i = floor(h);
f = h - i;
rgb = color(f, f, f);
- p = v*(1.0-s);
- q = v*(1.0-(s*f));
- t = v*(1.0-(s*(1.0-f)));
-
- if(i == 0.0) rgb = color(v, t, p);
- else if(i == 1.0) rgb = color(q, v, p);
- else if(i == 2.0) rgb = color(p, v, t);
- else if(i == 3.0) rgb = color(p, q, v);
- else if(i == 4.0) rgb = color(t, p, v);
+ p = v * (1.0 - s);
+ q = v * (1.0 - (s * f));
+ t = v * (1.0 - (s * (1.0 - f)));
+
+ if (i == 0.0) rgb = color(v, t, p);
+ else if (i == 1.0) rgb = color(q, v, p);
+ else if (i == 2.0) rgb = color(p, v, t);
+ else if (i == 3.0) rgb = color(p, q, v);
+ else if (i == 4.0) rgb = color(t, p, v);
else rgb = color(v, p, q);
}
diff --git a/intern/cycles/kernel/osl/nodes/node_fresnel.h b/intern/cycles/kernel/osl/nodes/node_fresnel.h
index 0c8a5276ede..dfd0a23fe1e 100644
--- a/intern/cycles/kernel/osl/nodes/node_fresnel.h
+++ b/intern/cycles/kernel/osl/nodes/node_fresnel.h
@@ -1,17 +1,32 @@
-
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
float fresnel_dielectric(vector Incoming, normal Normal, float eta)
{
/* compute fresnel reflectance without explicitly computing
- the refracted direction */
+ * the refracted direction */
float c = fabs(dot(Incoming, Normal));
float g = eta * eta - 1 + c * c;
float result;
- if(g > 0) {
+ if (g > 0) {
g = sqrt(g);
- float A =(g - c)/(g + c);
- float B =(c *(g + c)- 1)/(c *(g - c)+ 1);
- result = 0.5 * A * A *(1 + B * B);
+ float A = (g - c) / (g + c);
+ float B = (c * (g + c) - 1) / (c * (g - c) + 1);
+ result = 0.5 * A * A * (1 + B * B);
}
else
result = 1.0; /* TIR (no refracted component) */
diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h
index e0ec8038ee4..d2dbd6db8b3 100644
--- a/intern/cycles/kernel/osl/nodes/node_texture.h
+++ b/intern/cycles/kernel/osl/nodes/node_texture.h
@@ -20,20 +20,20 @@ float voronoi_distance(string distance_metric, vector d, float e)
{
float result = 0.0;
- if(distance_metric == "Distance Squared")
+ if (distance_metric == "Distance Squared")
result = dot(d, d);
- if(distance_metric == "Actual Distance")
+ if (distance_metric == "Actual Distance")
result = length(d);
- if(distance_metric == "Manhattan")
+ if (distance_metric == "Manhattan")
result = fabs(d[0]) + fabs(d[1]) + fabs(d[2]);
- if(distance_metric == "Chebychev")
+ if (distance_metric == "Chebychev")
result = max(fabs(d[0]), max(fabs(d[1]), fabs(d[2])));
- if(distance_metric == "Minkovsky 1/2")
+ if (distance_metric == "Minkovsky 1/2")
result = sqrt(fabs(d[0])) + sqrt(fabs(d[1])) + sqrt(fabs(d[1]));
- if(distance_metric == "Minkovsky 4")
- result = sqrt(sqrt(dot(d*d, d*d)));
- if(distance_metric == "Minkovsky")
- result = pow(pow(fabs(d[0]), e) + pow(fabs(d[1]), e) + pow(fabs(d[2]), e), 1.0/e);
+ if (distance_metric == "Minkovsky 4")
+ result = sqrt(sqrt(dot(d * d, d * d)));
+ if (distance_metric == "Minkovsky")
+ result = pow(pow(fabs(d[0]), e) + pow(fabs(d[1]), e) + pow(fabs(d[2]), e), 1.0 / e);
return result;
}
@@ -63,9 +63,9 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4])
da[2] = 1e10;
da[3] = 1e10;
- for(xx = xi-1; xx <= xi+1; xx++) {
- for(yy = yi-1; yy <= yi+1; yy++) {
- for(zz = zi-1; zz <= zi+1; zz++) {
+ for (xx = xi - 1; xx <= xi + 1; xx++) {
+ for (yy = yi - 1; yy <= yi + 1; yy++) {
+ for (zz = zi - 1; zz <= zi + 1; zz++) {
point ip = point(xx, yy, zz);
point vp = (point)cellnoise_color(ip);
point pd = p - (vp + ip);
@@ -73,7 +73,7 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4])
vp += point(xx, yy, zz);
- if(d < da[0]) {
+ if (d < da[0]) {
da[3] = da[2];
da[2] = da[1];
da[1] = da[0];
@@ -84,7 +84,7 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4])
pa[1] = pa[0];
pa[0] = vp;
}
- else if(d < da[1]) {
+ else if (d < da[1]) {
da[3] = da[2];
da[2] = da[1];
da[1] = d;
@@ -93,14 +93,14 @@ void voronoi(point p, string distance_metric, float e, float da[4], point pa[4])
pa[2] = pa[1];
pa[1] = vp;
}
- else if(d < da[2]) {
+ else if (d < da[2]) {
da[3] = da[2];
da[2] = d;
pa[3] = pa[2];
pa[2] = vp;
}
- else if(d < da[3]) {
+ else if (d < da[3]) {
da[3] = d;
pa[3] = vp;
}
@@ -138,16 +138,16 @@ float voronoi_F1F2(point p) { return voronoi_FnFn(p, 0, 1); }
float voronoi_Cr(point p)
{
/* crackle type pattern, just a scale/clamp of F2-F1 */
- float t = 10.0*voronoi_F1F2(p);
- return (t > 1.0)? 1.0: t;
+ float t = 10.0 * voronoi_F1F2(p);
+ return (t > 1.0) ? 1.0 : t;
}
-float voronoi_F1S(point p) { return 2.0*voronoi_F1(p) - 1.0; }
-float voronoi_F2S(point p) { return 2.0*voronoi_F2(p) - 1.0; }
-float voronoi_F3S(point p) { return 2.0*voronoi_F3(p) - 1.0; }
-float voronoi_F4S(point p) { return 2.0*voronoi_F4(p) - 1.0; }
-float voronoi_F1F2S(point p) { return 2.0*voronoi_F1F2(p) - 1.0; }
-float voronoi_CrS(point p) { return 2.0*voronoi_Cr(p) - 1.0; }
+float voronoi_F1S(point p) { return 2.0 * voronoi_F1(p) - 1.0; }
+float voronoi_F2S(point p) { return 2.0 * voronoi_F2(p) - 1.0; }
+float voronoi_F3S(point p) { return 2.0 * voronoi_F3(p) - 1.0; }
+float voronoi_F4S(point p) { return 2.0 * voronoi_F4(p) - 1.0; }
+float voronoi_F1F2S(point p) { return 2.0 * voronoi_F1F2(p) - 1.0; }
+float voronoi_CrS(point p) { return 2.0 * voronoi_Cr(p) - 1.0; }
/* Noise Bases */
@@ -155,21 +155,21 @@ float noise_basis(point p, string basis)
{
float result = 0.0;
- if(basis == "Perlin")
+ if (basis == "Perlin")
result = noise(p);
- if(basis == "Voronoi F1")
+ if (basis == "Voronoi F1")
result = voronoi_F1S(p);
- if(basis == "Voronoi F2")
+ if (basis == "Voronoi F2")
result = voronoi_F2S(p);
- if(basis == "Voronoi F3")
+ if (basis == "Voronoi F3")
result = voronoi_F3S(p);
- if(basis == "Voronoi F4")
+ if (basis == "Voronoi F4")
result = voronoi_F4S(p);
- if(basis == "Voronoi F2-F1")
+ if (basis == "Voronoi F2-F1")
result = voronoi_F1F2S(p);
- if(basis == "Voronoi Crackle")
+ if (basis == "Voronoi Crackle")
result = voronoi_CrS(p);
- if(basis == "Cell Noise")
+ if (basis == "Cell Noise")
result = cellnoise(p);
return result;
@@ -180,7 +180,7 @@ float noise_basis(point p, string basis)
float noise_basis_hard(point p, string basis, int hard)
{
float t = noise_basis(p, basis);
- return (hard)? fabs(2.0*t - 1.0): t;
+ return (hard) ? fabs(2.0 * t - 1.0) : t;
}
/* Waves */
@@ -189,22 +189,22 @@ float noise_wave(string wave, float a)
{
float result = 0.0;
- if(wave == "Sine") {
- result = 0.5 + 0.5*sin(a);
+ if (wave == "Sine") {
+ result = 0.5 + 0.5 * sin(a);
}
- else if(wave == "Saw") {
- float b = 2*M_PI;
+ else if (wave == "Saw") {
+ float b = 2 * M_PI;
int n = (int)(a / b);
- a -= n*b;
- if(a < 0) a += b;
+ a -= n * b;
+ if (a < 0) a += b;
result = a / b;
}
- else if(wave == "Tri") {
- float b = 2*M_PI;
+ else if (wave == "Tri") {
+ float b = 2 * M_PI;
float rmax = 1.0;
- result = rmax - 2.0*fabs(floor((a*(1.0/b))+0.5) - (a*(1.0/b)));
+ result = rmax - 2.0 * fabs(floor((a * (1.0 / b)) + 0.5) - (a * (1.0 / b)));
}
return result;
@@ -219,18 +219,18 @@ float noise_turbulence(point p, string basis, int octaves, int hard)
float sum = 0.0;
int i;
- for(i = 0; i <= octaves; i++) {
- float t = noise_basis(fscale*p, basis);
+ for (i = 0; i <= octaves; i++) {
+ float t = noise_basis(fscale * p, basis);
- if(hard)
- t = fabs(2.0*t - 1.0);
+ if (hard)
+ t = fabs(2.0 * t - 1.0);
- sum += t*amp;
+ sum += t * amp;
amp *= 0.5;
fscale *= 2.0;
}
- sum *= ((float)(1 << octaves)/(float)((1 << (octaves+1)) - 1));
+ sum *= ((float)(1 << octaves) / (float)((1 << (octaves + 1)) - 1));
return sum;
}
@@ -241,8 +241,8 @@ float nonzero(float f, float eps)
{
float r;
- if(abs(f) < eps)
- r = sign(f)*eps;
+ if (abs(f) < eps)
+ r = sign(f) * eps;
else
r = f;
diff --git a/intern/cycles/kernel/osl/nodes/stdosl.h b/intern/cycles/kernel/osl/nodes/stdosl.h
index e4a110e737c..0c07c501d69 100644
--- a/intern/cycles/kernel/osl/nodes/stdosl.h
+++ b/intern/cycles/kernel/osl/nodes/stdosl.h
@@ -163,241 +163,246 @@ vector normalize (vector v) BUILTIN;
vector faceforward (vector N, vector I, vector Nref) BUILTIN;
vector faceforward (vector N, vector I) BUILTIN;
vector reflect (vector I, vector N) { return I - 2*dot(N,I)*N; }
-vector refract (vector I, vector N, float eta) {
- float IdotN = dot (I, N);
- float k = 1 - eta*eta * (1 - IdotN*IdotN);
- return (k < 0) ? vector(0,0,0) : (eta*I - N * (eta*IdotN + sqrt(k)));
+vector refract(vector I, vector N, float eta) {
+ float IdotN = dot(I, N);
+ float k = 1 - eta * eta * (1 - IdotN * IdotN);
+ return (k < 0) ? vector(0, 0, 0) : (eta * I - N * (eta * IdotN + sqrt(k)));
}
-void fresnel (vector I, normal N, float eta,
- output float Kr, output float Kt,
- output vector R, output vector T)
+void fresnel(vector I, normal N, float eta,
+ output float Kr, output float Kt,
+ output vector R, output vector T)
{
- float sqr(float x) { return x*x; }
- float c = dot(I, N);
- if (c < 0)
- c = -c;
- R = reflect(I, N);
- float g = 1.0 / sqr(eta) - 1.0 + c * c;
- if (g >= 0.0) {
- g = sqrt (g);
- float beta = g - c;
- float F = (c * (g+c) - 1.0) / (c * beta + 1.0);
- F = 0.5 * (1.0 + sqr(F));
- F *= sqr (beta / (g+c));
- Kr = F;
- Kt = (1.0 - Kr) * eta*eta;
- // OPT: the following recomputes some of the above values, but it
- // gives us the same result as if the shader-writer called refract()
- T = refract(I, N, eta);
- } else {
- // total internal reflection
- Kr = 1.0;
- Kt = 0.0;
- T = vector (0,0,0);
- }
+ float sqr(float x) {
+ return x * x;
+ }
+ float c = dot(I, N);
+ if (c < 0)
+ c = -c;
+ R = reflect(I, N);
+ float g = 1.0 / sqr(eta) - 1.0 + c * c;
+ if (g >= 0.0) {
+ g = sqrt(g);
+ float beta = g - c;
+ float F = (c * (g + c) - 1.0) / (c * beta + 1.0);
+ F = 0.5 * (1.0 + sqr(F));
+ F *= sqr(beta / (g + c));
+ Kr = F;
+ Kt = (1.0 - Kr) * eta * eta;
+ // OPT: the following recomputes some of the above values, but it
+ // gives us the same result as if the shader-writer called refract()
+ T = refract(I, N, eta);
+ }
+ else {
+ // total internal reflection
+ Kr = 1.0;
+ Kt = 0.0;
+ T = vector(0, 0, 0);
+ }
#undef sqr
}
-void fresnel (vector I, normal N, float eta,
- output float Kr, output float Kt)
+void fresnel(vector I, normal N, float eta,
+ output float Kr, output float Kt)
{
- vector R, T;
- fresnel(I, N, eta, Kr, Kt, R, T);
+ vector R, T;
+ fresnel(I, N, eta, Kr, Kt, R, T);
}
-point rotate (point q, float angle, point a, point b) BUILTIN;
+point rotate(point q, float angle, point a, point b) BUILTIN;
-normal transform (matrix Mto, normal p) BUILTIN;
-vector transform (matrix Mto, vector p) BUILTIN;
-point transform (matrix Mto, point p) BUILTIN;
+normal transform(matrix Mto, normal p) BUILTIN;
+vector transform(matrix Mto, vector p) BUILTIN;
+point transform(matrix Mto, point p) BUILTIN;
// Implementation of transform-with-named-space in terms of matrices:
-point transform (string tospace, point x)
+point transform(string tospace, point x)
{
- return transform (matrix ("common", tospace), x);
+ return transform(matrix("common", tospace), x);
}
-point transform (string fromspace, string tospace, point x)
+point transform(string fromspace, string tospace, point x)
{
- return transform (matrix (fromspace, tospace), x);
+ return transform(matrix(fromspace, tospace), x);
}
-vector transform (string tospace, vector x)
+vector transform(string tospace, vector x)
{
- return transform (matrix ("common", tospace), x);
+ return transform(matrix("common", tospace), x);
}
-vector transform (string fromspace, string tospace, vector x)
+vector transform(string fromspace, string tospace, vector x)
{
- return transform (matrix (fromspace, tospace), x);
+ return transform(matrix(fromspace, tospace), x);
}
-normal transform (string tospace, normal x)
+normal transform(string tospace, normal x)
{
- return transform (matrix ("common", tospace), x);
+ return transform(matrix("common", tospace), x);
}
-normal transform (string fromspace, string tospace, normal x)
+normal transform(string fromspace, string tospace, normal x)
{
- return transform (matrix (fromspace, tospace), x);
+ return transform(matrix(fromspace, tospace), x);
}
-float transformu (string tounits, float x) BUILTIN;
-float transformu (string fromunits, string tounits, float x) BUILTIN;
+float transformu(string tounits, float x) BUILTIN;
+float transformu(string fromunits, string tounits, float x) BUILTIN;
// Color functions
-float luminance (color c) {
- return dot ((vector)c, vector(0.2126, 0.7152, 0.0722));
+float luminance(color c) {
+ return dot((vector)c, vector(0.2126, 0.7152, 0.0722));
}
-color transformc (string to, color x)
+color transformc(string to, color x)
{
- color rgb_to_hsv (color rgb) { // See Foley & van Dam
- float r = rgb[0], g = rgb[1], b = rgb[2];
- float mincomp = min (r, min (g, b));
- float maxcomp = max (r, max (g, b));
- float delta = maxcomp - mincomp; // chroma
- float h, s, v;
- v = maxcomp;
- if (maxcomp > 0)
- s = delta / maxcomp;
- else s = 0;
- if (s <= 0)
- h = 0;
- else {
- if (r >= maxcomp) h = (g-b) / delta;
- else if (g >= maxcomp) h = 2 + (b-r) / delta;
- else h = 4 + (r-g) / delta;
- h /= 6;
- if (h < 0)
- h += 1;
- }
- return color (h, s, v);
- }
-
- color rgb_to_hsl (color rgb) { // See Foley & van Dam
- // First convert rgb to hsv, then to hsl
- float minval = min (rgb[0], min (rgb[1], rgb[2]));
- color hsv = rgb_to_hsv (rgb);
- float maxval = hsv[2]; // v == maxval
- float h = hsv[0], s, l = (minval+maxval) / 2;
- if (minval == maxval)
- s = 0; // special 'achromatic' case, hue is 0
- else if (l <= 0.5)
- s = (maxval - minval) / (maxval + minval);
- else
- s = (maxval - minval) / (2 - maxval - minval);
- return color (h, s, l);
- }
-
- color r;
- if (to == "rgb" || to == "RGB")
- r = x;
- else if (to == "hsv")
- r = rgb_to_hsv (x);
- else if (to == "hsl")
- r = rgb_to_hsl (x);
- else if (to == "YIQ")
- r = color (dot (vector(0.299, 0.587, 0.114), (vector)x),
- dot (vector(0.596, -0.275, -0.321), (vector)x),
- dot (vector(0.212, -0.523, 0.311), (vector)x));
- else if (to == "xyz")
- r = color (dot (vector(0.412453, 0.357580, 0.180423), (vector)x),
- dot (vector(0.212671, 0.715160, 0.072169), (vector)x),
- dot (vector(0.019334, 0.119193, 0.950227), (vector)x));
- else {
- error ("Unknown color space \"%s\"", to);
- r = x;
- }
- return r;
+ color rgb_to_hsv(color rgb) { // See Foley & van Dam
+ float r = rgb[0], g = rgb[1], b = rgb[2];
+ float mincomp = min(r, min(g, b));
+ float maxcomp = max(r, max(g, b));
+ float delta = maxcomp - mincomp; // chroma
+ float h, s, v;
+ v = maxcomp;
+ if (maxcomp > 0)
+ s = delta / maxcomp;
+ else s = 0;
+ if (s <= 0)
+ h = 0;
+ else {
+ if (r >= maxcomp) h = (g - b) / delta;
+ else if (g >= maxcomp) h = 2 + (b - r) / delta;
+ else h = 4 + (r - g) / delta;
+ h /= 6;
+ if (h < 0)
+ h += 1;
+ }
+ return color(h, s, v);
+ }
+
+ color rgb_to_hsl(color rgb) { // See Foley & van Dam
+ // First convert rgb to hsv, then to hsl
+ float minval = min(rgb[0], min(rgb[1], rgb[2]));
+ color hsv = rgb_to_hsv(rgb);
+ float maxval = hsv[2]; // v == maxval
+ float h = hsv[0], s, l = (minval + maxval) / 2;
+ if (minval == maxval)
+ s = 0; // special 'achromatic' case, hue is 0
+ else if (l <= 0.5)
+ s = (maxval - minval) / (maxval + minval);
+ else
+ s = (maxval - minval) / (2 - maxval - minval);
+ return color(h, s, l);
+ }
+
+ color r;
+ if (to == "rgb" || to == "RGB")
+ r = x;
+ else if (to == "hsv")
+ r = rgb_to_hsv(x);
+ else if (to == "hsl")
+ r = rgb_to_hsl(x);
+ else if (to == "YIQ")
+ r = color(dot(vector(0.299, 0.587, 0.114), (vector)x),
+ dot(vector(0.596, -0.275, -0.321), (vector)x),
+ dot(vector(0.212, -0.523, 0.311), (vector)x));
+ else if (to == "xyz")
+ r = color(dot(vector(0.412453, 0.357580, 0.180423), (vector)x),
+ dot(vector(0.212671, 0.715160, 0.072169), (vector)x),
+ dot(vector(0.019334, 0.119193, 0.950227), (vector)x));
+ else {
+ error("Unknown color space \"%s\"", to);
+ r = x;
+ }
+ return r;
}
-color transformc (string from, string to, color x)
+color transformc(string from, string to, color x)
{
- color hsv_to_rgb (color c) { // Reference: Foley & van Dam
- float h = c[0], s = c[1], v = c[2];
- color r;
- if (s < 0.0001) {
- r = v;
- } else {
- h = 6 * (h - floor(h)); // expand to [0..6)
- int hi = (int)h;
- float f = h - hi;
- float p = v * (1-s);
- float q = v * (1-s*f);
- float t = v * (1-s*(1-f));
- if (hi == 0) r = color (v, t, p);
- else if (hi == 1) r = color (q, v, p);
- else if (hi == 2) r = color (p, v, t);
- else if (hi == 3) r = color (p, q, v);
- else if (hi == 4) r = color (t, p, v);
- else r = color (v, p, q);
- }
- return r;
- }
-
- color hsl_to_rgb (color c) {
- float h = c[0], s = c[1], l = c[2];
- // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam)
- float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s);
- color r;
- if (v <= 0) {
- r = 0;
- } else {
- float min = 2 * l - v;
- s = (v - min) / v;
- r = hsv_to_rgb (color (h, s, v));
- }
- return r;
- }
-
- color r;
- if (from == "rgb" || from == "RGB")
- r = x;
- else if (from == "hsv")
- r = hsv_to_rgb (x);
- else if (from == "hsl")
- r = hsl_to_rgb (x);
- else if (from == "YIQ")
- r = color (dot (vector(1, 0.9557, 0.6199), (vector)x),
- dot (vector(1, -0.2716, -0.6469), (vector)x),
- dot (vector(1, -1.1082, 1.7051), (vector)x));
- else if (from == "xyz")
- r = color (dot (vector( 3.240479, -1.537150, -0.498535), (vector)x),
- dot (vector(-0.969256, 1.875991, 0.041556), (vector)x),
- dot (vector( 0.055648, -0.204043, 1.057311), (vector)x));
- else {
- error ("Unknown color space \"%s\"", to);
- r = x;
- }
- return transformc (to, r);
+ color hsv_to_rgb(color c) { // Reference: Foley & van Dam
+ float h = c[0], s = c[1], v = c[2];
+ color r;
+ if (s < 0.0001) {
+ r = v;
+ }
+ else {
+ h = 6 * (h - floor(h)); // expand to [0..6)
+ int hi = (int)h;
+ float f = h - hi;
+ float p = v * (1 - s);
+ float q = v * (1 - s * f);
+ float t = v * (1 - s * (1 - f));
+ if (hi == 0) r = color(v, t, p);
+ else if (hi == 1) r = color(q, v, p);
+ else if (hi == 2) r = color(p, v, t);
+ else if (hi == 3) r = color(p, q, v);
+ else if (hi == 4) r = color(t, p, v);
+ else r = color(v, p, q);
+ }
+ return r;
+ }
+
+ color hsl_to_rgb(color c) {
+ float h = c[0], s = c[1], l = c[2];
+ // Easiest to convert hsl -> hsv, then hsv -> RGB (per Foley & van Dam)
+ float v = (l <= 0.5) ? (l * (1 + s)) : (l * (1 - s) + s);
+ color r;
+ if (v <= 0) {
+ r = 0;
+ }
+ else {
+ float min = 2 * l - v;
+ s = (v - min) / v;
+ r = hsv_to_rgb(color(h, s, v));
+ }
+ return r;
+ }
+
+ color r;
+ if (from == "rgb" || from == "RGB")
+ r = x;
+ else if (from == "hsv")
+ r = hsv_to_rgb(x);
+ else if (from == "hsl")
+ r = hsl_to_rgb(x);
+ else if (from == "YIQ")
+ r = color(dot(vector(1, 0.9557, 0.6199), (vector)x),
+ dot(vector(1, -0.2716, -0.6469), (vector)x),
+ dot(vector(1, -1.1082, 1.7051), (vector)x));
+ else if (from == "xyz")
+ r = color(dot(vector(3.240479, -1.537150, -0.498535), (vector)x),
+ dot(vector(-0.969256, 1.875991, 0.041556), (vector)x),
+ dot(vector(0.055648, -0.204043, 1.057311), (vector)x));
+ else {
+ error("Unknown color space \"%s\"", to);
+ r = x;
+ }
+ return transformc(to, r);
}
// Matrix functions
-float determinant (matrix m) BUILTIN;
-matrix transpose (matrix m) BUILTIN;
+float determinant(matrix m) BUILTIN;
+matrix transpose(matrix m) BUILTIN;
// Pattern generation
-float step (float edge, float x) BUILTIN;
-color step (color edge, color x) BUILTIN;
-point step (point edge, point x) BUILTIN;
-vector step (vector edge, vector x) BUILTIN;
-normal step (normal edge, normal x) BUILTIN;
-float smoothstep (float edge0, float edge1, float x) BUILTIN;
+float step(float edge, float x) BUILTIN;
+color step(color edge, color x) BUILTIN;
+point step(point edge, point x) BUILTIN;
+vector step(vector edge, vector x) BUILTIN;
+normal step(normal edge, normal x) BUILTIN;
+float smoothstep(float edge0, float edge1, float x) BUILTIN;
// Derivatives and area operators
@@ -408,24 +413,26 @@ float smoothstep (float edge0, float edge1, float x) BUILTIN;
// String functions
-int strlen (string s) BUILTIN;
-int startswith (string s, string prefix) BUILTIN;
-int endswith (string s, string suffix) BUILTIN;
-string substr (string s, int start, int len) BUILTIN;
-string substr (string s, int start) { return substr (s, start, strlen(s)); }
+int strlen(string s) BUILTIN;
+int startswith(string s, string prefix) BUILTIN;
+int endswith(string s, string suffix) BUILTIN;
+string substr(string s, int start, int len) BUILTIN;
+string substr(string s, int start) {
+ return substr(s, start, strlen(s));
+}
// Define concat in terms of shorter concat
-string concat (string a, string b, string c) {
- return concat(concat(a,b), c);
+string concat(string a, string b, string c) {
+ return concat(concat(a, b), c);
}
-string concat (string a, string b, string c, string d) {
- return concat(concat(a,b,c), d);
+string concat(string a, string b, string c, string d) {
+ return concat(concat(a, b, c), d);
}
-string concat (string a, string b, string c, string d, string e) {
- return concat(concat(a,b,c,d), e);
+string concat(string a, string b, string c, string d, string e) {
+ return concat(concat(a, b, c, d), e);
}
-string concat (string a, string b, string c, string d, string e, string f) {
- return concat(concat(a,b,c,d,e), f);
+string concat(string a, string b, string c, string d, string e, string f) {
+ return concat(concat(a, b, c, d, e), f);
}
@@ -438,7 +445,7 @@ closure color diffuse(normal N) BUILTIN;
closure color oren_nayar(normal N, float sigma) BUILTIN;
closure color translucent(normal N) BUILTIN;
closure color reflection(normal N, float eta) BUILTIN;
-closure color reflection(normal N) { return reflection (N, 0.0); }
+closure color reflection(normal N) { return reflection(N, 0.0); }
closure color refraction(normal N, float eta) BUILTIN;
closure color dielectric(normal N, float eta) BUILTIN;
closure color transparent() BUILTIN;
@@ -446,7 +453,7 @@ closure color microfacet_ggx(normal N, float ag) BUILTIN;
closure color microfacet_ggx_refraction(normal N, float ag, float eta) BUILTIN;
closure color microfacet_beckmann(normal N, float ab) BUILTIN;
closure color microfacet_beckmann_refraction(normal N, float ab, float eta) BUILTIN;
-closure color ward(normal N, vector T,float ax, float ay) BUILTIN;
+closure color ward(normal N, vector T, float ax, float ay) BUILTIN;
closure color ashikhmin_velvet(normal N, float sigma) BUILTIN;
closure color westin_backscatter(normal N, float roughness) BUILTIN;
closure color westin_sheen(normal N, float edginess) BUILTIN;
@@ -460,7 +467,7 @@ closure color holdout() BUILTIN;
closure color subsurface(float eta, float g, float mfp, float albedo) BUILTIN;
// Renderer state
-int raytype (string typename) BUILTIN;
+int raytype(string typename) BUILTIN;
#undef BUILTIN
#undef BUILTIN_DERIV
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index b87cdf8af86..0793b29d1ac 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -48,7 +48,7 @@ static void generic_closure_setup(OSL::RendererServices *, int id, void *data)
prim->setup();
}
-static bool generic_closure_mergeable(int id, const void *dataA, const void *dataB)
+static bool generic_closure_compare(int id, const void *dataA, const void *dataB)
{
assert(dataA && dataB);
@@ -59,11 +59,7 @@ static bool generic_closure_mergeable(int id, const void *dataA, const void *dat
static void register_closure(OSL::ShadingSystem *ss, const char *name, int id, OSL::ClosureParam *params, OSL::PrepareClosureFunc prepare)
{
- int j;
- for(j = 0; params[j].type != TypeDesc(); ++j) {}
- int size = params[j].offset;
-
- ss->register_closure(name, id, params, size, prepare, generic_closure_setup, generic_closure_mergeable);
+ ss->register_closure(name, id, params, prepare, generic_closure_setup, generic_closure_compare);
}
void OSLShader::register_closures(OSL::ShadingSystem *ss)
diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp
index 1b52a3e489b..a1574d6e0db 100644
--- a/intern/cycles/kernel/osl/osl_services.cpp
+++ b/intern/cycles/kernel/osl/osl_services.cpp
@@ -37,7 +37,7 @@ CCL_NAMESPACE_BEGIN
/* RenderServices implementation */
-#define TO_MATRIX44(m) (*(OSL::Matrix44*)&(m))
+#define TO_MATRIX44(m) (*(OSL::Matrix44 *)&(m))
/* static ustrings */
ustring OSLRenderServices::u_distance("distance");
@@ -65,14 +65,14 @@ void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_)
bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time)
{
/* this is only used for shader and object space, we don't really have
- a concept of shader space, so we just use object space for both. */
- if(xform) {
+ * a concept of shader space, so we just use object space for both. */
+ if (xform) {
KernelGlobals *kg = kernel_globals;
- const ShaderData *sd = (const ShaderData*)xform;
+ const ShaderData *sd = (const ShaderData *)xform;
int object = sd->object;
- if(object != ~0) {
- Transform tfm = object_fetch_transform(kg, object, OBJECT_TRANSFORM);
+ if (object != ~0) {
+ Transform tfm = object_fetch_transform(kg, object, time, OBJECT_TRANSFORM);
tfm = transform_transpose(tfm);
result = TO_MATRIX44(tfm);
@@ -86,14 +86,14 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, OSL::TransformationPtr
bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, OSL::TransformationPtr xform, float time)
{
/* this is only used for shader and object space, we don't really have
- a concept of shader space, so we just use object space for both. */
- if(xform) {
+ * a concept of shader space, so we just use object space for both. */
+ if (xform) {
KernelGlobals *kg = kernel_globals;
- const ShaderData *sd = (const ShaderData*)xform;
+ const ShaderData *sd = (const ShaderData *)xform;
int object = sd->object;
- if(object != ~0) {
- Transform tfm = object_fetch_transform(kg, object, OBJECT_INVERSE_TRANSFORM);
+ if (object != ~0) {
+ Transform tfm = object_fetch_transform(kg, object, time, OBJECT_INVERSE_TRANSFORM);
tfm = transform_transpose(tfm);
result = TO_MATRIX44(tfm);
@@ -108,22 +108,22 @@ bool OSLRenderServices::get_matrix(OSL::Matrix44 &result, ustring from, float ti
{
KernelGlobals *kg = kernel_globals;
- if(from == u_ndc) {
+ if (from == u_ndc) {
Transform tfm = transform_transpose(kernel_data.cam.ndctoworld);
result = TO_MATRIX44(tfm);
return true;
}
- else if(from == u_raster) {
+ else if (from == u_raster) {
Transform tfm = transform_transpose(kernel_data.cam.rastertoworld);
result = TO_MATRIX44(tfm);
return true;
}
- else if(from == u_screen) {
+ else if (from == u_screen) {
Transform tfm = transform_transpose(kernel_data.cam.screentoworld);
result = TO_MATRIX44(tfm);
return true;
}
- else if(from == u_camera) {
+ else if (from == u_camera) {
Transform tfm = transform_transpose(kernel_data.cam.cameratoworld);
result = TO_MATRIX44(tfm);
return true;
@@ -136,22 +136,22 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl
{
KernelGlobals *kg = kernel_globals;
- if(to == u_ndc) {
+ if (to == u_ndc) {
Transform tfm = transform_transpose(kernel_data.cam.worldtondc);
result = TO_MATRIX44(tfm);
return true;
}
- else if(to == u_raster) {
+ else if (to == u_raster) {
Transform tfm = transform_transpose(kernel_data.cam.worldtoraster);
result = TO_MATRIX44(tfm);
return true;
}
- else if(to == u_screen) {
+ else if (to == u_screen) {
Transform tfm = transform_transpose(kernel_data.cam.worldtoscreen);
result = TO_MATRIX44(tfm);
return true;
}
- else if(to == u_camera) {
+ else if (to == u_camera) {
Transform tfm = transform_transpose(kernel_data.cam.worldtocamera);
result = TO_MATRIX44(tfm);
return true;
@@ -161,56 +161,57 @@ bool OSLRenderServices::get_inverse_matrix(OSL::Matrix44 &result, ustring to, fl
}
bool OSLRenderServices::get_array_attribute(void *renderstate, bool derivatives,
- ustring object, TypeDesc type, ustring name,
- int index, void *val)
+ ustring object, TypeDesc type, ustring name,
+ int index, void *val)
{
return false;
}
static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd,
- const OSLGlobals::Attribute& attr, bool derivatives, void *val)
+ const OSLGlobals::Attribute& attr, bool derivatives, void *val)
{
- if(attr.type == TypeDesc::TypeFloat) {
- float *fval = (float*)val;
+ if (attr.type == TypeDesc::TypeFloat) {
+ float *fval = (float *)val;
fval[0] = triangle_attribute_float(kg, sd, attr.elem, attr.offset,
- (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
+ (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
}
else {
/* todo: this won't work when float3 has w component */
- float3 *fval = (float3*)val;
+ float3 *fval = (float3 *)val;
fval[0] = triangle_attribute_float3(kg, sd, attr.elem, attr.offset,
- (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: NULL);
+ (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
}
return true;
}
static bool get_mesh_attribute_convert(KernelGlobals *kg, const ShaderData *sd,
- const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val)
+ const OSLGlobals::Attribute& attr, const TypeDesc& type, bool derivatives, void *val)
{
- if(attr.type == TypeDesc::TypeFloat) {
+ if (attr.type == TypeDesc::TypeFloat) {
float tmp[3];
- float3 *fval = (float3*)val;
+ float3 *fval = (float3 *)val;
get_mesh_attribute(kg, sd, attr, derivatives, tmp);
fval[0] = make_float3(tmp[0], tmp[0], tmp[0]);
- if(derivatives) {
+ if (derivatives) {
fval[1] = make_float3(tmp[1], tmp[1], tmp[1]);
fval[2] = make_float3(tmp[2], tmp[2], tmp[2]);
}
return true;
}
- else if(attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
- attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
+ else if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
+ attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor)
+ {
float3 tmp[3];
- float *fval = (float*)val;
+ float *fval = (float *)val;
get_mesh_attribute(kg, sd, attr, derivatives, tmp);
fval[0] = average(tmp[0]);
- if(derivatives) {
+ if (derivatives) {
fval[1] = average(tmp[1]);
fval[2] = average(tmp[2]);
}
@@ -226,29 +227,29 @@ static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivat
size_t datasize = attr.value.datasize();
memcpy(val, attr.value.data(), datasize);
- if(derivatives)
- memset((char*)val + datasize, 0, datasize*2);
+ if (derivatives)
+ memset((char *)val + datasize, 0, datasize * 2);
}
bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustring object_name,
- TypeDesc type, ustring name, void *val)
+ TypeDesc type, ustring name, void *val)
{
KernelGlobals *kg = kernel_globals;
- const ShaderData *sd = (const ShaderData*)renderstate;
+ const ShaderData *sd = (const ShaderData *)renderstate;
int object = sd->object;
int tri = sd->prim;
/* lookup of attribute on another object */
- if(object_name != u_empty) {
+ if (object_name != u_empty) {
OSLGlobals::ObjectNameMap::iterator it = kg->osl.object_name_map.find(object_name);
- if(it == kg->osl.object_name_map.end())
+ if (it == kg->osl.object_name_map.end())
return false;
object = it->second;
tri = ~0;
}
- else if(object == ~0) {
+ else if (object == ~0) {
/* no background attributes supported */
return false;
}
@@ -257,20 +258,23 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri
OSLGlobals::AttributeMap& attribute_map = kg->osl.attribute_map[object];
OSLGlobals::AttributeMap::iterator it = attribute_map.find(name);
- if(it == attribute_map.end())
+ if (it == attribute_map.end())
return false;
/* type mistmatch? */
const OSLGlobals::Attribute& attr = it->second;
- if(attr.elem != ATTR_ELEMENT_VALUE) {
+ if (attr.elem != ATTR_ELEMENT_VALUE) {
/* triangle and vertex attributes */
- if(tri != ~0) {
- if(attr.type == type || (attr.type == TypeDesc::TypeColor &&
- (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal)))
+ if (tri != ~0) {
+ if (attr.type == type || (attr.type == TypeDesc::TypeColor &&
+ (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || type == TypeDesc::TypeNormal)))
+ {
return get_mesh_attribute(kg, sd, attr, derivatives, val);
- else
+ }
+ else {
return get_mesh_attribute_convert(kg, sd, attr, type, derivatives, val);
+ }
}
}
else {
@@ -283,7 +287,7 @@ bool OSLRenderServices::get_attribute(void *renderstate, bool derivatives, ustri
}
bool OSLRenderServices::get_userdata(bool derivatives, ustring name, TypeDesc type,
- void *renderstate, void *val)
+ void *renderstate, void *val)
{
return false; /* disabled by lockgeom */
}
@@ -294,42 +298,46 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst
}
void *OSLRenderServices::get_pointcloud_attr_query(ustring *attr_names,
- TypeDesc *attr_types, int nattrs)
+ TypeDesc *attr_types, int nattrs)
{
#ifdef WITH_PARTIO
m_attr_queries.push_back(AttrQuery());
AttrQuery &query = m_attr_queries.back();
/* make space for what we need. the only reason to use
- std::vector is to skip the delete */
+ * std::vector is to skip the delete */
query.attr_names.resize(nattrs);
query.attr_partio_types.resize(nattrs);
/* capacity will keep the length of the smallest array passed
- to the query. Just to prevent buffer overruns */
+ * to the query. Just to prevent buffer overruns */
query.capacity = -1;
- for(int i = 0; i < nattrs; ++i)
- {
+ for (int i = 0; i < nattrs; ++i) {
query.attr_names[i] = attr_names[i];
- TypeDesc element_type = attr_types[i].elementtype ();
+ TypeDesc element_type = attr_types[i].elementtype();
- if(query.capacity < 0)
- query.capacity = attr_types[i].numelements();
+ if (query.capacity < 0)
+ query.capacity = attr_types[i].numelements();
else
- query.capacity = min(query.capacity, (int)attr_types[i].numelements());
+ query.capacity = min(query.capacity, (int)attr_types[i].numelements());
/* convert the OSL (OIIO) type to the equivalent Partio type so
- we can do a fast check at query time. */
- if(element_type == TypeDesc::TypeFloat)
- query.attr_partio_types[i] = Partio::FLOAT;
- else if(element_type == TypeDesc::TypeInt)
- query.attr_partio_types[i] = Partio::INT;
- else if(element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint ||
- element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal)
- query.attr_partio_types[i] = Partio::VECTOR;
- else
- return NULL; /* report some error of unknown type */
+ * we can do a fast check at query time. */
+ if (element_type == TypeDesc::TypeFloat) {
+ query.attr_partio_types[i] = Partio::FLOAT;
+ }
+ else if (element_type == TypeDesc::TypeInt) {
+ query.attr_partio_types[i] = Partio::INT;
+ }
+ else if (element_type == TypeDesc::TypeColor || element_type == TypeDesc::TypePoint ||
+ element_type == TypeDesc::TypeVector || element_type == TypeDesc::TypeNormal)
+ {
+ query.attr_partio_types[i] = Partio::VECTOR;
+ }
+ else {
+ return NULL; /* report some error of unknown type */
+ }
}
/* this is valid until the end of RenderServices */
@@ -348,35 +356,35 @@ Partio::ParticlesData *OSLRenderServices::get_pointcloud(ustring filename)
#endif
int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 &center, float radius,
- int max_points, void *_attr_query, void **attr_outdata)
+ int max_points, void *_attr_query, void **attr_outdata)
{
/* todo: this code has never been tested, and most likely does not
- work. it's based on the example code in OSL */
+ * work. it's based on the example code in OSL */
#ifdef WITH_PARTIO
/* query Partio for this pointcloud lookup using cached attr_query */
- if(!_attr_query)
+ if (!_attr_query)
return 0;
AttrQuery *attr_query = (AttrQuery *)_attr_query;
- if(attr_query->capacity < max_points)
+ if (attr_query->capacity < max_points)
return 0;
/* get the pointcloud entry for the given filename */
Partio::ParticlesData *cloud = get_pointcloud(filename);
/* now we have to look up all the attributes in the file. we can't do this
- before hand cause we never know what we are going to load. */
+ * before hand cause we never know what we are going to load. */
int nattrs = attr_query->attr_names.size();
Partio::ParticleAttribute *attr = (Partio::ParticleAttribute *)alloca(sizeof(Partio::ParticleAttribute) * nattrs);
- for(int i = 0; i < nattrs; ++i) {
+ for (int i = 0; i < nattrs; ++i) {
/* special case attributes */
- if(attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index)
+ if (attr_query->attr_names[i] == u_distance || attr_query->attr_names[i] == u_index)
continue;
/* lookup the attribute by name*/
- if(!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) {
+ if (!cloud->attributeInfo(attr_query->attr_names[i].c_str(), attr[i])) {
/* issue an error here and return, types don't match */
Partio::endCachedAccess(cloud);
cloud->release();
@@ -394,20 +402,20 @@ int OSLRenderServices::pointcloud(ustring filename, const OSL::Vec3 &center, flo
int count = indices.size();
/* retrieve the attributes directly to user space */
- for(int j = 0; j < nattrs; ++j) {
+ for (int j = 0; j < nattrs; ++j) {
/* special cases */
- if(attr_query->attr_names[j] == u_distance) {
- for(int i = 0; i < count; ++i)
+ if (attr_query->attr_names[j] == u_distance) {
+ for (int i = 0; i < count; ++i)
((float *)attr_outdata[j])[i] = sqrtf(dist2[i]);
}
- else if(attr_query->attr_names[j] == u_index) {
- for(int i = 0; i < count; ++i)
+ else if (attr_query->attr_names[j] == u_index) {
+ for (int i = 0; i < count; ++i)
((int *)attr_outdata[j])[i] = indices[i];
}
else {
/* note we make a single call per attribute, we don't loop over the
- points. Partio does it, so it is there that we have to care about
- performance */
+ * points. Partio does it, so it is there that we have to care about
+ * performance */
cloud->data(attr[j], count, &indices[0], true, attr_outdata[j]);
}
}
diff --git a/intern/cycles/kernel/osl/osl_services.h b/intern/cycles/kernel/osl/osl_services.h
index 85a01e54e5c..e637b53ab78 100644
--- a/intern/cycles/kernel/osl/osl_services.h
+++ b/intern/cycles/kernel/osl/osl_services.h
@@ -57,34 +57,33 @@ public:
bool get_inverse_matrix(OSL::Matrix44 &result, ustring to, float time);
bool get_array_attribute(void *renderstate, bool derivatives,
- ustring object, TypeDesc type, ustring name,
- int index, void *val);
+ ustring object, TypeDesc type, ustring name,
+ int index, void *val);
bool get_attribute(void *renderstate, bool derivatives, ustring object,
- TypeDesc type, ustring name, void *val);
+ TypeDesc type, ustring name, void *val);
bool get_userdata(bool derivatives, ustring name, TypeDesc type,
- void *renderstate, void *val);
+ void *renderstate, void *val);
bool has_userdata(ustring name, TypeDesc type, void *renderstate);
void *get_pointcloud_attr_query(ustring *attr_names,
- TypeDesc *attr_types, int nattrs);
+ TypeDesc *attr_types, int nattrs);
int pointcloud(ustring filename, const OSL::Vec3 &center, float radius,
- int max_points, void *attr_query, void **attr_outdata);
+ int max_points, void *attr_query, void **attr_outdata);
private:
KernelGlobals *kernel_globals;
#ifdef WITH_PARTIO
/* OSL gets pointers to this but its definition is private.
- right now it only caches the types already converted to
- Partio constants. this is what get_pointcloud_attr_query
- returns */
- struct AttrQuery
- {
+ * right now it only caches the types already converted to
+ * Partio constants. this is what get_pointcloud_attr_query
+ * returns */
+ struct AttrQuery {
/* names of the attributes to query */
std::vector<ustring> attr_names;
/* types as (enum Partio::ParticleAttributeType) of the
- attributes in the query */
+ * attributes in the query */
std::vector<int> attr_partio_types;
/* for sanity checks, capacity of the output arrays */
int capacity;
diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp
index 18a8e974492..d8d510a7c9b 100644
--- a/intern/cycles/kernel/osl/osl_shader.cpp
+++ b/intern/cycles/kernel/osl/osl_shader.cpp
@@ -27,7 +27,6 @@
#include "util_foreach.h"
#include <OSL/oslexec.h>
-#include <oslexec_pvt.h>
CCL_NAMESPACE_BEGIN
@@ -37,7 +36,7 @@ tls_ptr(OSLGlobals::ThreadData, OSLGlobals::thread_data);
void OSLShader::thread_init(KernelGlobals *kg)
{
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = new OSLGlobals::ThreadData();
@@ -46,12 +45,12 @@ void OSLShader::thread_init(KernelGlobals *kg)
tls_set(kg->osl.thread_data, tdata);
- ((OSLRenderServices*)ssi->renderer())->thread_init(kg);
+ ((OSLRenderServices *)ssi->renderer())->thread_init(kg);
}
void OSLShader::thread_free(KernelGlobals *kg)
{
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
@@ -62,12 +61,12 @@ void OSLShader::thread_free(KernelGlobals *kg)
/* Globals */
-#define TO_VEC3(v) (*(OSL::Vec3*)&(v))
-#define TO_COLOR3(v) (*(OSL::Color3*)&(v))
+#define TO_VEC3(v) (*(OSL::Vec3 *)&(v))
+#define TO_COLOR3(v) (*(OSL::Color3 *)&(v))
#define TO_FLOAT3(v) make_float3(v[0], v[1], v[2])
static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd,
- int path_flag, OSL::ShaderGlobals *globals)
+ int path_flag, OSL::ShaderGlobals *globals)
{
/* copy from shader data to shader globals */
globals->P = TO_VEC3(sd->P);
@@ -86,7 +85,7 @@ static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd,
globals->dvdy = sd->dv.dy;
globals->dPdu = TO_VEC3(sd->dPdu);
globals->dPdv = TO_VEC3(sd->dPdv);
- globals->surfacearea = (sd->object == ~0)? 1.0f: object_surface_area(kg, sd->object);
+ globals->surfacearea = (sd->object == ~0) ? 1.0f : object_surface_area(kg, sd->object);
/* booleans */
globals->raytype = path_flag; /* todo: add our own ray types */
@@ -109,35 +108,35 @@ static void shaderdata_to_shaderglobals(KernelGlobals *kg, ShaderData *sd,
/* Surface */
static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
- const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f))
+ const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f))
{
- /* OSL gives use a closure tree, we flatten it into arrays per
+ /* OSL gives us a closure tree, we flatten it into arrays per
* closure type, for evaluation, sampling, etc later on. */
- if(closure->type == OSL::ClosureColor::COMPONENT) {
- OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure;
- OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data();
+ if (closure->type == OSL::ClosureColor::COMPONENT) {
+ OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
+ OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data();
- if(prim) {
+ if (prim) {
ShaderClosure sc;
sc.prim = prim;
sc.weight = weight;
- switch(prim->category()) {
+ switch (prim->category()) {
case ClosurePrimitive::BSDF: {
- if(sd->num_closure == MAX_CLOSURE)
+ if (sd->num_closure == MAX_CLOSURE)
return;
- OSL::BSDFClosure *bsdf = (OSL::BSDFClosure*)prim;
+ OSL::BSDFClosure *bsdf = (OSL::BSDFClosure *)prim;
ustring scattering = bsdf->scattering();
/* no caustics option */
- if(no_glossy && scattering == OSL::Labels::GLOSSY)
+ if (no_glossy && scattering == OSL::Labels::GLOSSY)
return;
/* sample weight */
float albedo = bsdf->albedo(TO_VEC3(sd->I));
- float sample_weight = fabsf(average(weight))*albedo;
+ float sample_weight = fabsf(average(weight)) * albedo;
float sample_sum = sd->osl_closure.bsdf_sample_sum + sample_weight;
sc.sample_weight = sample_weight;
@@ -145,10 +144,10 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
sd->osl_closure.bsdf_sample_sum = sample_sum;
/* scattering flags */
- if(scattering == OSL::Labels::DIFFUSE)
- sd->flag |= SD_BSDF|SD_BSDF_HAS_EVAL;
- else if(scattering == OSL::Labels::GLOSSY)
- sd->flag |= SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_GLOSSY;
+ if (scattering == OSL::Labels::DIFFUSE)
+ sd->flag |= SD_BSDF | SD_BSDF_HAS_EVAL;
+ else if (scattering == OSL::Labels::GLOSSY)
+ sd->flag |= SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_GLOSSY;
else
sd->flag |= SD_BSDF;
@@ -157,7 +156,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
break;
}
case ClosurePrimitive::Emissive: {
- if(sd->num_closure == MAX_CLOSURE)
+ if (sd->num_closure == MAX_CLOSURE)
return;
/* sample weight */
@@ -175,7 +174,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
break;
}
case ClosurePrimitive::Holdout:
- if(sd->num_closure == MAX_CLOSURE)
+ if (sd->num_closure == MAX_CLOSURE)
return;
sc.sample_weight = 0.0f;
@@ -192,12 +191,12 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
}
}
}
- else if(closure->type == OSL::ClosureColor::MUL) {
- OSL::ClosureMul *mul = (OSL::ClosureMul*)closure;
+ else if (closure->type == OSL::ClosureColor::MUL) {
+ OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
flatten_surface_closure_tree(sd, no_glossy, mul->closure, TO_FLOAT3(mul->weight) * weight);
}
- else if(closure->type == OSL::ClosureColor::ADD) {
- OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure;
+ else if (closure->type == OSL::ClosureColor::ADD) {
+ OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
flatten_surface_closure_tree(sd, no_glossy, add->closureA, weight);
flatten_surface_closure_tree(sd, no_glossy, add->closureB, weight);
}
@@ -206,7 +205,7 @@ static void flatten_surface_closure_tree(ShaderData *sd, bool no_glossy,
void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag)
{
/* gather pointers */
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info);
@@ -218,14 +217,14 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int
/* execute shader for this point */
int shader = sd->shader & SHADER_MASK;
- if(kg->osl.surface_state[shader])
+ if (kg->osl.surface_state[shader])
ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.surface_state[shader]), *globals);
/* flatten closure tree */
sd->num_closure = 0;
sd->randb_closure = randb;
- if(globals->Ci) {
+ if (globals->Ci) {
bool no_glossy = (path_flag & PATH_RAY_DIFFUSE) && kernel_data.integrator.no_caustics;
flatten_surface_closure_tree(sd, no_glossy, globals->Ci);
}
@@ -235,27 +234,27 @@ void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int
static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure)
{
- /* OSL gives use a closure tree, if we are shading for background there
+ /* OSL gives us a closure tree, if we are shading for background there
* is only one supported closure type at the moment, which has no evaluation
* functions, so we just sum the weights */
- if(closure->type == OSL::ClosureColor::COMPONENT) {
- OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure;
- OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data();
+ if (closure->type == OSL::ClosureColor::COMPONENT) {
+ OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
+ OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data();
- if(prim && prim->category() == OSL::ClosurePrimitive::Background)
+ if (prim && prim->category() == OSL::ClosurePrimitive::Background)
return make_float3(1.0f, 1.0f, 1.0f);
}
- else if(closure->type == OSL::ClosureColor::MUL) {
- OSL::ClosureMul *mul = (OSL::ClosureMul*)closure;
+ else if (closure->type == OSL::ClosureColor::MUL) {
+ OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
return TO_FLOAT3(mul->weight) * flatten_background_closure_tree(mul->closure);
}
- else if(closure->type == OSL::ClosureColor::ADD) {
- OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure;
+ else if (closure->type == OSL::ClosureColor::ADD) {
+ OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
return flatten_background_closure_tree(add->closureA) +
- flatten_background_closure_tree(add->closureB);
+ flatten_background_closure_tree(add->closureB);
}
return make_float3(0.0f, 0.0f, 0.0f);
@@ -264,7 +263,7 @@ static float3 flatten_background_closure_tree(const OSL::ClosureColor *closure)
float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag)
{
/* gather pointers */
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info);
@@ -274,11 +273,11 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl
shaderdata_to_shaderglobals(kg, sd, path_flag, globals);
/* execute shader for this point */
- if(kg->osl.background_state)
+ if (kg->osl.background_state)
ctx->execute(OSL::pvt::ShadUseSurface, *kg->osl.background_state, *globals);
/* return background color immediately */
- if(globals->Ci)
+ if (globals->Ci)
return flatten_background_closure_tree(globals->Ci);
return make_float3(0.0f, 0.0f, 0.0f);
@@ -287,23 +286,23 @@ float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_fl
/* Volume */
static void flatten_volume_closure_tree(ShaderData *sd,
- const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f))
+ const OSL::ClosureColor *closure, float3 weight = make_float3(1.0f, 1.0f, 1.0f))
{
- /* OSL gives use a closure tree, we flatten it into arrays per
+ /* OSL gives us a closure tree, we flatten it into arrays per
* closure type, for evaluation, sampling, etc later on. */
- if(closure->type == OSL::ClosureColor::COMPONENT) {
- OSL::ClosureComponent *comp = (OSL::ClosureComponent*)closure;
- OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive*)comp->data();
+ if (closure->type == OSL::ClosureColor::COMPONENT) {
+ OSL::ClosureComponent *comp = (OSL::ClosureComponent *)closure;
+ OSL::ClosurePrimitive *prim = (OSL::ClosurePrimitive *)comp->data();
- if(prim) {
+ if (prim) {
ShaderClosure sc;
sc.prim = prim;
sc.weight = weight;
- switch(prim->category()) {
+ switch (prim->category()) {
case ClosurePrimitive::Volume: {
- if(sd->num_closure == MAX_CLOSURE)
+ if (sd->num_closure == MAX_CLOSURE)
return;
/* sample weight */
@@ -329,12 +328,12 @@ static void flatten_volume_closure_tree(ShaderData *sd,
}
}
}
- else if(closure->type == OSL::ClosureColor::MUL) {
- OSL::ClosureMul *mul = (OSL::ClosureMul*)closure;
+ else if (closure->type == OSL::ClosureColor::MUL) {
+ OSL::ClosureMul *mul = (OSL::ClosureMul *)closure;
flatten_volume_closure_tree(sd, mul->closure, TO_FLOAT3(mul->weight) * weight);
}
- else if(closure->type == OSL::ClosureColor::ADD) {
- OSL::ClosureAdd *add = (OSL::ClosureAdd*)closure;
+ else if (closure->type == OSL::ClosureColor::ADD) {
+ OSL::ClosureAdd *add = (OSL::ClosureAdd *)closure;
flatten_volume_closure_tree(sd, add->closureA, weight);
flatten_volume_closure_tree(sd, add->closureB, weight);
}
@@ -343,7 +342,7 @@ static void flatten_volume_closure_tree(ShaderData *sd,
void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag)
{
/* gather pointers */
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info);
@@ -355,7 +354,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int
/* execute shader */
int shader = sd->shader & SHADER_MASK;
- if(kg->osl.volume_state[shader])
+ if (kg->osl.volume_state[shader])
ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.volume_state[shader]), *globals);
/* retrieve resulting closures */
@@ -363,7 +362,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int
sd->osl_closure.num_volume = 0;
sd->osl_closure.randb = randb;
- if(globals->Ci)
+ if (globals->Ci)
flatten_volume_closure_tree(sd, globals->Ci);
}
@@ -372,7 +371,7 @@ void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int
void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
{
/* gather pointers */
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::pvt::ShadingContext *ctx = ssi->get_context(tdata->thread_info);
@@ -384,7 +383,7 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
/* execute shader */
int shader = sd->shader & SHADER_MASK;
- if(kg->osl.displacement_state[shader])
+ if (kg->osl.displacement_state[shader])
ctx->execute(OSL::pvt::ShadUseSurface, *(kg->osl.displacement_state[shader]), *globals);
/* get back position */
@@ -393,17 +392,17 @@ void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd)
void OSLShader::release(KernelGlobals *kg, const ShaderData *sd)
{
- OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl*)kg->osl.ss;
+ OSL::pvt::ShadingSystemImpl *ssi = (OSL::pvt::ShadingSystemImpl *)kg->osl.ss;
OSLGlobals::ThreadData *tdata = tls_get(OSLGlobals::ThreadData, kg->osl.thread_data);
- ssi->release_context((OSL::pvt::ShadingContext*)sd->osl_ctx, tdata->thread_info);
+ ssi->release_context((OSL::pvt::ShadingContext *)sd->osl_ctx, tdata->thread_info);
}
/* BSDF Closure */
int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float randu, float randv, float3& eval, float3& omega_in, differential3& domega_in, float& pdf)
{
- OSL::BSDFClosure *sample_bsdf = (OSL::BSDFClosure*)sc->prim;
+ OSL::BSDFClosure *sample_bsdf = (OSL::BSDFClosure *)sc->prim;
int label = LABEL_NONE;
pdf = 0.0f;
@@ -412,27 +411,27 @@ int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float
ustring ulabel;
ulabel = sample_bsdf->sample(TO_VEC3(sd->Ng),
- TO_VEC3(sd->I), TO_VEC3(sd->dI.dx), TO_VEC3(sd->dI.dy),
- randu, randv,
- TO_VEC3(omega_in), TO_VEC3(domega_in.dx), TO_VEC3(domega_in.dy),
- pdf, TO_COLOR3(eval));
+ TO_VEC3(sd->I), TO_VEC3(sd->dI.dx), TO_VEC3(sd->dI.dy),
+ randu, randv,
+ TO_VEC3(omega_in), TO_VEC3(domega_in.dx), TO_VEC3(domega_in.dy),
+ pdf, TO_COLOR3(eval));
/* convert OSL label */
- if(ulabel == OSL::Labels::REFLECT)
+ if (ulabel == OSL::Labels::REFLECT)
label = LABEL_REFLECT;
- else if(ulabel == OSL::Labels::TRANSMIT)
+ else if (ulabel == OSL::Labels::TRANSMIT)
label = LABEL_TRANSMIT;
else
- return LABEL_NONE; /* sampling failed */
+ return LABEL_NONE; /* sampling failed */
/* convert scattering to our bitflag label */
ustring uscattering = sample_bsdf->scattering();
- if(uscattering == OSL::Labels::DIFFUSE)
+ if (uscattering == OSL::Labels::DIFFUSE)
label |= LABEL_DIFFUSE;
- else if(uscattering == OSL::Labels::GLOSSY)
+ else if (uscattering == OSL::Labels::GLOSSY)
label |= LABEL_GLOSSY;
- else if(uscattering == OSL::Labels::SINGULAR)
+ else if (uscattering == OSL::Labels::SINGULAR)
label |= LABEL_SINGULAR;
else
label |= LABEL_TRANSPARENT;
@@ -442,10 +441,10 @@ int OSLShader::bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float
float3 OSLShader::bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3& omega_in, float& pdf)
{
- OSL::BSDFClosure *bsdf = (OSL::BSDFClosure*)sc->prim;
+ OSL::BSDFClosure *bsdf = (OSL::BSDFClosure *)sc->prim;
OSL::Color3 bsdf_eval;
- if(dot(sd->Ng, omega_in) >= 0.0f)
+ if (dot(sd->Ng, omega_in) >= 0.0f)
bsdf_eval = bsdf->eval_reflect(TO_VEC3(sd->I), TO_VEC3(omega_in), pdf);
else
bsdf_eval = bsdf->eval_transmit(TO_VEC3(sd->I), TO_VEC3(omega_in), pdf);
@@ -457,7 +456,7 @@ float3 OSLShader::bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const
float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc)
{
- OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure*)sc->prim;
+ OSL::EmissiveClosure *emissive = (OSL::EmissiveClosure *)sc->prim;
OSL::Color3 emissive_eval = emissive->eval(TO_VEC3(sd->Ng), TO_VEC3(sd->I));
eval += TO_FLOAT3(emissive_eval);
@@ -468,9 +467,9 @@ float3 OSLShader::emissive_eval(const ShaderData *sd, const ShaderClosure *sc)
float3 OSLShader::volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, const float3 omega_out)
{
- OSL::VolumeClosure *volume = (OSL::VolumeClosure*)sc->prim;
+ OSL::VolumeClosure *volume = (OSL::VolumeClosure *)sc->prim;
OSL::Color3 volume_eval = volume->eval_phase(TO_VEC3(omega_in), TO_VEC3(omega_out));
- return TO_FLOAT3(volume_eval)*sc->weight;
+ return TO_FLOAT3(volume_eval) * sc->weight;
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/osl/osl_shader.h b/intern/cycles/kernel/osl/osl_shader.h
index 6b1d402989b..815557ed203 100644
--- a/intern/cycles/kernel/osl/osl_shader.h
+++ b/intern/cycles/kernel/osl/osl_shader.h
@@ -68,15 +68,15 @@ public:
/* sample & eval */
static int bsdf_sample(const ShaderData *sd, const ShaderClosure *sc,
- float randu, float randv,
- float3& eval, float3& omega_in, differential3& domega_in, float& pdf);
+ float randu, float randv,
+ float3& eval, float3& omega_in, differential3& domega_in, float& pdf);
static float3 bsdf_eval(const ShaderData *sd, const ShaderClosure *sc,
- const float3& omega_in, float& pdf);
+ const float3& omega_in, float& pdf);
static float3 emissive_eval(const ShaderData *sd, const ShaderClosure *sc);
static float3 volume_eval_phase(const ShaderData *sd, const ShaderClosure *sc,
- const float3 omega_in, const float3 omega_out);
+ const float3 omega_in, const float3 omega_out);
/* release */
static void release(KernelGlobals *kg, const ShaderData *sd);
diff --git a/intern/cycles/kernel/osl/vol_subsurface.cpp b/intern/cycles/kernel/osl/vol_subsurface.cpp
index 0cd3060051b..818a057b6cc 100644
--- a/intern/cycles/kernel/osl/vol_subsurface.cpp
+++ b/intern/cycles/kernel/osl/vol_subsurface.cpp
@@ -46,88 +46,90 @@ using namespace OSL;
class SubsurfaceClosure : public VolumeClosure {
public:
- float m_g;
- float m_eta;
- Color3 m_mfp, m_albedo;
- static float root_find_Rd(const float Rd0, const float A) {
- // quick exit for trivial cases
- if (Rd0 <= 0) return 0;
- const float A43 = A * 4.0f / 3.0f;
- // Find alpha such that f(alpha) = Rd (see eq.15). A simple bisection
- // method can be used because this function is monotonicaly increasing.
- float lo = 0, hi = 1;
- for (int i = 0; i < 20; i++) { // 2^20 divisions should be sufficient
- // eval function at midpoint
- float alpha = 0.5f * (lo + hi);
- float a1 = sqrtf(3 * (1 - alpha));
- float e1 = expf(-a1);
- float e2 = expf(-A43 * a1);
- float Rd = 0.5f * alpha * (1 + e2) * e1 - Rd0;
- if (fabsf(Rd) < 1e-6f)
- return alpha; // close enough
- else if (Rd > 0)
- hi = alpha; // root is on left side
- else
- lo = alpha; // root is on right side
- }
- // didn't quite converge, pick result in the middle of remaining interval
- return 0.5f * (lo + hi);
- }
- SubsurfaceClosure() { }
-
- void setup()
- {
- ior(m_eta);
-
- if (m_g >= 0.99f) m_g = 0.99f;
- if (m_g <= -0.99f) m_g = -0.99f;
-
- // eq.10
- float inv_eta = 1 / m_eta;
- float Fdr = -1.440f * inv_eta * inv_eta + 0.710 * inv_eta + 0.668f + 0.0636 * m_eta;
- float A = (1 + Fdr) / (1 - Fdr);
- // compute sigma_s, sigma_a (eq.16)
- Color3 alpha_prime = Color3 (root_find_Rd(m_albedo[0], A),
- root_find_Rd(m_albedo[1], A),
- root_find_Rd(m_albedo[2], A));
- Color3 sigma_t_prime = Color3 (m_mfp.x > 0 ? 1.0f / (m_mfp[0] * sqrtf(3 * (1 - alpha_prime[0]))) : 0.0f,
- m_mfp.y > 0 ? 1.0f / (m_mfp[1] * sqrtf(3 * (1 - alpha_prime[1]))) : 0.0f,
- m_mfp.z > 0 ? 1.0f / (m_mfp[2] * sqrtf(3 * (1 - alpha_prime[2]))) : 0.0f);
- Color3 sigma_s_prime = alpha_prime * sigma_t_prime;
-
- sigma_s((1.0f / (1 - m_g)) * sigma_s_prime);
- sigma_a(sigma_t_prime - sigma_s_prime);
- }
-
- bool mergeable (const ClosurePrimitive *other) const {
- const SubsurfaceClosure *comp = (const SubsurfaceClosure *)other;
- return m_g == comp->m_g && VolumeClosure::mergeable(other);
- }
-
- size_t memsize () const { return sizeof(*this); }
-
- const char *name () const { return "subsurface"; }
-
- void print_on (std::ostream &out) const {
- out << name() << " ()";
- }
-
- virtual Color3 eval_phase(const Vec3 &omega_in, const Vec3 &omega_out) const {
- float costheta = omega_in.dot(omega_out);
- float ph = 0.25f * float(M_1_PI) * ((1 - m_g * m_g) / powf(1 + m_g * m_g - 2.0f * m_g * costheta, 1.5f));
- return Color3 (ph, ph, ph);
- }
+ float m_g;
+ float m_eta;
+ Color3 m_mfp, m_albedo;
+ static float root_find_Rd(const float Rd0, const float A) {
+ // quick exit for trivial cases
+ if (Rd0 <= 0) return 0;
+ const float A43 = A * 4.0f / 3.0f;
+ // Find alpha such that f(alpha) = Rd (see eq.15). A simple bisection
+ // method can be used because this function is monotonicaly increasing.
+ float lo = 0, hi = 1;
+ for (int i = 0; i < 20; i++) { // 2^20 divisions should be sufficient
+ // eval function at midpoint
+ float alpha = 0.5f * (lo + hi);
+ float a1 = sqrtf(3 * (1 - alpha));
+ float e1 = expf(-a1);
+ float e2 = expf(-A43 * a1);
+ float Rd = 0.5f * alpha * (1 + e2) * e1 - Rd0;
+ if (fabsf(Rd) < 1e-6f)
+ return alpha; // close enough
+ else if (Rd > 0)
+ hi = alpha; // root is on left side
+ else
+ lo = alpha; // root is on right side
+ }
+ // didn't quite converge, pick result in the middle of remaining interval
+ return 0.5f * (lo + hi);
+ }
+ SubsurfaceClosure() {
+ }
+
+ void setup()
+ {
+ ior(m_eta);
+
+ if (m_g >= 0.99f) m_g = 0.99f;
+ if (m_g <= -0.99f) m_g = -0.99f;
+
+ // eq.10
+ float inv_eta = 1 / m_eta;
+ float Fdr = -1.440f * inv_eta * inv_eta + 0.710 * inv_eta + 0.668f + 0.0636 * m_eta;
+ float A = (1 + Fdr) / (1 - Fdr);
+ // compute sigma_s, sigma_a (eq.16)
+ Color3 alpha_prime = Color3(root_find_Rd(m_albedo[0], A),
+ root_find_Rd(m_albedo[1], A),
+ root_find_Rd(m_albedo[2], A));
+ Color3 sigma_t_prime = Color3(m_mfp.x > 0 ? 1.0f / (m_mfp[0] * sqrtf(3 * (1 - alpha_prime[0]))) : 0.0f,
+ m_mfp.y > 0 ? 1.0f / (m_mfp[1] * sqrtf(3 * (1 - alpha_prime[1]))) : 0.0f,
+ m_mfp.z > 0 ? 1.0f / (m_mfp[2] * sqrtf(3 * (1 - alpha_prime[2]))) : 0.0f);
+ Color3 sigma_s_prime = alpha_prime * sigma_t_prime;
+
+ sigma_s((1.0f / (1 - m_g)) * sigma_s_prime);
+ sigma_a(sigma_t_prime - sigma_s_prime);
+ }
+
+ bool mergeable(const ClosurePrimitive *other) const {
+ const SubsurfaceClosure *comp = (const SubsurfaceClosure *)other;
+ return m_g == comp->m_g && VolumeClosure::mergeable(other);
+ }
+
+ size_t memsize() const { return sizeof(*this); }
+
+ const char *name() const { return "subsurface"; }
+
+ void print_on(std::ostream &out) const {
+ out << name() << " ()";
+ }
+
+ virtual Color3 eval_phase(const Vec3 &omega_in, const Vec3 &omega_out) const {
+ float costheta = omega_in.dot(omega_out);
+ float ph = 0.25f * float(M_1_PI) * ((1 - m_g * m_g) / powf(1 + m_g * m_g - 2.0f * m_g * costheta, 1.5f));
+ return Color3(ph, ph, ph);
+ }
};
ClosureParam closure_subsurface_params[] = {
- CLOSURE_FLOAT_PARAM (SubsurfaceClosure, m_eta),
- CLOSURE_FLOAT_PARAM (SubsurfaceClosure, m_g),
- CLOSURE_COLOR_PARAM (SubsurfaceClosure, m_mfp),
- CLOSURE_COLOR_PARAM (SubsurfaceClosure, m_albedo),
- CLOSURE_STRING_KEYPARAM("label"),
- CLOSURE_FINISH_PARAM(SubsurfaceClosure) };
+ CLOSURE_FLOAT_PARAM(SubsurfaceClosure, m_eta),
+ CLOSURE_FLOAT_PARAM(SubsurfaceClosure, m_g),
+ CLOSURE_COLOR_PARAM(SubsurfaceClosure, m_mfp),
+ CLOSURE_COLOR_PARAM(SubsurfaceClosure, m_albedo),
+ CLOSURE_STRING_KEYPARAM("label"),
+ CLOSURE_FINISH_PARAM(SubsurfaceClosure)
+};
CLOSURE_PREPARE(closure_subsurface_prepare, SubsurfaceClosure)
diff --git a/intern/cycles/kernel/svm/bsdf.h b/intern/cycles/kernel/svm/bsdf.h
index 18c1da73fbd..1a90eab0cd1 100644
--- a/intern/cycles/kernel/svm/bsdf.h
+++ b/intern/cycles/kernel/svm/bsdf.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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 __OSL_BSDF_H__
#define __OSL_BSDF_H__
@@ -47,7 +47,7 @@ __device float fresnel_dielectric(float eta, const float3 N,
float cos = dot(N, I), neta;
float3 Nn;
// compute reflection
- *R =(2 * cos)* N - I;
+ *R = (2 * cos)* N - I;
#ifdef __RAY_DIFFERENTIALS__
*dRdx = (2 * dot(N, dIdx)) * N - dIdx;
*dRdy = (2 * dot(N, dIdy)) * N - dIdy;
@@ -65,18 +65,18 @@ __device float fresnel_dielectric(float eta, const float3 N,
Nn = -N;
*is_inside = true;
}
- *R =(2 * cos)* Nn - I;
+ *R = (2 * cos)* Nn - I;
float arg = 1 -(neta * neta *(1 -(cos * cos)));
if(arg < 0) {
- *T= make_float3(0.0f, 0.0f, 0.0f);
+ *T = make_float3(0.0f, 0.0f, 0.0f);
#ifdef __RAY_DIFFERENTIALS__
- *dTdx= make_float3(0.0f, 0.0f, 0.0f);
- *dTdy= make_float3(0.0f, 0.0f, 0.0f);
+ *dTdx = make_float3(0.0f, 0.0f, 0.0f);
+ *dTdy = make_float3(0.0f, 0.0f, 0.0f);
#endif
return 1; // total internal reflection
} else {
float dnp = sqrtf(arg);
- float nK =(neta * cos)- dnp;
+ float nK = (neta * cos)- dnp;
*T = -(neta * I)+(nK * Nn);
#ifdef __RAY_DIFFERENTIALS__
*dTdx = -(neta * dIdx) + ((neta - neta * neta * cos / dnp) * dot(dIdx, Nn)) * Nn;
@@ -85,8 +85,8 @@ __device float fresnel_dielectric(float eta, const float3 N,
// compute Fresnel terms
float cosTheta1 = cos; // N.R
float cosTheta2 = -dot(Nn, *T);
- float pPara =(cosTheta1 - eta * cosTheta2)/(cosTheta1 + eta * cosTheta2);
- float pPerp =(eta * cosTheta1 - cosTheta2)/(eta * cosTheta1 + cosTheta2);
+ float pPara = (cosTheta1 - eta * cosTheta2)/(cosTheta1 + eta * cosTheta2);
+ float pPerp = (eta * cosTheta1 - cosTheta2)/(eta * cosTheta1 + cosTheta2);
return 0.5f * (pPara * pPara + pPerp * pPerp);
}
}
@@ -99,8 +99,8 @@ __device float fresnel_dielectric_cos(float cosi, float eta)
float g = eta * eta - 1 + c * c;
if(g > 0) {
g = sqrtf(g);
- float A =(g - c)/(g + c);
- float B =(c *(g + c)- 1)/(c *(g - c)+ 1);
+ float A = (g - c)/(g + c);
+ float B = (c *(g + c)- 1)/(c *(g - c)+ 1);
return 0.5f * A * A *(1 + B * B);
}
return 1.0f; // TIR(no refracted component)
@@ -110,10 +110,10 @@ __device float fresnel_conductor(float cosi, float eta, float k)
{
float tmp_f = eta * eta + k * k;
float tmp = tmp_f * cosi * cosi;
- float Rparl2 =(tmp -(2.0f * eta * cosi)+ 1)/
- (tmp +(2.0f * eta * cosi)+ 1);
- float Rperp2 =(tmp_f -(2.0f * eta * cosi)+ cosi * cosi)/
- (tmp_f +(2.0f * eta * cosi)+ cosi * cosi);
+ float Rparl2 = (tmp - (2.0f * eta * cosi) + 1)/
+ (tmp + (2.0f * eta * cosi) + 1);
+ float Rperp2 = (tmp_f - (2.0f * eta * cosi) + cosi * cosi)/
+ (tmp_f + (2.0f * eta * cosi) + cosi * cosi);
return(Rparl2 + Rperp2) * 0.5f;
}
diff --git a/intern/cycles/kernel/svm/bsdf_ashikhmin_velvet.h b/intern/cycles/kernel/svm/bsdf_ashikhmin_velvet.h
index 2e9343647b8..40249dbe9c6 100644
--- a/intern/cycles/kernel/svm/bsdf_ashikhmin_velvet.h
+++ b/intern/cycles/kernel/svm/bsdf_ashikhmin_velvet.h
@@ -28,7 +28,7 @@
* 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_ASHIKHMIN_VELVET_H__
#define __BSDF_ASHIKHMIN_VELVET_H__
diff --git a/intern/cycles/kernel/svm/bsdf_diffuse.h b/intern/cycles/kernel/svm/bsdf_diffuse.h
index e8a002cb84c..45e82a566c0 100644
--- a/intern/cycles/kernel/svm/bsdf_diffuse.h
+++ b/intern/cycles/kernel/svm/bsdf_diffuse.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_DIFFUSE_H__
#define __BSDF_DIFFUSE_H__
diff --git a/intern/cycles/kernel/svm/bsdf_microfacet.h b/intern/cycles/kernel/svm/bsdf_microfacet.h
index 8771578a2fd..01e3acb76e8 100644
--- a/intern/cycles/kernel/svm/bsdf_microfacet.h
+++ b/intern/cycles/kernel/svm/bsdf_microfacet.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_MICROFACET_H__
#define __BSDF_MICROFACET_H__
diff --git a/intern/cycles/kernel/svm/bsdf_reflection.h b/intern/cycles/kernel/svm/bsdf_reflection.h
index f00b72c4869..09b4e0e48f0 100644
--- a/intern/cycles/kernel/svm/bsdf_reflection.h
+++ b/intern/cycles/kernel/svm/bsdf_reflection.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_REFLECTION_H__
#define __BSDF_REFLECTION_H__
diff --git a/intern/cycles/kernel/svm/bsdf_refraction.h b/intern/cycles/kernel/svm/bsdf_refraction.h
index 07ef8633e0d..c9c268999c0 100644
--- a/intern/cycles/kernel/svm/bsdf_refraction.h
+++ b/intern/cycles/kernel/svm/bsdf_refraction.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_REFRACTION_H__
#define __BSDF_REFRACTION_H__
diff --git a/intern/cycles/kernel/svm/bsdf_transparent.h b/intern/cycles/kernel/svm/bsdf_transparent.h
index 4425c4bf104..511836cdfa2 100644
--- a/intern/cycles/kernel/svm/bsdf_transparent.h
+++ b/intern/cycles/kernel/svm/bsdf_transparent.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_TRANSPARENT_H__
#define __BSDF_TRANSPARENT_H__
diff --git a/intern/cycles/kernel/svm/bsdf_ward.h b/intern/cycles/kernel/svm/bsdf_ward.h
index d46baf099a6..86bca69425d 100644
--- a/intern/cycles/kernel/svm/bsdf_ward.h
+++ b/intern/cycles/kernel/svm/bsdf_ward.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_WARD_H__
#define __BSDF_WARD_H__
diff --git a/intern/cycles/kernel/svm/bsdf_westin.h b/intern/cycles/kernel/svm/bsdf_westin.h
index 21e5018c489..6193d81c244 100644
--- a/intern/cycles/kernel/svm/bsdf_westin.h
+++ b/intern/cycles/kernel/svm/bsdf_westin.h
@@ -1,34 +1,34 @@
-/*
- * 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.
-*/
+/*
+ * 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_WESTIN_H__
#define __BSDF_WESTIN_H__
diff --git a/intern/cycles/kernel/svm/emissive.h b/intern/cycles/kernel/svm/emissive.h
index e3f99e9b729..9a906f82963 100644
--- a/intern/cycles/kernel/svm/emissive.h
+++ b/intern/cycles/kernel/svm/emissive.h
@@ -1,47 +1,39 @@
-/*
- * 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.
-*/
+/*
+ * 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.
+ */
CCL_NAMESPACE_BEGIN
/* EMISSION CLOSURE */
-__device float3 emissive_eval(const float3 Ng, const float3 I)
-{
- float cosNO = fabsf(dot(Ng, I));
- float res = (cosNO > 0.0f)? 1.0f: 0.0f;
-
- return make_float3(res, res, res);
-}
-
/// Return the probability distribution function in the direction I,
/// given the parameters and the light's surface normal. This MUST match
/// the PDF computed by sample().
@@ -51,6 +43,13 @@ __device float emissive_pdf(const float3 Ng, const float3 I)
return (cosNO > 0.0f)? 1.0f: 0.0f;
}
+__device float3 emissive_eval(const float3 Ng, const float3 I)
+{
+ float res = emissive_pdf(Ng, I);
+
+ return make_float3(res, res, res);
+}
+
__device float3 svm_emissive_eval(ShaderData *sd, ShaderClosure *sc)
{
return emissive_eval(sd->Ng, sd->I);
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 6a05639beb9..8901e5e9628 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -269,6 +269,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
case NODE_OBJECT_INFO:
svm_node_object_info(kg, sd, stack, node.y, node.z);
break;
+ case NODE_PARTICLE_INFO:
+ svm_node_particle_info(kg, sd, stack, node.y, node.z);
+ break;
#endif
case NODE_CONVERT:
svm_node_convert(sd, stack, node.y, node.z, node.w);
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index 8409e83d94e..935504026ef 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -374,7 +374,7 @@ __device void svm_node_mix_closure(ShaderData *sd, float *stack,
{
#ifdef __MULTI_CLOSURE__
/* fetch weight from blend input, previous mix closures,
- and write to stack to be used by closure nodes later */
+ * and write to stack to be used by closure nodes later */
uint weight_offset, in_weight_offset, weight1_offset, weight2_offset;
decode_node_uchar4(node.y, &weight_offset, &in_weight_offset, &weight1_offset, &weight2_offset);
@@ -387,8 +387,8 @@ __device void svm_node_mix_closure(ShaderData *sd, float *stack,
stack_store_float(stack, weight2_offset, in_weight*weight);
#else
/* pick a closure and make the random number uniform over 0..1 again.
- closure 1 starts on the next node, for closure 2 the start is at an
- offset from the current node, so we jump */
+ * closure 1 starts on the next node, for closure 2 the start is at an
+ * offset from the current node, so we jump */
uint weight_offset = node.y;
uint node_jump = node.z;
float weight = stack_load_float(stack, weight_offset);
@@ -410,8 +410,8 @@ __device void svm_node_add_closure(ShaderData *sd, float *stack, uint unused,
/* nothing to do, handled in compiler */
#else
/* pick one of the two closures with probability 0.5. sampling quality
- is not going to be great, for that we'd need to evaluate the weights
- of the two closures being added */
+ * is not going to be great, for that we'd need to evaluate the weights
+ * of the two closures being added */
float weight = 0.5f;
if(*randb < weight) {
diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h
index dab19983946..88127b56474 100644
--- a/intern/cycles/kernel/svm/svm_geometry.h
+++ b/intern/cycles/kernel/svm/svm_geometry.h
@@ -94,5 +94,27 @@ __device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *sta
stack_store_float(stack, out_offset, data);
}
+/* Particle Info */
+
+__device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
+{
+ float data;
+
+ switch(type) {
+ case NODE_INFO_PAR_AGE: {
+ uint particle_id = object_particle_id(kg, sd->object);
+ data = particle_age(kg, particle_id);
+ stack_store_float(stack, out_offset, data);
+ break;
+ }
+ case NODE_INFO_PAR_LIFETIME: {
+ uint particle_id = object_particle_id(kg, sd->object);
+ data = particle_lifetime(kg, particle_id);
+ stack_store_float(stack, out_offset, data);
+ break;
+ }
+ }
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/kernel/svm/svm_gradient.h b/intern/cycles/kernel/svm/svm_gradient.h
index c7013800d6b..7fad1175c49 100644
--- a/intern/cycles/kernel/svm/svm_gradient.h
+++ b/intern/cycles/kernel/svm/svm_gradient.h
@@ -20,13 +20,13 @@ CCL_NAMESPACE_BEGIN
/* Gradient */
-__device float svm_gradient(float3 p, NodeBlendType type)
+__device float svm_gradient(float3 p, NodeGradientType type)
{
float x, y, z;
- x= p.x;
- y= p.y;
- z= p.z;
+ x = p.x;
+ y = p.y;
+ z = p.z;
if(type == NODE_BLEND_LINEAR) {
return x;
@@ -45,7 +45,7 @@ __device float svm_gradient(float3 p, NodeBlendType type)
return (x + y)/2.0f;
}
else if(type == NODE_BLEND_RADIAL) {
- return atan2(y, x)/(2.0f*M_PI_F) + 0.5f;
+ return atan2f(y, x) / (2.0f * M_PI_F) + 0.5f;
}
else {
float r = fmaxf(1.0f - sqrtf(x*x + y*y + z*z), 0.0f);
@@ -67,7 +67,7 @@ __device void svm_node_tex_gradient(ShaderData *sd, float *stack, uint4 node)
float3 co = stack_load_float3(stack, co_offset);
- float f = svm_gradient(co, (NodeBlendType)type);
+ float f = svm_gradient(co, (NodeGradientType)type);
f = clamp(f, 0.0f, 1.0f);
if(stack_valid(fac_offset))
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 388f006c40f..3b2b9204d86 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -92,13 +92,13 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y)
float4 r;
/* not particularly proud of this massive switch, what are the
- alternatives?
- - use a single big 1D texture, and do our own lookup/filtering
- - group by size and use a 3d texture, performance impact
- - group into larger texture with some padding for correct lerp
-
- also note that cuda has 128 textures limit, we use 100 now, since
- we still need some for other storage */
+ * alternatives?
+ * - use a single big 1D texture, and do our own lookup/filtering
+ * - group by size and use a 3d texture, performance impact
+ * - group into larger texture with some padding for correct lerp
+ *
+ * also note that cuda has 128 textures limit, we use 100 now, since
+ * we still need some for other storage */
switch(id) {
case 0: r = kernel_tex_image_interp(__tex_image_000, x, y); break;
diff --git a/intern/cycles/kernel/svm/svm_magic.h b/intern/cycles/kernel/svm/svm_magic.h
index 65d37937e1e..fdded813784 100644
--- a/intern/cycles/kernel/svm/svm_magic.h
+++ b/intern/cycles/kernel/svm/svm_magic.h
@@ -34,39 +34,39 @@ __device_noinline float3 svm_magic(float3 p, int n, float distortion)
y *= distortion;
if(n > 1) {
- x= cosf(x-y-z);
+ x = cosf(x-y-z);
x *= distortion;
if(n > 2) {
- z= sinf(-x-y-z);
+ z = sinf(-x-y-z);
z *= distortion;
if(n > 3) {
- x= -cosf(-x+y-z);
+ x = -cosf(-x+y-z);
x *= distortion;
if(n > 4) {
- y= -sinf(-x+y+z);
+ y = -sinf(-x+y+z);
y *= distortion;
if(n > 5) {
- y= -cosf(-x+y+z);
+ y = -cosf(-x+y+z);
y *= distortion;
if(n > 6) {
- x= cosf(x+y+z);
+ x = cosf(x+y+z);
x *= distortion;
if(n > 7) {
- z= sinf(x+y-z);
+ z = sinf(x+y-z);
z *= distortion;
if(n > 8) {
- x= -cosf(-x-y+z);
+ x = -cosf(-x-y+z);
x *= distortion;
if(n > 9) {
- y= -sinf(x-y+z);
+ y = -sinf(x-y+z);
y *= distortion;
}
}
diff --git a/intern/cycles/kernel/svm/svm_mix.h b/intern/cycles/kernel/svm/svm_mix.h
index e2274a2e691..6b455e713c2 100644
--- a/intern/cycles/kernel/svm/svm_mix.h
+++ b/intern/cycles/kernel/svm/svm_mix.h
@@ -248,8 +248,8 @@ __device float3 svm_mix_soft(float t, float3 col1, float3 col2)
{
float tm = 1.0f - t;
- float3 one= make_float3(1.0f, 1.0f, 1.0f);
- float3 scr= one - (one - col2)*(one - col1);
+ float3 one = make_float3(1.0f, 1.0f, 1.0f);
+ float3 scr = one - (one - col2)*(one - col1);
return tm*col1 + t*((one - col1)*col2*col1 + col1*scr);
}
@@ -259,19 +259,19 @@ __device float3 svm_mix_linear(float t, float3 col1, float3 col2)
float3 outcol = col1;
if(col2.x > 0.5f)
- outcol.x= col1.x + t*(2.0f*(col2.x - 0.5f));
+ outcol.x = col1.x + t*(2.0f*(col2.x - 0.5f));
else
- outcol.x= col1.x + t*(2.0f*(col2.x) - 1.0f);
+ outcol.x = col1.x + t*(2.0f*(col2.x) - 1.0f);
if(col2.y > 0.5f)
- outcol.y= col1.y + t*(2.0f*(col2.y - 0.5f));
+ outcol.y = col1.y + t*(2.0f*(col2.y - 0.5f));
else
- outcol.y= col1.y + t*(2.0f*(col2.y) - 1.0f);
+ outcol.y = col1.y + t*(2.0f*(col2.y) - 1.0f);
if(col2.z > 0.5f)
- outcol.z= col1.z + t*(2.0f*(col2.z - 0.5f));
+ outcol.z = col1.z + t*(2.0f*(col2.z - 0.5f));
else
- outcol.z= col1.z + t*(2.0f*(col2.z) - 1.0f);
+ outcol.z = col1.z + t*(2.0f*(col2.z) - 1.0f);
return outcol;
}
diff --git a/intern/cycles/kernel/svm/svm_musgrave.h b/intern/cycles/kernel/svm/svm_musgrave.h
index 9444dc20e6e..425909e59f1 100644
--- a/intern/cycles/kernel/svm/svm_musgrave.h
+++ b/intern/cycles/kernel/svm/svm_musgrave.h
@@ -41,7 +41,7 @@ __device_noinline float noise_musgrave_fBm(float3 p, NodeNoiseBasis basis, float
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ rmd = octaves - floorf(octaves);
if(rmd != 0.0f)
value += rmd * snoise(p) * pwr;
@@ -69,7 +69,7 @@ __device_noinline float noise_musgrave_multi_fractal(float3 p, NodeNoiseBasis ba
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ rmd = octaves - floorf(octaves);
if(rmd != 0.0f)
value *= (rmd * pwr * snoise(p) + 1.0f); /* correct? */
@@ -102,7 +102,7 @@ __device_noinline float noise_musgrave_hetero_terrain(float3 p, NodeNoiseBasis b
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ rmd = octaves - floorf(octaves);
if(rmd != 0.0f) {
increment = (snoise(p) + offset) * pwr * value;
value += rmd * increment;
@@ -141,7 +141,7 @@ __device_noinline float noise_musgrave_hybrid_multi_fractal(float3 p, NodeNoiseB
p *= lacunarity;
}
- rmd = octaves - floor(octaves);
+ rmd = octaves - floorf(octaves);
if(rmd != 0.0f)
result += rmd * ((snoise(p) + offset) * pwr);
diff --git a/intern/cycles/kernel/svm/svm_noise.h b/intern/cycles/kernel/svm/svm_noise.h
index 1d3ace061ab..dfaf43acbd4 100644
--- a/intern/cycles/kernel/svm/svm_noise.h
+++ b/intern/cycles/kernel/svm/svm_noise.h
@@ -28,7 +28,7 @@
* 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.
-*/
+ */
CCL_NAMESPACE_BEGIN
@@ -84,9 +84,9 @@ __device uint phash(int kx, int ky, int kz, int3 p)
__device float floorfrac(float x, int* i)
{
- float f = floorf(x);
- *i = (int)f;
- return x - f;
+ float f = floorf(x);
+ *i = (int)f;
+ return x - f;
}
__device float fade(float t)
@@ -96,7 +96,7 @@ __device float fade(float t)
__device float nerp(float t, float a, float b)
{
- return (1.0f - t) * a + t * b;
+ return (1.0f - t) * a + t * b;
}
__device float grad(int hash, float x, float y, float z)
diff --git a/intern/cycles/kernel/svm/svm_texture.h b/intern/cycles/kernel/svm/svm_texture.h
index 448132bff46..6c22d98e0df 100644
--- a/intern/cycles/kernel/svm/svm_texture.h
+++ b/intern/cycles/kernel/svm/svm_texture.h
@@ -152,7 +152,7 @@ __device float voronoi_CrS(float3 p) { return 2.0f*voronoi_Cr(p) - 1.0f; }
__device float noise_basis(float3 p, NodeNoiseBasis basis)
{
/* Only Perlin enabled for now, others break CUDA compile by making kernel
- too big, with compile using > 4GB, due to everything being inlined. */
+ * too big, with compile using > 4GB, due to everything being inlined. */
#if 0
if(basis == NODE_NOISE_PERLIN)
@@ -188,10 +188,10 @@ __device float noise_basis_hard(float3 p, NodeNoiseBasis basis, int hard)
/* Waves */
-__device float noise_wave(NodeWaveType wave, float a)
+__device float noise_wave(NodeWaveBasis wave, float a)
{
if(wave == NODE_WAVE_SINE) {
- return 0.5f + 0.5f*sin(a);
+ return 0.5f + 0.5f * sinf(a);
}
else if(wave == NODE_WAVE_SAW) {
float b = 2.0f*M_PI_F;
@@ -221,7 +221,7 @@ __device_noinline float noise_turbulence(float3 p, NodeNoiseBasis basis, float o
int i, n;
octaves = clamp(octaves, 0.0f, 16.0f);
- n= (int)octaves;
+ n = (int)octaves;
for(i = 0; i <= n; i++) {
float t = noise_basis(fscale*p, basis);
@@ -234,7 +234,7 @@ __device_noinline float noise_turbulence(float3 p, NodeNoiseBasis basis, float o
fscale *= 2.0f;
}
- float rmd = octaves - floor(octaves);
+ float rmd = octaves - floorf(octaves);
if(rmd != 0.0f) {
float t = noise_basis(fscale*p, basis);
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 97849736ef6..c1eeeb55268 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -30,70 +30,66 @@ CCL_NAMESPACE_BEGIN
/* Nodes */
-/* note that we do not simply use 0, 1, 2, .. as values for these. this works
- * around an obscure CUDA bug that happens when compiling for fermi. why it
- * happens i have no idea, but consecutive values are problematic, maybe it
- * generates an incorrect jump table. */
-
typedef enum NodeType {
NODE_END = 0,
- NODE_CLOSURE_BSDF = 100,
- NODE_CLOSURE_EMISSION = 200,
- NODE_CLOSURE_BACKGROUND = 300,
- NODE_CLOSURE_SET_WEIGHT = 400,
- NODE_CLOSURE_WEIGHT = 500,
- NODE_MIX_CLOSURE = 600,
- NODE_JUMP = 700,
- NODE_TEX_IMAGE = 1000,
- NODE_TEX_SKY = 1100,
- NODE_GEOMETRY = 1200,
- NODE_LIGHT_PATH = 1300,
- NODE_VALUE_F = 1400,
- NODE_VALUE_V = 1500,
- NODE_MIX = 1600,
- NODE_ATTR = 1700,
- NODE_CONVERT = 1900,
- NODE_FRESNEL = 2000,
- NODE_EMISSION_WEIGHT = 2100,
- NODE_TEX_GRADIENT = 2200,
- NODE_TEX_VORONOI = 2300,
- NODE_TEX_MUSGRAVE = 2400,
- NODE_TEX_WAVE = 2500,
- NODE_TEX_MAGIC = 2600,
- NODE_TEX_NOISE = 3000,
- NODE_SHADER_JUMP = 3100,
- NODE_SET_DISPLACEMENT = 3200,
- NODE_GEOMETRY_BUMP_DX = 3300,
- NODE_GEOMETRY_BUMP_DY = 3400,
- NODE_SET_BUMP = 3500,
- NODE_MATH = 3600,
- NODE_VECTOR_MATH = 3700,
- NODE_MAPPING = 3800,
- NODE_TEX_COORD = 3900,
- NODE_TEX_COORD_BUMP_DX = 4000,
- NODE_TEX_COORD_BUMP_DY = 4100,
- NODE_ADD_CLOSURE = 4200,
- NODE_EMISSION_SET_WEIGHT_TOTAL = 4300,
- NODE_ATTR_BUMP_DX = 4400,
- NODE_ATTR_BUMP_DY = 4500,
- NODE_TEX_ENVIRONMENT = 4600,
- NODE_CLOSURE_HOLDOUT = 4700,
- NODE_LAYER_WEIGHT = 4800,
- NODE_CLOSURE_VOLUME = 4900,
- NODE_SEPARATE_RGB = 5000,
- NODE_COMBINE_RGB = 5100,
- NODE_HSV = 5200,
- NODE_CAMERA = 5300,
- NODE_INVERT = 5400,
- NODE_NORMAL = 5500,
- NODE_GAMMA = 5600,
- NODE_TEX_CHECKER = 5700,
- NODE_BRIGHTCONTRAST = 5800,
- NODE_RGB_RAMP = 5900,
- NODE_RGB_CURVES = 6000,
- NODE_MIN_MAX = 6100,
- NODE_LIGHT_FALLOFF = 6200,
- NODE_OBJECT_INFO = 6300
+ NODE_CLOSURE_BSDF,
+ NODE_CLOSURE_EMISSION,
+ NODE_CLOSURE_BACKGROUND,
+ NODE_CLOSURE_SET_WEIGHT,
+ NODE_CLOSURE_WEIGHT,
+ NODE_MIX_CLOSURE,
+ NODE_JUMP,
+ NODE_TEX_IMAGE,
+ NODE_TEX_SKY,
+ NODE_GEOMETRY,
+ NODE_LIGHT_PATH,
+ NODE_VALUE_F,
+ NODE_VALUE_V,
+ NODE_MIX,
+ NODE_ATTR,
+ NODE_CONVERT,
+ NODE_FRESNEL,
+ NODE_EMISSION_WEIGHT,
+ NODE_TEX_GRADIENT,
+ NODE_TEX_VORONOI,
+ NODE_TEX_MUSGRAVE,
+ NODE_TEX_WAVE,
+ NODE_TEX_MAGIC,
+ NODE_TEX_NOISE,
+ NODE_SHADER_JUMP,
+ NODE_SET_DISPLACEMENT,
+ NODE_GEOMETRY_BUMP_DX,
+ NODE_GEOMETRY_BUMP_DY,
+ NODE_SET_BUMP,
+ NODE_MATH,
+ NODE_VECTOR_MATH,
+ NODE_MAPPING,
+ NODE_TEX_COORD,
+ NODE_TEX_COORD_BUMP_DX,
+ NODE_TEX_COORD_BUMP_DY,
+ NODE_ADD_CLOSURE,
+ NODE_EMISSION_SET_WEIGHT_TOTAL,
+ NODE_ATTR_BUMP_DX,
+ NODE_ATTR_BUMP_DY,
+ NODE_TEX_ENVIRONMENT,
+ NODE_CLOSURE_HOLDOUT,
+ NODE_LAYER_WEIGHT,
+ NODE_CLOSURE_VOLUME,
+ NODE_SEPARATE_RGB,
+ NODE_COMBINE_RGB,
+ NODE_HSV,
+ NODE_CAMERA,
+ NODE_INVERT,
+ NODE_NORMAL,
+ NODE_GAMMA,
+ NODE_TEX_CHECKER,
+ NODE_BRIGHTCONTRAST,
+ NODE_RGB_RAMP,
+ NODE_RGB_CURVES,
+ NODE_MIN_MAX,
+ NODE_LIGHT_FALLOFF,
+ NODE_OBJECT_INFO,
+ NODE_PARTICLE_INFO
} NodeType;
typedef enum NodeAttributeType {
@@ -117,6 +113,11 @@ typedef enum NodeObjectInfo {
NODE_INFO_OB_RANDOM
} NodeObjectInfo;
+typedef enum NodeParticleInfo {
+ NODE_INFO_PAR_AGE,
+ NODE_INFO_PAR_LIFETIME
+} NodeParticleInfo;
+
typedef enum NodeLightPath {
NODE_LP_camera = 0,
NODE_LP_shadow,
@@ -220,11 +221,11 @@ typedef enum NodeNoiseBasis {
NODE_NOISE_CELL_NOISE
} NodeNoiseBasis;
-typedef enum NodeWaveType {
+typedef enum NodeWaveBasis {
NODE_WAVE_SINE,
NODE_WAVE_SAW,
NODE_WAVE_TRI
-} NodeWaveType;
+} NodeWaveBasis;
typedef enum NodeMusgraveType {
NODE_MUSGRAVE_MULTIFRACTAL,
@@ -234,12 +235,12 @@ typedef enum NodeMusgraveType {
NODE_MUSGRAVE_HETERO_TERRAIN
} NodeMusgraveType;
-typedef enum NodeWoodType {
+typedef enum NodeWaveType {
NODE_WAVE_BANDS,
NODE_WAVE_RINGS
-} NodeWoodType;
+} NodeWaveType;
-typedef enum NodeBlendType {
+typedef enum NodeGradientType {
NODE_BLEND_LINEAR,
NODE_BLEND_QUADRATIC,
NODE_BLEND_EASING,
@@ -247,24 +248,7 @@ typedef enum NodeBlendType {
NODE_BLEND_RADIAL,
NODE_BLEND_QUADRATIC_SPHERE,
NODE_BLEND_SPHERICAL
-} NodeBlendType;
-
-typedef enum NodeBlendAxis {
- NODE_BLEND_HORIZONTAL,
- NODE_BLEND_VERTICAL
-} NodeBlendAxis;
-
-typedef enum NodeMarbleType {
- NODE_MARBLE_SOFT,
- NODE_MARBLE_SHARP,
- NODE_MARBLE_SHARPER
-} NodeMarbleType;
-
-typedef enum NodeStucciType {
- NODE_STUCCI_PLASTIC,
- NODE_STUCCI_WALL_IN,
- NODE_STUCCI_WALL_OUT
-} NodeStucciType;
+} NodeGradientType;
typedef enum NodeVoronoiColoring {
NODE_VORONOI_INTENSITY,
diff --git a/intern/cycles/kernel/svm/svm_voronoi.h b/intern/cycles/kernel/svm/svm_voronoi.h
index f5ee7851a51..7e7bd970320 100644
--- a/intern/cycles/kernel/svm/svm_voronoi.h
+++ b/intern/cycles/kernel/svm/svm_voronoi.h
@@ -38,7 +38,7 @@ __device_noinline float4 svm_voronoi(NodeVoronoiColoring coloring, float scale,
}
else {
color = cellnoise_color(pa[0]);
- fac= average(color);
+ fac = average(color);
}
return make_float4(color.x, color.y, color.z, fac);
diff --git a/intern/cycles/kernel/svm/svm_wave.h b/intern/cycles/kernel/svm/svm_wave.h
index 39edd7d9fff..d2d808e4063 100644
--- a/intern/cycles/kernel/svm/svm_wave.h
+++ b/intern/cycles/kernel/svm/svm_wave.h
@@ -18,18 +18,18 @@
CCL_NAMESPACE_BEGIN
-/* Marble */
+/* Wave */
-__device_noinline float svm_wave(NodeWoodType type, float3 p, float scale, float detail, float distortion, float dscale)
+__device_noinline float svm_wave(NodeWaveType type, float3 p, float scale, float detail, float distortion, float dscale)
{
float w, n;
p *= scale;
if(type == NODE_WAVE_BANDS)
- n= (p.x + p.y + p.z)*10.0f;
+ n = (p.x + p.y + p.z) * 10.0f;
else /* if(type == NODE_WAVE_RINGS) */
- n= len(p)*20.0f;
+ n = len(p) * 20.0f;
if(distortion != 0.0f)
n += distortion * noise_turbulence(p*dscale, NODE_NOISE_PERLIN, detail, 0);
@@ -55,7 +55,7 @@ __device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stack,
float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
float dscale = stack_load_float_default(stack, dscale_offset, node2.w);
- float f = svm_wave((NodeWoodType)type, co, scale, detail, distortion, dscale);
+ float f = svm_wave((NodeWaveType)type, co, scale, detail, distortion, dscale);
if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f);
if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, make_float3(f, f, f));
diff --git a/intern/cycles/kernel/svm/volume.h b/intern/cycles/kernel/svm/volume.h
index 86cb2dcc24e..10e9c5de352 100644
--- a/intern/cycles/kernel/svm/volume.h
+++ b/intern/cycles/kernel/svm/volume.h
@@ -19,7 +19,7 @@
CCL_NAMESPACE_BEGIN
/* note: the interfaces here are just as an example, need to figure
- out the right functions and parameters to use */
+ * out the right functions and parameters to use */
/* ISOTROPIC VOLUME CLOSURE */