From 17c82a7e5709705a96cb4c9d20715a6bc07d688c Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Wed, 17 Oct 2012 16:16:35 +0000 Subject: Cycles / OSL: * Layer Weight is now available in OSL. --- intern/cycles/kernel/osl/nodes/CMakeLists.txt | 1 + .../cycles/kernel/osl/nodes/node_blend_weight.osl | 42 ------------------- .../cycles/kernel/osl/nodes/node_layer_weight.osl | 47 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 42 deletions(-) delete mode 100644 intern/cycles/kernel/osl/nodes/node_blend_weight.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_layer_weight.osl (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index cb965ac1530..65b8504ce43 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -29,6 +29,7 @@ set(SRC_OSL node_hsv.osl node_image_texture.osl node_invert.osl + node_layer_weight.osl node_light_path.osl node_light_falloff.osl node_magic_texture.osl diff --git a/intern/cycles/kernel/osl/nodes/node_blend_weight.osl b/intern/cycles/kernel/osl/nodes/node_blend_weight.osl deleted file mode 100644 index 836897fc5e3..00000000000 --- a/intern/cycles/kernel/osl/nodes/node_blend_weight.osl +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * 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. - */ - -#include "stdosl.h" -#include "node_fresnel.h" - -shader node_blend_weight( - float Blend = 0.3, - normal Normal = N, - output float Fresnel = 0.0, - output float Facing = 0.0) -{ - float f = max(1.0 - Blend, 1e-5); - Fresnel = fresnel_dielectric(I, Normal, backfacing()? f: 1.0 / f); - - Facing = abs(dot(I, Normal)); - - if (Blend != 0.5) { - Blend = clamp(Blend, 0.0, 1.0); - Blend = (Blend < 0.5)? 2.0 * Blend: 0.5 / (1.0 - Blend); - - Facing = powf(Facing, Blend); - } - - Facing = 1.0 - Facing; -} - diff --git a/intern/cycles/kernel/osl/nodes/node_layer_weight.osl b/intern/cycles/kernel/osl/nodes/node_layer_weight.osl new file mode 100644 index 00000000000..ea25d0c0e02 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_layer_weight.osl @@ -0,0 +1,47 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + */ + +#include "stdosl.h" +#include "node_fresnel.h" + +shader node_layer_weight( + float Blend = 0.5, + normal Normal = N, + output float Fresnel = 0.0, + output float Facing = 0.0) +{ + float blend = Blend; + + /* Fresnel */ + float eta = max(1.0 - Blend, 1e-5); + eta = backfacing()? eta: 1.0 / eta; + Fresnel = fresnel_dielectric(I, Normal, eta); + + /* Facing */ + Facing = abs(dot(I, Normal)); + + if (blend != 0.5) { + blend = clamp(blend, 0.0, 1.0); + blend = (blend < 0.5)? 2.0 * blend: 0.5 / (1.0 - blend); + + Facing = pow(Facing, blend); + } + + Facing = 1.0 - Facing; +} + -- cgit v1.2.3