From da376e0237517543aa21740ee2363234ee1c20ae Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Wed, 27 Apr 2011 11:58:34 +0000 Subject: Cycles render engine, initial commit. This is the engine itself, blender modifications and build instructions will follow later. Cycles uses code from some great open source projects, many thanks them: * BVH building and traversal code from NVidia's "Understanding the Efficiency of Ray Traversal on GPUs": http://code.google.com/p/understanding-the-efficiency-of-ray-traversal-on-gpus/ * Open Shading Language for a large part of the shading system: http://code.google.com/p/openshadinglanguage/ * Blender for procedural textures and a few other nodes. * Approximate Catmull Clark subdivision from NVidia Mesh tools: http://code.google.com/p/nvidia-mesh-tools/ * Sobol direction vectors from: http://web.maths.unsw.edu.au/~fkuo/sobol/ * Film response functions from: http://www.cs.columbia.edu/CAVE/software/softlib/dorf.php --- intern/cycles/kernel/osl/nodes/CMakeLists.txt | 69 +++ .../cycles/kernel/osl/nodes/node_add_closure.osl | 28 ++ intern/cycles/kernel/osl/nodes/node_attribute.osl | 43 ++ intern/cycles/kernel/osl/nodes/node_background.osl | 28 ++ .../cycles/kernel/osl/nodes/node_blend_texture.osl | 78 ++++ intern/cycles/kernel/osl/nodes/node_bump.osl | 46 ++ .../kernel/osl/nodes/node_clouds_texture.osl | 42 ++ .../kernel/osl/nodes/node_convert_from_color.osl | 33 ++ .../kernel/osl/nodes/node_convert_from_float.osl | 33 ++ .../kernel/osl/nodes/node_convert_from_normal.osl | 33 ++ .../kernel/osl/nodes/node_convert_from_point.osl | 33 ++ .../kernel/osl/nodes/node_convert_from_vector.osl | 33 ++ .../cycles/kernel/osl/nodes/node_diffuse_bsdf.osl | 28 ++ .../osl/nodes/node_distorted_noise_texture.osl | 46 ++ intern/cycles/kernel/osl/nodes/node_emission.osl | 32 ++ .../kernel/osl/nodes/node_environment_texture.osl | 28 ++ intern/cycles/kernel/osl/nodes/node_fresnel.h | 21 + intern/cycles/kernel/osl/nodes/node_fresnel.osl | 30 ++ intern/cycles/kernel/osl/nodes/node_geometry.osl | 50 +++ intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl | 41 ++ .../cycles/kernel/osl/nodes/node_glossy_bsdf.osl | 45 ++ .../cycles/kernel/osl/nodes/node_image_texture.osl | 28 ++ intern/cycles/kernel/osl/nodes/node_light_path.osl | 36 ++ .../cycles/kernel/osl/nodes/node_magic_texture.osl | 103 +++++ intern/cycles/kernel/osl/nodes/node_mapping.osl | 28 ++ .../kernel/osl/nodes/node_marble_texture.osl | 58 +++ intern/cycles/kernel/osl/nodes/node_math.osl | 84 ++++ intern/cycles/kernel/osl/nodes/node_mix.osl | 388 +++++++++++++++++ .../cycles/kernel/osl/nodes/node_mix_closure.osl | 30 ++ .../kernel/osl/nodes/node_musgrave_texture.osl | 218 ++++++++++ .../cycles/kernel/osl/nodes/node_noise_texture.osl | 36 ++ .../kernel/osl/nodes/node_output_displacement.osl | 25 ++ .../kernel/osl/nodes/node_output_surface.osl | 25 ++ .../cycles/kernel/osl/nodes/node_output_volume.osl | 25 ++ .../cycles/kernel/osl/nodes/node_sky_texture.osl | 162 +++++++ .../kernel/osl/nodes/node_stucci_texture.osl | 49 +++ intern/cycles/kernel/osl/nodes/node_texture.h | 251 +++++++++++ .../kernel/osl/nodes/node_texture_coordinate.osl | 66 +++ .../kernel/osl/nodes/node_translucent_bsdf.osl | 28 ++ .../kernel/osl/nodes/node_transparent_bsdf.osl | 28 ++ intern/cycles/kernel/osl/nodes/node_value.osl | 33 ++ .../cycles/kernel/osl/nodes/node_vector_math.osl | 53 +++ .../cycles/kernel/osl/nodes/node_velvet_bsdf.osl | 40 ++ .../kernel/osl/nodes/node_voronoi_texture.osl | 82 ++++ intern/cycles/kernel/osl/nodes/node_ward_bsdf.osl | 30 ++ .../cycles/kernel/osl/nodes/node_wood_texture.osl | 63 +++ intern/cycles/kernel/osl/nodes/stdosl.h | 471 +++++++++++++++++++++ 47 files changed, 3260 insertions(+) create mode 100644 intern/cycles/kernel/osl/nodes/CMakeLists.txt create mode 100644 intern/cycles/kernel/osl/nodes/node_add_closure.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_attribute.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_background.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_blend_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_bump.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_clouds_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_convert_from_color.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_convert_from_float.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_convert_from_point.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_diffuse_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_distorted_noise_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_emission.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_environment_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_fresnel.h create mode 100644 intern/cycles/kernel/osl/nodes/node_fresnel.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_geometry.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_image_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_light_path.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_magic_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_mapping.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_marble_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_math.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_mix.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_mix_closure.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_noise_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_output_displacement.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_output_surface.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_output_volume.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_sky_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_stucci_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_texture.h create mode 100644 intern/cycles/kernel/osl/nodes/node_texture_coordinate.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_translucent_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_transparent_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_value.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_vector_math.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_ward_bsdf.osl create mode 100644 intern/cycles/kernel/osl/nodes/node_wood_texture.osl create mode 100644 intern/cycles/kernel/osl/nodes/stdosl.h (limited to 'intern/cycles/kernel/osl/nodes') diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt new file mode 100644 index 00000000000..435acc5f680 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -0,0 +1,69 @@ + +# OSL node shaders + +SET(osl_sources + node_add_closure.osl + node_attribute.osl + node_background.osl + node_blend_texture.osl + node_bump.osl + node_clouds_texture.osl + node_convert_from_color.osl + node_convert_from_float.osl + node_convert_from_normal.osl + node_convert_from_point.osl + node_convert_from_vector.osl + node_diffuse_bsdf.osl + node_distorted_noise_texture.osl + node_emission.osl + node_environment_texture.osl + node_fresnel.osl + node_geometry.osl + node_glass_bsdf.osl + node_glossy_bsdf.osl + node_image_texture.osl + node_light_path.osl + node_magic_texture.osl + node_mapping.osl + node_marble_texture.osl + node_math.osl + node_mix.osl + node_mix_closure.osl + node_musgrave_texture.osl + node_noise_texture.osl + node_output_displacement.osl + node_output_surface.osl + node_output_volume.osl + node_sky_texture.osl + node_stucci_texture.osl + node_texture_coordinate.osl + node_translucent_bsdf.osl + node_transparent_bsdf.osl + node_value.osl + node_vector_math.osl + node_velvet_bsdf.osl + node_voronoi_texture.osl + node_ward_bsdf.osl + node_wood_texture.osl) + +SET(osl_headers + node_texture.h + stdosl.h) + +SET(oso_sources) + +FOREACH(_file ${osl_sources}) + SET(osl_file ${CMAKE_CURRENT_SOURCE_DIR}/${_file}) + STRING(REPLACE ".osl" ".oso" oso_file ${osl_file}) + STRING(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} oso_file ${oso_file}) + ADD_CUSTOM_COMMAND( + OUTPUT ${oso_file} + COMMAND ${OSL_COMPILER} -O2 ${osl_file} + DEPENDS ${osl_file} ${osl_headers}) + LIST(APPEND oso_sources ${oso_file}) +ENDFOREACH() + +ADD_CUSTOM_TARGET(shader ALL DEPENDS ${oso_sources} ${osl_headers}) + +INSTALL(FILES ${oso_sources} DESTINATION ${INSTALL_PATH}/cycles/shader) + diff --git a/intern/cycles/kernel/osl/nodes/node_add_closure.osl b/intern/cycles/kernel/osl/nodes/node_add_closure.osl new file mode 100644 index 00000000000..ecf6bf5912e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_add_closure.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_add_closure( + closure color Closure1 = background(), + closure color Closure2 = background(), + output closure color Closure = background()) +{ + Closure = Closure1 + Closure2; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_attribute.osl b/intern/cycles/kernel/osl/nodes/node_attribute.osl new file mode 100644 index 00000000000..d273d0c68d7 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_attribute.osl @@ -0,0 +1,43 @@ +/* + * 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" + +shader node_attribute( + string bump_offset = "center", + string name = "", + output point Vector = point(0.0, 0.0, 0.0), + output color Color = color(0.0, 0.0, 0.0), + output float Fac = 0.0) +{ + getattribute(name, Color); + Vector = point(Color); + getattribute(name, Fac); + + if(bump_offset == "dx") { + Color += Dx(Color); + Vector += Dx(Vector); + Fac += Dx(Fac); + } + else if(bump_offset == "dy") { + Color += Dy(Color); + Vector += Dy(Vector); + Fac += Dy(Fac); + } +} + diff --git a/intern/cycles/kernel/osl/nodes/node_background.osl b/intern/cycles/kernel/osl/nodes/node_background.osl new file mode 100644 index 00000000000..69f8d85a82e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_background.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_background( + color Color = color(0.8, 0.8, 0.8), + float Strength = 1.0, + output closure color Background = background()) +{ + Background = Color*Strength*background(); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_blend_texture.osl b/intern/cycles/kernel/osl/nodes/node_blend_texture.osl new file mode 100644 index 00000000000..de1bdaca90b --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_blend_texture.osl @@ -0,0 +1,78 @@ +/* + * 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_texture.h" + +/* Blend */ + +float blend(point p, string progression, string axis) +{ + float x, y; + + if(axis == "Vertical") { + x= p[1]; + y= p[0]; + } + else { + x= p[0]; + y= p[1]; + } + + float result = 0.0; + + if(progression == "Linear") { + result = (1.0 + x)/2.0; + } + else if(progression == "Quadratic") { + float r = max((1.0 + x)/2.0, 0.0); + result = r*r; + } + else if(progression == "Easing") { + float r = min(max((1.0 + x)/2.0, 0.0), 1.0); + float t = r*r; + + result = (3.0*t - 2.0*t*r); + } + else if(progression == "Diagonal") { + result = (2.0 + x + y)/4.0; + } + else if(progression == "Radial") { + result = atan2(y, x)/(2*M_PI) + 0.5; + } + else { + float r = max(1.0 - sqrt(x*x + y*y + p[2]*p[2]), 0.0); + + if(progression == "Quadratic Sphere") + result = r*r; + else if(progression == "Spherical") + result = r; + } + + return result; +} + +shader node_blend_texture( + string Progression = "Linear", + string Axis = "Horizontal", + point Vector = P, + output float Fac = 0.0) +{ + Fac = blend(Vector, Progression, Axis); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_bump.osl b/intern/cycles/kernel/osl/nodes/node_bump.osl new file mode 100644 index 00000000000..a3849e70f98 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_bump.osl @@ -0,0 +1,46 @@ +/* + * 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" + +/* "Bump Mapping Unparametrized Surfaces on the GPU" + * Morten S. Mikkelsen, 2010 */ + +surface node_bump( + float SampleCenter = 0.0, + float SampleX = 0.0, + float SampleY = 0.0, + output normal Normal = N) +{ + float dx = SampleX - SampleCenter; + float dy = SampleY - SampleCenter; + + vector dPdx = Dx(P); + vector dPdy = Dy(P); + + vector Rx = cross(dPdy, N); + vector Ry = cross(N, dPdx); + + float det = dot(dPdx, Rx); + vector surfgrad = dx*Rx + dy*Ry; + + surfgrad *= 0.1; /* todo: remove this factor */ + + Normal = normalize(abs(det)*N - sign(det)*surfgrad); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_clouds_texture.osl b/intern/cycles/kernel/osl/nodes/node_clouds_texture.osl new file mode 100644 index 00000000000..6d244d81e27 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_clouds_texture.osl @@ -0,0 +1,42 @@ +/* + * 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_texture.h" + +/* Turbulence */ + +shader node_clouds_texture( + string Basis = "Perlin", + int Hard = 0, + int Depth = 2, + float Size = 0.25, + point Vector = P, + output float Fac = 0.0, + output color Color = color(0.0, 0.0, 0.0)) +{ + float size = nonzero(Size, 1e-5); + point p = Vector/size; + + Fac = noise_turbulence(p, Basis, Depth, Hard); + + Color[0] = Fac; + Color[1] = noise_turbulence(point(p[1], p[0], p[2]), Basis, Depth, Hard); + Color[2] = noise_turbulence(point(p[1], p[2], p[0]), Basis, Depth, Hard); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl new file mode 100644 index 00000000000..97356139c48 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_convert_from_color( + color Color = color(0.0, 0.0, 0.0), + output float Val = 0.0, + output vector Vector = vector(0.0, 0.0, 0.0), + output point Point = point(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0)) +{ + Val = Color[0]*0.2126 + Color[1]*0.7152 + Color[2]*0.0722; + Vector = vector(Color[0], Color[1], Color[2]); + Point = point(Color[0], Color[1], Color[2]); + Normal = normal(Color[0], Color[1], Color[2]); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl new file mode 100644 index 00000000000..00e78f3bab4 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_convert_from_float( + float Val = 0.0, + output color Color = color(0.0, 0.0, 0.0), + output vector Vector = vector(0.0, 0.0, 0.0), + output point Point = point(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0)) +{ + Color = color(Val, Val, Val); + Vector = vector(Val, Val, Val); + Point = point(Val, Val, Val); + Normal = normal(Val, Val, Val); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl new file mode 100644 index 00000000000..0bb9092591d --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_convert_from_normal( + normal Normal = normal(0.0, 0.0, 0.0), + output float Val = 0.0, + output vector Vector = vector(0.0, 0.0, 0.0), + output color Color = color(0.0, 0.0, 0.0), + output point Point = point(0.0, 0.0, 0.0)) +{ + Val = (Normal[0] + Normal[1] + Normal[2])*(1.0/3.0); + Vector = vector(Normal[0], Normal[1], Normal[2]); + Color = color(Normal[0], Normal[1], Normal[2]); + Point = point(Normal[0], Normal[1], Normal[2]); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl new file mode 100644 index 00000000000..e66d6a864d6 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_convert_from_point( + point Point = point(0.0, 0.0, 0.0), + output float Val = 0.0, + output vector Vector = vector(0.0, 0.0, 0.0), + output color Color = color(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0)) +{ + Val = (Point[0] + Point[1] + Point[2])*(1.0/3.0); + Vector = vector(Point[0], Point[1], Point[2]); + Color = color(Point[0], Point[1], Point[2]); + Normal = normal(Point[0], Point[1], Point[2]); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl new file mode 100644 index 00000000000..37ba9582cad --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_convert_from_vector( + vector Vector = vector(0.0, 0.0, 0.0), + output float Val = 0.0, + output color Color = color(0.0, 0.0, 0.0), + output point Point = point(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0)) +{ + Val = (Vector[0] + Vector[1] + Vector[2])*(1.0/3.0); + Color = color(Vector[0], Vector[1], Vector[2]); + Point = point(Vector[0], Vector[1], Vector[2]); + Normal = normal(Vector[0], Vector[1], Vector[2]); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_diffuse_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_diffuse_bsdf.osl new file mode 100644 index 00000000000..8cf161c17cc --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_diffuse_bsdf.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_diffuse_bsdf( + color Color = color(0.8, 0.8, 0.8), + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + BSDF = Color*diffuse(Normal); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_distorted_noise_texture.osl b/intern/cycles/kernel/osl/nodes/node_distorted_noise_texture.osl new file mode 100644 index 00000000000..bb338c4ef0f --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_distorted_noise_texture.osl @@ -0,0 +1,46 @@ +/* + * 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_texture.h" + +/* Distorted Noise (variable lacunarity noise) */ + +float noise_distorted(point p, string basis, string distortion_basis, float distortion) +{ + point r; + + r[0] = noise_basis(p + point(13.5), basis) * distortion; + r[1] = noise_basis(p, basis) * distortion; + r[2] = noise_basis(p - point(13.5), basis) * distortion; + + return noise_basis(p + r, distortion_basis); /* distorted-domain noise */ +} + +shader node_distorted_noise_texture( + string Basis = "Perlin", + string DistortionBasis = "Perlin", + float Distortion = 1.0, + float Size = 0.25, + point Vector = P, + output float Fac = 0.0) +{ + float size = nonzero(Size, 1e-5); + Fac = noise_distorted(Vector/size, Basis, DistortionBasis, Distortion); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_emission.osl b/intern/cycles/kernel/osl/nodes/node_emission.osl new file mode 100644 index 00000000000..8bfd1af173a --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_emission.osl @@ -0,0 +1,32 @@ +/* + * 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" + +shader node_emission( + int TotalPower = 0, + color Color = color(0.8, 0.8, 0.8), + float Strength = 1.0, + output closure color Emission = emission()) +{ + if(TotalPower) + Emission = ((Strength/surfacearea())*Color)*emission(); + else + Emission = (Strength*Color)*emission(); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_environment_texture.osl b/intern/cycles/kernel/osl/nodes/node_environment_texture.osl new file mode 100644 index 00000000000..569b22d53ec --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_environment_texture.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_environment_texture( + vector Vector = P, + string filename = "", + output color Color = color(0.0, 0.0, 0.0)) +{ + Color = (color)environment(filename, Vector); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_fresnel.h b/intern/cycles/kernel/osl/nodes/node_fresnel.h new file mode 100644 index 00000000000..0c8a5276ede --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_fresnel.h @@ -0,0 +1,21 @@ + +float fresnel_dielectric(vector Incoming, normal Normal, float eta) +{ + /* compute fresnel reflectance without explicitly computing + the refracted direction */ + float c = fabs(dot(Incoming, Normal)); + float g = eta * eta - 1 + c * c; + float result; + + 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); + } + else + result = 1.0; /* TIR (no refracted component) */ + + return result; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_fresnel.osl b/intern/cycles/kernel/osl/nodes/node_fresnel.osl new file mode 100644 index 00000000000..ddc86db130f --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_fresnel.osl @@ -0,0 +1,30 @@ +/* + * 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_fresnel( + float Fresnel = 0.3, + normal Normal = N, + output float Fac = 0.0) +{ + float f = max(1.0 - Fresnel, 0.00001); + Fac = fresnel_dielectric(I, Normal, backfacing()? f: 1.0/f); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_geometry.osl b/intern/cycles/kernel/osl/nodes/node_geometry.osl new file mode 100644 index 00000000000..bf76e2e597a --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_geometry.osl @@ -0,0 +1,50 @@ +/* + * 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" + +shader node_geometry( + normal NormalIn = N, + string bump_offset = "center", + + output point Position = point(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0), + output normal Tangent = normal(0.0, 0.0, 0.0), + output normal TrueNormal = normal(0.0, 0.0, 0.0), + output vector Incoming = vector(0.0, 0.0, 0.0), + output point UV = point(0.0, 0.0, 0.0), + output float Backfacing = 0.0) +{ + Position = P; + Normal = NormalIn; + Tangent = normalize(dPdu); + TrueNormal = Ng; + Incoming = I; + UV = point(u, v, 0.0); + Backfacing = backfacing(); + + if(bump_offset == "dx") { + Position += Dx(Position); + UV += Dx(UV); + } + else if(bump_offset == "dy") { + Position += Dy(Position); + UV += Dy(UV); + } +} + diff --git a/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl new file mode 100644 index 00000000000..af946048011 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_glass_bsdf.osl @@ -0,0 +1,41 @@ +/* + * 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_glass_bsdf( + color Color = color(0.8, 0.8, 0.8), + string distribution = "Sharp", + float Roughness = 0.2, + float Fresnel = 0.3, + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + float f = clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); + float eta = backfacing()? f: 1.0/f; + float Fr = fresnel_dielectric(I, Normal, eta); + + if(distribution == "Sharp") + BSDF = Color*(Fr*reflection(Normal) + (1.0-Fr)*refraction(Normal, eta)); + else if(distribution == "Beckmann") + BSDF = Color*(Fr*microfacet_beckmann(Normal, Roughness) + (1.0-Fr)*microfacet_beckmann_refraction(Normal, Roughness, eta)); + else if(distribution == "GGX") + BSDF = Color*(Fr*microfacet_ggx(Normal, Roughness) + (1.0-Fr)*microfacet_ggx_refraction(Normal, Roughness, eta)); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl new file mode 100644 index 00000000000..ca6bee74b38 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_glossy_bsdf.osl @@ -0,0 +1,45 @@ +/* + * 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_glossy_bsdf( + color Color = color(0.8, 0.8, 0.8), + string distribution = "Beckmann", + float Roughness = 0.2, + float Fresnel = 1.0, + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + float Fr = 1.0; + + if(Fresnel < 1.0) { + float eta = 1.0/clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); + Fr = fresnel_dielectric(I, Normal, eta); + } + + if(distribution == "Sharp") + BSDF = (Fr*Color)*reflection(Normal); + else if(distribution == "Beckmann") + BSDF = (Fr*Color)*microfacet_beckmann(Normal, Roughness); + else if(distribution == "GGX") + BSDF = (Fr*Color)*microfacet_ggx(Normal, Roughness); + +} + diff --git a/intern/cycles/kernel/osl/nodes/node_image_texture.osl b/intern/cycles/kernel/osl/nodes/node_image_texture.osl new file mode 100644 index 00000000000..0dbcc122deb --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_image_texture.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_image_texture( + point Vector = P, + string filename = "", + output color Color = color(0.0, 0.0, 0.0)) +{ + Color = (color)texture(filename, Vector[0], 1.0-Vector[1], "wrap", "periodic"); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_light_path.osl b/intern/cycles/kernel/osl/nodes/node_light_path.osl new file mode 100644 index 00000000000..081640428ab --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_light_path.osl @@ -0,0 +1,36 @@ +/* + * 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" + +shader node_light_path( + output float IsCameraRay = 0.0, + output float IsShadowRay = 0.0, + output float IsDiffuseRay = 0.0, + output float IsGlossyRay = 0.0, + output float IsReflectionRay = 0.0, + output float IsTransmissionRay = 0.0) +{ + IsCameraRay = raytype("camera"); + IsShadowRay = raytype("shadow"); + IsDiffuseRay = raytype("diffuse"); + IsGlossyRay = raytype("glossy"); + IsReflectionRay = raytype("reflection"); + IsTransmissionRay = raytype("refraction"); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_magic_texture.osl b/intern/cycles/kernel/osl/nodes/node_magic_texture.osl new file mode 100644 index 00000000000..0b6e980debc --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_magic_texture.osl @@ -0,0 +1,103 @@ +/* + * 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_texture.h" + +/* Magic */ + +color magic(point p, int n, float turbulence) +{ + float turb = turbulence/5.0; + + float x = sin((p[0] + p[1] + p[2])*5.0); + float y = cos((-p[0] + p[1] - p[2])*5.0); + float z = -cos((-p[0] - p[1] + p[2])*5.0); + + if(n > 0) { + x *= turb; + y *= turb; + z *= turb; + y = -cos(x-y+z); + y *= turb; + + if(n > 1) { + x= cos(x-y-z); + x *= turb; + + if(n > 2) { + z= sin(-x-y-z); + z *= turb; + + if(n > 3) { + x= -cos(-x+y-z); + x *= turb; + + if(n > 4) { + y= -sin(-x+y+z); + y *= turb; + + if(n > 5) { + y= -cos(-x+y+z); + y *= turb; + + if(n > 6) { + x= cos(x+y+z); + x *= turb; + + if(n > 7) { + z= sin(x+y-z); + z *= turb; + + if(n > 8) { + x= -cos(-x-y+z); + x *= turb; + + if(n > 9) { + y= -sin(x-y+z); + y *= turb; + } + } + } + } + } + } + } + } + } + } + + if(turb != 0.0) { + turb *= 2.0; + x /= turb; + y /= turb; + z /= turb; + } + + return color(0.5 - x, 0.5 - y, 0.5 - z); +} + +shader node_magic_texture( + int Depth = 2, + float Turbulence = 5.0, + point Vector = P, + output color Color = color(0.0, 0.0, 0.0)) +{ + Color = magic(Vector, Depth, Turbulence); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_mapping.osl b/intern/cycles/kernel/osl/nodes/node_mapping.osl new file mode 100644 index 00000000000..f342837d3c9 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_mapping.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_mapping( + matrix Matrix = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), + point Vector = point(0.0, 0.0, 0.0), + output point Vector_ = point(0.0, 0.0, 0.0)) +{ + Vector_ = transform(Matrix, Vector); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_marble_texture.osl b/intern/cycles/kernel/osl/nodes/node_marble_texture.osl new file mode 100644 index 00000000000..9e18dee3235 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_marble_texture.osl @@ -0,0 +1,58 @@ +/* + * 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_texture.h" + +/* Marble */ + +float marble(point p, float size, string type, string wave, string basis, int hard, float turb, int depth) +{ + float x = p[0]; + float y = p[1]; + float z = p[2]; + + float n = 5.0 * (x + y + z); + + float mi = n + turb * noise_turbulence(p/size, basis, depth, hard); + + mi = noise_wave(wave, mi); + + if(type == "Sharp") + mi = sqrt(mi); + else if(type == "Sharper") + mi = sqrt(sqrt(mi)); + + return mi; +} + +shader node_marble_texture( + string Type = "Soft", + string Wave = "Sine", + string Basis = "Perlin", + int Hard = 0, + float Size = 0.25, + float Turbulence = 5.0, + int Depth = 2, + point Vector = P, + output float Fac = 0.0) +{ + float size = nonzero(Size, 1e-5); + Fac = marble(Vector, size, Type, Wave, Basis, Hard, Turbulence, Depth); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_math.osl b/intern/cycles/kernel/osl/nodes/node_math.osl new file mode 100644 index 00000000000..be9bb71d511 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_math.osl @@ -0,0 +1,84 @@ +/* + * 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" + +float safe_divide(float a, float b) +{ + float result; + + if(b == 0.0) + result = 0.0; + else + result = a/b; + + return result; +} + +float safe_log(float a, float b) +{ + if(a < 0.0 || b < 0.0) + return 0.0; + + return log(a)/log(b); +} + +shader node_math( + string type = "Add", + float Value1 = 0.0, + float Value2 = 0.0, + output float Value = 0.0) +{ + /* OSL asin, acos, pow check for values that could give rise to nan */ + + if(type == "Add") + Value = Value1 + Value2; + if(type == "Subtract") + Value = Value1 - Value2; + if(type == "Multiply") + Value = Value1*Value2; + if(type == "Divide") + Value = safe_divide(Value1, Value2); + if(type == "Sine") + Value = sin(Value1); + if(type == "Cosine") + Value = cos(Value1); + if(type == "Tangent") + Value = tan(Value1); + if(type == "Arcsine") + Value = asin(Value1); + if(type == "Arccosine") + Value = acos(Value1); + if(type == "Arctangent") + Value = atan(Value1); + if(type == "Power") + Value = pow(Value1, Value2); + if(type == "Logarithm") + Value = safe_log(Value1, Value2); + if(type == "Minimum") + Value = min(Value1, Value2); + if(type == "Maximum") + Value = max(Value1, Value2); + if(type == "Round") + Value = floor(Value1 + 0.5); + if(type == "Less Than") + Value = Value1 < Value2; + if(type == "Greater Than") + Value = Value1 > Value2; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_mix.osl b/intern/cycles/kernel/osl/nodes/node_mix.osl new file mode 100644 index 00000000000..582aa7b3c60 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_mix.osl @@ -0,0 +1,388 @@ +/* + * 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" + +color rgb_to_hsv(color rgb) +{ + float cmax, cmin, h, s, v, cdelta; + color c; + + cmax = max(rgb[0], max(rgb[1], rgb[2])); + cmin = min(rgb[0], min(rgb[1], rgb[2])); + cdelta = cmax - cmin; + + v = cmax; + + if(cmax != 0.0) { + s = cdelta/cmax; + } + else { + s = 0.0; + h = 0.0; + } + + if(s == 0.0) { + h = 0.0; + } + else { + 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]; + else h = 4.0 + c[1] - c[0]; + + h /= 6.0; + + if(h < 0.0) + h += 1.0; + } + + return color(h, s, v); +} + +color hsv_to_rgb(color hsv) +{ + float i, f, p, q, t, h, s, v; + color rgb; + + h = hsv[0]; + s = hsv[1]; + v = hsv[2]; + + if(s==0.0) { + rgb = color(v, v, v); + } + else { + 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); + else rgb = color(v, p, q); + } + + return rgb; +} + +color node_mix_blend(float t, color col1, color col2) +{ + return mix(col1, col2, t); +} + +color node_mix_add(float t, color col1, color col2) +{ + return mix(col1, col1 + col2, t); +} + +color node_mix_mul(float t, color col1, color col2) +{ + return mix(col1, col1 * col2, t); +} + +color node_mix_screen(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + return color(1.0) - (color(tm) + t*(color(1.0) - col2))*(color(1.0) - col1); +} + +color node_mix_overlay(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + color outcol = col1; + + if(outcol[0] < 0.5) + outcol[0] *= tm + 2.0*t*col2[0]; + else + outcol[0] = 1.0 - (tm + 2.0*t*(1.0 - col2[0]))*(1.0 - outcol[0]); + + if(outcol[1] < 0.5) + outcol[1] *= tm + 2.0*t*col2[1]; + else + outcol[1] = 1.0 - (tm + 2.0*t*(1.0 - col2[1]))*(1.0 - outcol[1]); + + if(outcol[2] < 0.5) + outcol[2] *= tm + 2.0*t*col2[2]; + else + outcol[2] = 1.0 - (tm + 2.0*t*(1.0 - col2[2]))*(1.0 - outcol[2]); + + return outcol; +} + +color node_mix_sub(float t, color col1, color col2) +{ + return mix(col1, col1 - col2, t); +} + +color node_mix_div(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + color outcol = col1; + + if(col2[0] != 0.0) outcol[0] = tm*outcol[0] + t*outcol[0]/col2[0]; + if(col2[1] != 0.0) outcol[1] = tm*outcol[1] + t*outcol[1]/col2[1]; + if(col2[2] != 0.0) outcol[2] = tm*outcol[2] + t*outcol[2]/col2[2]; + + return outcol; +} + +color node_mix_diff(float t, color col1, color col2) +{ + return mix(col1, abs(col1 - col2), t); +} + +color node_mix_dark(float t, color col1, color col2) +{ + return min(col1, col2*t); +} + +color node_mix_light(float t, color col1, color col2) +{ + return max(col1, col2*t); +} + +color node_mix_dodge(float t, color col1, color col2) +{ + color outcol = col1; + + if(outcol[0] != 0.0) { + float tmp = 1.0 - t*col2[0]; + if(tmp <= 0.0) + outcol[0] = 1.0; + else if((tmp = outcol[0]/tmp) > 1.0) + outcol[0] = 1.0; + else + outcol[0] = tmp; + } + if(outcol[1] != 0.0) { + float tmp = 1.0 - t*col2[1]; + if(tmp <= 0.0) + outcol[1] = 1.0; + else if((tmp = outcol[1]/tmp) > 1.0) + outcol[1] = 1.0; + else + outcol[1] = tmp; + } + if(outcol[2] != 0.0) { + float tmp = 1.0 - t*col2[2]; + if(tmp <= 0.0) + outcol[2] = 1.0; + else if((tmp = outcol[2]/tmp) > 1.0) + outcol[2] = 1.0; + else + outcol[2] = tmp; + } + + return outcol; +} + +color node_mix_burn(float t, color col1, color col2) +{ + float tmp, tm = 1.0 - t; + + color outcol = col1; + + tmp = tm + t*col2[0]; + if(tmp <= 0.0) + outcol[0] = 0.0; + else if((tmp = (1.0 - (1.0 - outcol[0])/tmp)) < 0.0) + outcol[0] = 0.0; + else if(tmp > 1.0) + outcol[0] = 1.0; + else + outcol[0] = tmp; + + tmp = tm + t*col2[1]; + if(tmp <= 0.0) + outcol[1] = 0.0; + else if((tmp = (1.0 - (1.0 - outcol[1])/tmp)) < 0.0) + outcol[1] = 0.0; + else if(tmp > 1.0) + outcol[1] = 1.0; + else + outcol[1] = tmp; + + tmp = tm + t*col2[2]; + if(tmp <= 0.0) + outcol[2] = 0.0; + else if((tmp = (1.0 - (1.0 - outcol[2])/tmp)) < 0.0) + outcol[2] = 0.0; + else if(tmp > 1.0) + outcol[2] = 1.0; + else + outcol[2] = tmp; + + return outcol; +} + +color node_mix_hue(float t, color col1, color col2) +{ + color outcol = col1; + color hsv2 = rgb_to_hsv(col2); + + if(hsv2[1] != 0.0) { + color hsv = rgb_to_hsv(outcol); + hsv[0] = hsv2[0]; + color tmp = hsv_to_rgb(hsv); + + outcol = mix(outcol, tmp, t); + } + + return outcol; +} + +color node_mix_sat(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + color outcol = col1; + + color hsv = rgb_to_hsv(outcol); + + if(hsv[1] != 0.0) { + color hsv2 = rgb_to_hsv(col2); + + hsv[1] = tm*hsv[1] + t*hsv2[1]; + outcol = hsv_to_rgb(hsv); + } + + return outcol; +} + +color node_mix_val(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + color hsv = rgb_to_hsv(col1); + color hsv2 = rgb_to_hsv(col2); + + hsv[2] = tm*hsv[2] + t*hsv2[2]; + + return hsv_to_rgb(hsv); +} + +color node_mix_color(float t, color col1, color col2) +{ + color outcol = col1; + color hsv2 = rgb_to_hsv(col2); + + if(hsv2[1] != 0.0) { + color hsv = rgb_to_hsv(outcol); + hsv[0] = hsv2[0]; + hsv[1] = hsv2[1]; + color tmp = hsv_to_rgb(hsv); + + outcol = mix(outcol, tmp, t); + } + + return outcol; +} + +color node_mix_soft(float t, color col1, color col2) +{ + float tm = 1.0 - t; + + color one= color(1.0); + color scr= one - (one - col2)*(one - col1); + + return tm*col1 + t*((one - col1)*col2*col1 + col1*scr); +} + +color node_mix_linear(float t, color col1, color col2) +{ + color outcol = col1; + + if(col2[0] > 0.5) + outcol[0]= col1[0] + t*(2.0*(col2[0] - 0.5)); + else + outcol[0]= col1[0] + t*(2.0*(col2[0]) - 1.0); + + if(col2[1] > 0.5) + outcol[1]= col1[1] + t*(2.0*(col2[1] - 0.5)); + else + outcol[1]= col1[1] + t*(2.0*(col2[1]) - 1.0); + + if(col2[2] > 0.5) + outcol[2]= col1[2] + t*(2.0*(col2[2] - 0.5)); + else + outcol[2]= col1[2] + t*(2.0*(col2[2]) - 1.0); + + return outcol; +} + +shader node_mix( + string type = "Mix", + float Fac = 0.5, + color Color1 = color(0.0, 0.0, 0.0), + color Color2 = color(0.0, 0.0, 0.0), + output color Color = color(0.0, 0.0, 0.0)) +{ + float t = clamp(Fac, 0.0, 1.0); + + if(type == "Mix") + Color = node_mix_blend(t, Color1, Color2); + if(type == "Add") + Color = node_mix_add(t, Color1, Color2); + if(type == "Multiply") + Color = node_mix_mul(t, Color1, Color2); + if(type == "Screen") + Color = node_mix_screen(t, Color1, Color2); + if(type == "Overlay") + Color = node_mix_overlay(t, Color1, Color2); + if(type == "Subtract") + Color = node_mix_sub(t, Color1, Color2); + if(type == "Divide") + Color = node_mix_div(t, Color1, Color2); + if(type == "Difference") + Color = node_mix_diff(t, Color1, Color2); + if(type == "Darken") + Color = node_mix_dark(t, Color1, Color2); + if(type == "Lighten") + Color = node_mix_light(t, Color1, Color2); + if(type == "Dodge") + Color = node_mix_dodge(t, Color1, Color2); + if(type == "Burn") + Color = node_mix_burn(t, Color1, Color2); + if(type == "Hue") + Color = node_mix_hue(t, Color1, Color2); + if(type == "Saturation") + Color = node_mix_sat(t, Color1, Color2); + if(type == "Value") + Color = node_mix_val (t, Color1, Color2); + if(type == "Color") + Color = node_mix_color(t, Color1, Color2); + if(type == "Soft Light") + Color = node_mix_soft(t, Color1, Color2); + if(type == "Linear Light") + Color = node_mix_linear(t, Color1, Color2); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_mix_closure.osl b/intern/cycles/kernel/osl/nodes/node_mix_closure.osl new file mode 100644 index 00000000000..1a377abd381 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_mix_closure.osl @@ -0,0 +1,30 @@ +/* + * 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" + +shader node_mix_closure( + float Fac = 0.5, + closure color Closure1 = background(), + closure color Closure2 = background(), + output closure color Closure = background()) +{ + float t = clamp(Fac, 0.0, 1.0); + Closure = (1.0 - t)*Closure1 + t*Closure2; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl b/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl new file mode 100644 index 00000000000..fbd0ce5c3bd --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_musgrave_texture.osl @@ -0,0 +1,218 @@ +/* + * 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_texture.h" + +/* Musgrave fBm + * + * H: fractal increment parameter + * lacunarity: gap between successive frequencies + * octaves: number of frequencies in the fBm + * + * from "Texturing and Modelling: A procedural approach" + */ + +float noise_musgrave_fBm(point p, string basis, float H, float lacunarity, float octaves) +{ + float rmd; + float value = 0.0; + float pwr = 1.0; + float pwHL = pow(lacunarity, -H); + int i; + + for(i = 0; i < (int)octaves; i++) { + value += noise_basis(p, basis) * pwr; + pwr *= pwHL; + p *= lacunarity; + } + + rmd = octaves - floor(octaves); + if(rmd != 0.0) + value += rmd * noise_basis(p, basis) * pwr; + + return value; +} + +/* Musgrave Multifractal + * + * H: highest fractal dimension + * lacunarity: gap between successive frequencies + * octaves: number of frequencies in the fBm + */ + +float noise_musgrave_multi_fractal(point p, string basis, float H, float lacunarity, float octaves) +{ + float rmd; + float value = 1.0; + float pwr = 1.0; + float pwHL = pow(lacunarity, -H); + int i; + + for(i = 0; i < (int)octaves; i++) { + value *= (pwr * noise_basis(p, basis) + 1.0); + pwr *= pwHL; + p *= lacunarity; + } + + rmd = octaves - floor(octaves); + if(rmd != 0.0) + value *= (rmd * pwr * noise_basis(p, basis) + 1.0); /* correct? */ + + return value; +} + +/* Musgrave Heterogeneous Terrain + * + * H: fractal dimension of the roughest area + * lacunarity: gap between successive frequencies + * octaves: number of frequencies in the fBm + * offset: raises the terrain from `sea level' + */ + +float noise_musgrave_hetero_terrain(point p, string basis, float H, float lacunarity, float octaves, float offset) +{ + float value, increment, rmd; + float pwHL = pow(lacunarity, -H); + float pwr = pwHL; + int i; + + /* first unscaled octave of function; later octaves are scaled */ + value = offset + noise_basis(p, basis); + p *= lacunarity; + + for(i = 1; i < (int)octaves; i++) { + increment = (noise_basis(p, basis) + offset) * pwr * value; + value += increment; + pwr *= pwHL; + p *= lacunarity; + } + + rmd = octaves - floor(octaves); + if(rmd != 0.0) { + increment = (noise_basis(p, basis) + offset) * pwr * value; + value += rmd * increment; + } + + return value; +} + +/* Hybrid Additive/Multiplicative Multifractal Terrain + * + * H: fractal dimension of the roughest area + * lacunarity: gap between successive frequencies + * octaves: number of frequencies in the fBm + * offset: raises the terrain from `sea level' + */ + +float noise_musgrave_hybrid_multi_fractal(point p, string basis, float H, float lacunarity, float octaves, float offset, float gain) +{ + float result, signal, weight, rmd; + float pwHL = pow(lacunarity, -H); + float pwr = pwHL; + int i; + + result = noise_basis(p, basis) + offset; + weight = gain * result; + p *= lacunarity; + + for(i = 1; (weight > 0.001) && (i < (int)octaves); i++) { + if(weight > 1.0) + weight = 1.0; + + signal = (noise_basis(p, basis) + offset) * pwr; + pwr *= pwHL; + result += weight * signal; + weight *= gain * signal; + p *= lacunarity; + } + + rmd = octaves - floor(octaves); + if(rmd != 0.0) + result += rmd * ((noise_basis(p, basis) + offset) * pwr); + + return result; +} + +/* Ridged Multifractal Terrain + * + * H: fractal dimension of the roughest area + * lacunarity: gap between successive frequencies + * octaves: number of frequencies in the fBm + * offset: raises the terrain from `sea level' + */ + +float noise_musgrave_ridged_multi_fractal(point p, string basis, float H, float lacunarity, float octaves, float offset, float gain) +{ + float result, signal, weight; + float pwHL = pow(lacunarity, -H); + float pwr = pwHL; + int i; + + signal = offset - fabs(noise_basis(p, basis)); + signal *= signal; + result = signal; + weight = 1.0; + + for(i = 1; i < (int)octaves; i++) { + p *= lacunarity; + weight = clamp(signal * gain, 0.0, 1.0); + signal = offset - fabs(noise_basis(p, basis)); + signal *= signal; + signal *= weight; + result += signal * pwr; + pwr *= pwHL; + } + + return result; +} + +/* Shader */ + +shader node_musgrave_texture( + string Type = "fBM", + string Basis = "Perlin", + float Dimension = 2.0, + float Lacunarity = 1.0, + float Octaves = 2.0, + float Offset = 0.0, + float Intensity = 1.0, + float Gain = 1.0, + float Size = 0.25, + point Vector = P, + output float Fac = 0.0) +{ + float dimension = max(Dimension, 0.0); + float octaves = max(Octaves, 0.0); + float lacunarity = max(Lacunarity, 1e-5); + float size = nonzero(Size, 1e-5); + + point p = Vector/size; + + if(Type == "Multifractal") + Fac = Intensity*noise_musgrave_multi_fractal(p, Basis, dimension, lacunarity, octaves); + else if(Type == "fBM") + Fac = Intensity*noise_musgrave_fBm(p, Basis, dimension, lacunarity, octaves); + else if(Type == "Hybrid Multifractal") + Fac = Intensity*noise_musgrave_hybrid_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); + else if(Type == "Ridged Multifractal") + Fac = Intensity*noise_musgrave_ridged_multi_fractal(p, Basis, dimension, lacunarity, octaves, Offset, Gain); + else if(Type == "Hetero Terrain") + Fac = Intensity*noise_musgrave_hetero_terrain(p, Basis, dimension, lacunarity, octaves, Offset); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_noise_texture.osl b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl new file mode 100644 index 00000000000..193ed67d16e --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_noise_texture.osl @@ -0,0 +1,36 @@ +/* + * 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_texture.h" + +shader node_noise_texture( + point Vector = P, + output color Color = color(0.0, 0.0, 0.0), + output float Fac = 0.0) +{ + point p = Vector*1e8; + + float r = cellnoise(p); + float g = cellnoise(point(p[1], p[0], p[2])); + float b = cellnoise(point(p[1], p[2], p[0])); + + Fac = r; + Color = color(r, g, b); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_output_displacement.osl b/intern/cycles/kernel/osl/nodes/node_output_displacement.osl new file mode 100644 index 00000000000..a6b452c532a --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_output_displacement.osl @@ -0,0 +1,25 @@ +/* + * 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" + +displacement node_output_displacement(float Displacement = 0.0) +{ + P += N*Displacement*0.1; /* todo: get rid of this factor */ +} + diff --git a/intern/cycles/kernel/osl/nodes/node_output_surface.osl b/intern/cycles/kernel/osl/nodes/node_output_surface.osl new file mode 100644 index 00000000000..6efaf91121b --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_output_surface.osl @@ -0,0 +1,25 @@ +/* + * 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" + +surface node_output_surface(closure color Surface = background()) +{ + Ci = Surface; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_output_volume.osl b/intern/cycles/kernel/osl/nodes/node_output_volume.osl new file mode 100644 index 00000000000..18094242dc7 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_output_volume.osl @@ -0,0 +1,25 @@ +/* + * 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" + +volume node_output_volume(closure color Volume = background()) +{ + Ci = Volume; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_sky_texture.osl b/intern/cycles/kernel/osl/nodes/node_sky_texture.osl new file mode 100644 index 00000000000..fdb9b1d9708 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_sky_texture.osl @@ -0,0 +1,162 @@ +/* + * 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" + +struct KernelSunSky { + /* sun direction in spherical and cartesian */ + float theta, phi; + vector dir; + + /* perez function parameters */ + float zenith_Y, zenith_x, zenith_y; + float perez_Y[5], perez_x[5], perez_y[5]; +}; + +color xyY_to_xyz(float x, float y, float Y) +{ + float X, Z; + + if(y != 0.0) X = (x / y) * Y; + else X = 0.0; + + if(y != 0.0 && Y != 0.0) Z = ((1.0 - x - y) / y) * Y; + else Z = 0.0; + + return color(X, Y, Z); +} + +color xyz_to_rgb(float x, float y, float z) +{ + return color(3.240479 * x + -1.537150 * y + -0.498535 * z, + -0.969256 * x + 1.875991 * y + 0.041556 * z, + 0.055648 * x + -0.204043 * y + 1.057311 * z); +} + +float sky_angle_between(float thetav, float phiv, float theta, float phi) +{ + float cospsi = sin(thetav)*sin(theta)*cos(phi - phiv) + cos(thetav)*cos(theta); + + if(cospsi > 1.0) + return 0.0; + if(cospsi < -1.0) + return M_PI; + + return acos(cospsi); +} + +vector sky_spherical_coordinates(vector dir) +{ + return vector(acos(dir[2]), atan2(dir[0], dir[1]), 0); +} + +float sky_perez_function(float lam[5], float theta, float gamma) +{ + float ctheta = cos(theta); + float cgamma = cos(gamma); + + return (1.0 + lam[0]*exp(lam[1] / ctheta)) * (1.0 + lam[2]*exp(lam[3]*gamma) + lam[4]*cgamma*cgamma); +} + +color sky_xyz_radiance(KernelSunSky sunsky, vector dir) +{ + /* convert vector to spherical coordinates */ + vector spherical = sky_spherical_coordinates(dir); + float theta = spherical[0]; + float phi = spherical[1]; + + /* angle between sun direction and dir */ + float gamma = sky_angle_between(theta, phi, sunsky.theta, sunsky.phi); + + /* clamp theta to horizon */ + theta = min(theta, M_PI_2 - 0.001); + + /* compute xyY color space values */ + float x = sunsky.zenith_x * sky_perez_function(sunsky.perez_x, theta, gamma); + float y = sunsky.zenith_y * sky_perez_function(sunsky.perez_y, theta, gamma); + float Y = sunsky.zenith_Y * sky_perez_function(sunsky.perez_Y, theta, gamma); + + /* convert to RGB */ + color xyz = xyY_to_xyz(x, y, Y); + return xyz_to_rgb(xyz[0], xyz[1], xyz[2]); +} + +void precompute_sunsky(vector dir, float turbidity, output KernelSunSky sunsky) +{ + vector spherical = sky_spherical_coordinates(dir); + float theta = spherical[0]; + float phi = spherical[1]; + + sunsky.theta = theta; + sunsky.phi = phi; + sunsky.dir = dir; + + float theta2 = theta*theta; + float theta3 = theta*theta*theta; + float T = turbidity; + float T2 = T*T; + + float chi = (4.0/ 9.0- T / 120.0) * (M_PI - 2.0* theta); + sunsky.zenith_Y = (4.0453*T - 4.9710) * tan(chi) - 0.2155*T + 2.4192; + sunsky.zenith_Y *= 0.06; + + sunsky.zenith_x = + (0.00166* theta3 - 0.00375* theta2 + 0.00209* theta)*T2 + + (-0.02903* theta3 + 0.06377* theta2 - 0.03202* theta + 0.00394)*T + + (0.11693* theta3 - 0.21196* theta2 + 0.06052* theta + 0.25886); + + sunsky.zenith_y = + (0.00275* theta3 - 0.00610* theta2 + 0.00317* theta)*T2 + + (-0.04214* theta3 + 0.08970* theta2 - 0.04153* theta + 0.00516)*T + + (0.15346* theta3 - 0.26756* theta2 + 0.06670* theta + 0.26688); + + sunsky.perez_Y[0] = (0.1787*T - 1.4630); + sunsky.perez_Y[1] = (-0.3554*T + 0.4275); + sunsky.perez_Y[2] = (-0.0227*T + 5.3251); + sunsky.perez_Y[3] = (0.1206*T - 2.5771); + sunsky.perez_Y[4] = (-0.0670*T + 0.3703); + + sunsky.perez_x[0] = (-0.0193*T - 0.2592); + sunsky.perez_x[1] = (-0.0665*T + 0.0008); + sunsky.perez_x[2] = (-0.0004*T + 0.2125); + sunsky.perez_x[3] = (-0.0641*T - 0.8989); + sunsky.perez_x[4] = (-0.0033*T + 0.0452); + + sunsky.perez_y[0] = (-0.0167*T - 0.2608); + sunsky.perez_y[1] = (-0.0950*T + 0.0092); + sunsky.perez_y[2] = (-0.0079*T + 0.2102); + sunsky.perez_y[3] = (-0.0441*T - 1.6537); + sunsky.perez_y[4] = (-0.0109*T + 0.0529); + + sunsky.zenith_Y /= sky_perez_function(sunsky.perez_Y, 0, theta); + sunsky.zenith_x /= sky_perez_function(sunsky.perez_x, 0, theta); + sunsky.zenith_y /= sky_perez_function(sunsky.perez_y, 0, theta); +} + +shader node_sky_texture( + vector Vector = P, + vector sun_direction = vector(0, 0, 1), + float turbidity = 2.2, + output color Color = color(0.0, 0.0, 0.0)) +{ + KernelSunSky sunsky; + + precompute_sunsky(sun_direction, turbidity, sunsky); + Color = sky_xyz_radiance(sunsky, Vector); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_stucci_texture.osl b/intern/cycles/kernel/osl/nodes/node_stucci_texture.osl new file mode 100644 index 00000000000..f03e03d9a98 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_stucci_texture.osl @@ -0,0 +1,49 @@ +/* + * 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_texture.h" + +/* Stucci */ + +shader node_stucci_texture( + string Type = "Plastic", + string Basis = "Perlin", + int Hard = 0, + float Turbulence = 1.0, + float Size = 0.25, + point Vector = P, + output float Fac = 0.0) +{ + float size = nonzero(Size, 1e-5); + point p = Vector/size; + + float b2 = noise_basis_hard(p, Basis, Hard); + float ofs = Turbulence/200.0; + + if(Type != "Plastic") + ofs *= b2*b2; + + Fac = noise_basis_hard(point(p[0], p[1], p[2]+ofs), Basis, Hard); + + if(Type == "Wall Out") + Fac = 1.0 - Fac; + + Fac = max(Fac, 0.0); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_texture.h b/intern/cycles/kernel/osl/nodes/node_texture.h new file mode 100644 index 00000000000..8adb0e8aeb5 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_texture.h @@ -0,0 +1,251 @@ +/* + * 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. + */ + +/* Voronoi Distances */ + +float voronoi_distance(string distance_metric, vector d, float e) +{ + float result = 0.0; + + if(distance_metric == "Distance Squared") + result = dot(d, d); + if(distance_metric == "Actual Distance") + result = length(d); + if(distance_metric == "Manhattan") + result = fabs(d[0]) + fabs(d[1]) + fabs(d[2]); + if(distance_metric == "Chebychev") + result = max(fabs(d[0]), max(fabs(d[1]), fabs(d[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); + + return result; +} + +/* Voronoi / Worley like */ + +color cellnoise_color(point p) +{ + float r = cellnoise(p); + float g = cellnoise(point(p[1], p[0], p[2])); + float b = cellnoise(point(p[1], p[2], p[0])); + + return color(r, g, b); +} + +void voronoi(point p, string distance_metric, float e, float da[4], point pa[4]) +{ + /* returns distances in da and point coords in pa */ + int xx, yy, zz, xi, yi, zi; + + xi = (int)floor(p[0]); + yi = (int)floor(p[1]); + zi = (int)floor(p[2]); + + da[0] = 1e10; + da[1] = 1e10; + 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++) { + point ip = point(xx, yy, zz); + point vp = (point)cellnoise_color(ip); + point pd = p - (vp + ip); + float d = voronoi_distance(distance_metric, pd, e); + + vp += point(xx, yy, zz); + + if(d < da[0]) { + da[3] = da[2]; + da[2] = da[1]; + da[1] = da[0]; + da[0] = d; + + pa[3] = pa[2]; + pa[2] = pa[1]; + pa[1] = pa[0]; + pa[0] = vp; + } + else if(d < da[1]) { + da[3] = da[2]; + da[2] = da[1]; + da[1] = d; + + pa[3] = pa[2]; + pa[2] = pa[1]; + pa[1] = vp; + } + else if(d < da[2]) { + da[3] = da[2]; + da[2] = d; + + pa[3] = pa[2]; + pa[2] = vp; + } + else if(d < da[3]) { + da[3] = d; + pa[3] = vp; + } + } + } + } +} + +float voronoi_Fn(point p, int n) +{ + float da[4]; + point pa[4]; + + voronoi(p, "Distance Squared", 0, da, pa); + + return da[n]; +} + +float voronoi_FnFn(point p, int n1, int n2) +{ + float da[4]; + point pa[4]; + + voronoi(p, "Distance Squared", 0, da, pa); + + return da[n2] - da[n1]; +} + +float voronoi_F1(point p) { return voronoi_Fn(p, 0); } +float voronoi_F2(point p) { return voronoi_Fn(p, 1); } +float voronoi_F3(point p) { return voronoi_Fn(p, 2); } +float voronoi_F4(point p) { return voronoi_Fn(p, 3); } +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 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 */ + +float noise_basis(point p, string basis) +{ + float result = 0.0; + + if(basis == "Perlin") + result = noise(p); + if(basis == "Voronoi F1") + result = voronoi_F1S(p); + if(basis == "Voronoi F2") + result = voronoi_F2S(p); + if(basis == "Voronoi F3") + result = voronoi_F3S(p); + if(basis == "Voronoi F4") + result = voronoi_F4S(p); + if(basis == "Voronoi F2-F1") + result = voronoi_F1F2S(p); + if(basis == "Voronoi Crackle") + result = voronoi_CrS(p); + if(basis == "Cell Noise") + result = cellnoise(p); + + return result; +} + +/* Soft/Hard Noise */ + +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; +} + +/* Waves */ + +float noise_wave(string wave, float a) +{ + float result = 0.0; + + if(wave == "Sine") { + result = 0.5 + 0.5*sin(a); + } + else if(wave == "Saw") { + float b = 2*M_PI; + int n = (int)(a / b); + a -= n*b; + if(a < 0) a += b; + + result = a / b; + } + 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))); + } + + return result; +} + +/* Turbulence */ + +float noise_turbulence(point p, string basis, int octaves, int hard) +{ + float fscale = 1.0; + float amp = 1.0; + float sum = 0.0; + int i; + + for(i = 0; i <= octaves; i++) { + float t = noise_basis(fscale*p, basis); + + if(hard) + t = fabs(2.0*t - 1.0); + + sum += t*amp; + amp *= 0.5; + fscale *= 2.0; + } + + sum *= ((float)(1 << octaves)/(float)((1 << (octaves+1)) - 1)); + + return sum; +} + +/* Utility */ + +float nonzero(float f, float eps) +{ + float r; + + if(abs(f) < eps) + r = sign(f)*eps; + else + r = f; + + return r; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_texture_coordinate.osl b/intern/cycles/kernel/osl/nodes/node_texture_coordinate.osl new file mode 100644 index 00000000000..2acf72aef54 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_texture_coordinate.osl @@ -0,0 +1,66 @@ +/* + * 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" + +shader node_texture_coordinate( + normal Normal = N, + int is_background = 0, + string bump_offset = "center", + + output point Generated = point(0.0, 0.0, 0.0), + output point UV = point(0.0, 0.0, 0.0), + output point Object = point(0.0, 0.0, 0.0), + output point Camera = point(0.0, 0.0, 0.0), + output point Window = point(0.0, 0.0, 0.0), + output point Reflection = point(0.0, 0.0, 0.0)) +{ + if(is_background) { + Generated = P; + UV = point(0.0, 0.0, 0.0); + Object = P; + point Pcam = transform("camera", "world", point(0, 0, 0)); + Camera = transform("camera", P + Pcam); + Window = transform("NDC", P + Pcam); + Reflection = I; + } + else { + getattribute("std::generated", Generated); + getattribute("std::uv", UV); + Object = transform("object", P); + Camera = transform("camera", P); + Window = transform("NDC", P); + Reflection = reflect(I, Normal); + } + + if(bump_offset == "dx") { + Generated += Dx(Generated); + UV += Dx(UV); + Object += Dx(Object); + Camera += Dx(Camera); + Window += Dx(Window); + } + else if(bump_offset == "dy") { + Generated += Dy(Generated); + UV += Dy(UV); + Object += Dy(Object); + Camera += Dy(Camera); + Window += Dy(Window); + } +} + diff --git a/intern/cycles/kernel/osl/nodes/node_translucent_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_translucent_bsdf.osl new file mode 100644 index 00000000000..9acd46756d2 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_translucent_bsdf.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_translucent_bsdf( + color Color = color(0.8, 0.8, 0.8), + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + BSDF = Color*translucent(Normal); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_transparent_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_transparent_bsdf.osl new file mode 100644 index 00000000000..b347bfb116b --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_transparent_bsdf.osl @@ -0,0 +1,28 @@ +/* + * 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" + +shader node_transparent_bsdf( + color Color = color(0.8, 0.8, 0.8), + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + BSDF = Color*transparent(); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_value.osl b/intern/cycles/kernel/osl/nodes/node_value.osl new file mode 100644 index 00000000000..bee6f39f2bc --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_value.osl @@ -0,0 +1,33 @@ +/* + * 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" + +shader node_value( + float value_value = 0.0, + vector vector_value = vector(0.0, 0.0, 0.0), + color color_value = color(0.0, 0.0, 0.0), + output float Value = 0.0, + output vector Vector = vector(0.0, 0.0, 0.0), + output color Color = color(0.0, 0.0, 0.0)) +{ + Value = value_value; + Vector = vector_value; + Color = color_value; +} + diff --git a/intern/cycles/kernel/osl/nodes/node_vector_math.osl b/intern/cycles/kernel/osl/nodes/node_vector_math.osl new file mode 100644 index 00000000000..c6231d4350d --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_vector_math.osl @@ -0,0 +1,53 @@ +/* + * 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" + +shader node_vector_math( + string type = "Add", + vector Vector1 = vector(0.0, 0.0, 0.0), + vector Vector2 = vector(0.0, 0.0, 0.0), + output float Fac = 0.0, + output vector Vector = vector(0.0, 0.0, 0.0)) +{ + if(type == "Add") { + Vector = Vector1 + Vector2; + Fac = (abs(Vector[0]) + abs(Vector[1]) + abs(Vector[2]))/3.0; + } + if(type == "Subtract") { + Vector = Vector1 + Vector2; + Fac = (abs(Vector[0]) + abs(Vector[1]) + abs(Vector[2]))/3.0; + } + if(type == "Average") { + Fac = length(Vector1 + Vector2); + Vector = normalize(Vector1 + Vector2); + } + if(type == "Dot Product") { + Fac = dot(Vector1, Vector2); + } + if(type == "Cross Product") { + vector c = cross(Vector1, Vector2); + Fac = length(c); + Vector = normalize(c); + } + if(type == "Normalize") { + Fac = length(Vector1); + Vector = normalize(Vector1); + } +} + diff --git a/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl new file mode 100644 index 00000000000..2b6219f6325 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_velvet_bsdf.osl @@ -0,0 +1,40 @@ +/* + * 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_velvet_bsdf( + color Color = color(0.8, 0.8, 0.8), + float Sigma = 0.0, + float Fresnel = 0.3, + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + float Fr = 1.0; + + if(Fresnel < 1.0) { + float eta = 1.0/clamp(1.0 - Fresnel, 1e-5, 1.0 - 1e-5); + Fr = fresnel_dielectric(I, Normal, eta); + } + + float sigma = clamp(Sigma, 0.0, 1.0); + + BSDF = (Fr*Color)*ashikhmin_velvet(Normal, sigma); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl b/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl new file mode 100644 index 00000000000..140ba6a6ba1 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_voronoi_texture.osl @@ -0,0 +1,82 @@ +/* + * 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_texture.h" + +/* Voronoi */ + +shader node_voronoi_texture( + string DistanceMetric = "Actual Distance", + string Coloring = "Intensity", + float Weight1 = 1.0, + float Weight2 = 0.0, + float Weight3 = 0.0, + float Weight4 = 0.0, + float Exponent = 2.5, + float Intensity = 1.0, + float Size = 0.25, + point Vector = P, + output float Fac = 0.0, + output color Color = color(0.0, 0.0, 0.0)) +{ + float exponent = max(Exponent, 1e-5); + float size = nonzero(Size, 1e-5); + + float aw1 = fabs(Weight1); + float aw2 = fabs(Weight2); + float aw3 = fabs(Weight3); + float aw4 = fabs(Weight4); + float sc = (aw1 + aw2 + aw3 + aw4); + + if(sc != 0.0) + sc = Intensity/sc; + + /* compute distance and point coordinate of 4 nearest neighbours */ + float da[4]; + point pa[4]; + + voronoi(Vector/size, DistanceMetric, exponent, da, pa); + + /* Scalar output */ + Fac = sc * fabs(Weight1*da[0] + Weight2*da[1] + Weight3*da[2] + Weight4*da[3]); + + /* Colored output */ + if(Coloring == "Intensity") { + Color = color(Fac, Fac, Fac); + } + else { + Color = aw1*cellnoise_color(pa[0]); + Color += aw2*cellnoise_color(pa[1]); + Color += aw3*cellnoise_color(pa[2]); + Color += aw4*cellnoise_color(pa[3]); + + if(Coloring != "Position") { + float t1 = min((da[1] - da[0])*10.0, 1.0); + + if(Coloring == "Position, Outline, and Intensity") + Color *= t1*Fac; + else if(Coloring == "Position and Outline") + Color *= t1*sc; + } + else { + Color *= sc; + } + } +} + diff --git a/intern/cycles/kernel/osl/nodes/node_ward_bsdf.osl b/intern/cycles/kernel/osl/nodes/node_ward_bsdf.osl new file mode 100644 index 00000000000..68db07109ed --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_ward_bsdf.osl @@ -0,0 +1,30 @@ +/* + * 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" + +shader node_ward_bsdf( + color Color = color(0.8, 0.8, 0.8), + float RoughnessU = 0.0, + float RoughnessV = 0.0, + normal Normal = N, + output closure color BSDF = diffuse(Normal)) +{ + BSDF = Color*ward(Normal, normalize(dPdu), RoughnessU, RoughnessV); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_wood_texture.osl b/intern/cycles/kernel/osl/nodes/node_wood_texture.osl new file mode 100644 index 00000000000..f1d2e278597 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_wood_texture.osl @@ -0,0 +1,63 @@ +/* + * 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_texture.h" + +/* Wood */ + +float wood(point p, float size, string type, string wave, string basis, int hard, float turb) +{ + float x = p[0]; + float y = p[1]; + float z = p[2]; + + float result = 0.0; + + if(type == "Bands") { + result = noise_wave(wave, (x + y + z)*10.0); + } + else if(type == "Rings") { + result = noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0); + } + else if (type == "Band Noise") { + float wi = turb*noise_basis_hard(p/size, basis, hard); + result = noise_wave(wave, (x + y + z)*10.0 + wi); + } + else if (type == "Ring Noise") { + float wi = turb*noise_basis_hard(p/size, basis, hard); + result = noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0 + wi); + } + + return result; +} + +shader node_wood_texture( + string Type = "Bands", + string Wave = "Sine", + string Basis = "Perlin", + int Hard = 0, + float Size = 0.25, + float Turbulence = 5.0, + point Vector = P, + output float Fac = 0.0) +{ + float size = nonzero(Size, 1e-5); + Fac = wood(Vector, size, Type, Wave, Basis, Hard, Turbulence); +} + diff --git a/intern/cycles/kernel/osl/nodes/stdosl.h b/intern/cycles/kernel/osl/nodes/stdosl.h new file mode 100644 index 00000000000..6fe4f52df4a --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/stdosl.h @@ -0,0 +1,471 @@ +///////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved. +// +// 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 CCL_STDOSL_H +#define CCL_STDOSL_H + + +#ifndef M_PI +#define M_PI 3.1415926535897932 /* pi */ +#define M_PI_2 1.5707963267948966 /* pi/2 */ +#define M_PI_4 0.7853981633974483 /* pi/4 */ +#define M_2_PI 0.6366197723675813 /* 2/pi */ +#define M_2_SQRTPI 1.1283791670955126 /* 2/sqrt(pi) */ +#define M_E 2.7182818284590452 /* e (Euler's number) */ +#define M_LN2 0.6931471805599453 /* ln(2) */ +#define M_LN10 2.3025850929940457 /* ln(10) */ +#define M_LOG2E 1.4426950408889634 /* log_2(e) */ +#define M_LOG10E 0.4342944819032518 /* log_10(e) */ +#define M_SQRT2 1.4142135623730950 /* sqrt(2) */ +#define M_SQRT1_2 0.7071067811865475 /* 1/sqrt(2) */ +#endif + + + +// Declaration of built-in functions and closures +#define BUILTIN [[ int builtin = 1 ]] +#define BUILTIN_DERIV [[ int builtin = 1, int deriv = 1 ]] + +#define PERCOMP1(name) \ + normal name (normal x) BUILTIN; \ + vector name (vector x) BUILTIN; \ + point name (point x) BUILTIN; \ + color name (color x) BUILTIN; \ + float name (float x) BUILTIN; + +#define PERCOMP2(name) \ + normal name (normal x, normal y) BUILTIN; \ + vector name (vector x, vector y) BUILTIN; \ + point name (point x, point y) BUILTIN; \ + color name (color x, color y) BUILTIN; \ + float name (float x, float y) BUILTIN; + +#define PERCOMP2F(name) \ + normal name (normal x, float y) BUILTIN; \ + vector name (vector x, float y) BUILTIN; \ + point name (point x, float y) BUILTIN; \ + color name (color x, float y) BUILTIN; \ + float name (float x, float y) BUILTIN; + + +// Basic math +normal degrees (normal x) { return x*(180.0/M_PI); } +vector degrees (vector x) { return x*(180.0/M_PI); } +point degrees (point x) { return x*(180.0/M_PI); } +color degrees (color x) { return x*(180.0/M_PI); } +float degrees (float x) { return x*(180.0/M_PI); } +normal radians (normal x) { return x*(M_PI/180.0); } +vector radians (vector x) { return x*(M_PI/180.0); } +point radians (point x) { return x*(M_PI/180.0); } +color radians (color x) { return x*(M_PI/180.0); } +float radians (float x) { return x*(M_PI/180.0); } +PERCOMP1 (cos) +PERCOMP1 (sin) +PERCOMP1 (tan) +PERCOMP1 (acos) +PERCOMP1 (asin) +PERCOMP1 (atan) +PERCOMP2 (atan2) +PERCOMP1 (cosh) +PERCOMP1 (sinh) +PERCOMP1 (tanh) +PERCOMP2F (pow) +PERCOMP1 (exp) +PERCOMP1 (exp2) +PERCOMP1 (expm1) +PERCOMP1 (log) +point log (point a, float b) { return log(a)/log(b); } +vector log (vector a, float b) { return log(a)/log(b); } +color log (color a, float b) { return log(a)/log(b); } +float log (float a, float b) { return log(a)/log(b); } +PERCOMP1 (log2) +PERCOMP1 (log10) +PERCOMP1 (logb) +PERCOMP1 (sqrt) +PERCOMP1 (inversesqrt) +float hypot (float a, float b) { return sqrt (a*a + b*b); } +float hypot (float a, float b, float c) { return sqrt (a*a + b*b + c*c); } +PERCOMP1 (abs) +int abs (int x) BUILTIN; +PERCOMP1 (fabs) +int fabs (int x) BUILTIN; +PERCOMP1 (sign) +PERCOMP1 (floor) +PERCOMP1 (ceil) +PERCOMP1 (round) +PERCOMP1 (trunc) +PERCOMP2 (fmod) +PERCOMP2F (fmod) +PERCOMP2 (mod) +PERCOMP2F (mod) +int mod (int x, int y) BUILTIN; +PERCOMP2 (min) +PERCOMP2 (max) +normal clamp (normal x, normal minval, normal maxval) { return max(min(x,maxval),minval); } +vector clamp (vector x, vector minval, vector maxval) { return max(min(x,maxval),minval); } +point clamp (point x, point minval, point maxval) { return max(min(x,maxval),minval); } +color clamp (color x, color minval, color maxval) { return max(min(x,maxval),minval); } +float clamp (float x, float minval, float maxval) { return max(min(x,maxval),minval); } +//normal clamp (normal x, normal minval, normal maxval) BUILTIN; +//vector clamp (vector x, vector minval, vector maxval) BUILTIN; +//point clamp (point x, point minval, point maxval) BUILTIN; +//color clamp (color x, color minval, color maxval) BUILTIN; +//float clamp (float x, float minval, float maxval) BUILTIN; +normal mix (normal x, normal y, normal a) { return x*(1-a) + y*a; } +normal mix (normal x, normal y, float a) { return x*(1-a) + y*a; } +vector mix (vector x, vector y, vector a) { return x*(1-a) + y*a; } +vector mix (vector x, vector y, float a) { return x*(1-a) + y*a; } +point mix (point x, point y, point a) { return x*(1-a) + y*a; } +point mix (point x, point y, float a) { return x*(1-a) + y*a; } +color mix (color x, color y, color a) { return x*(1-a) + y*a; } +color mix (color x, color y, float a) { return x*(1-a) + y*a; } +float mix (float x, float y, float a) { return x*(1-a) + y*a; } +int isnan (float x) BUILTIN; +int isinf (float x) BUILTIN; +int isfinite (float x) BUILTIN; +float erf (float x) BUILTIN; +float erfc (float x) BUILTIN; + +// Vector functions + +vector cross (vector a, vector b) BUILTIN; +float dot (vector a, vector b) BUILTIN; +float length (vector v) BUILTIN; +float distance (point a, point b) BUILTIN; +float distance (point a, point b, point q) BUILTIN; +normal normalize (normal v) BUILTIN; +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))); +} +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); + } +#undef sqr +} + +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); +} + +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; + +// Implementation of transform-with-named-space in terms of matrices: + +point transform (string tospace, point x) +{ + return transform (matrix ("common", tospace), x); +} + +point transform (string fromspace, string tospace, point x) +{ + return transform (matrix (fromspace, tospace), x); +} + + +vector transform (string tospace, vector x) +{ + return transform (matrix ("common", tospace), x); +} + +vector transform (string fromspace, string tospace, vector x) +{ + return transform (matrix (fromspace, tospace), x); +} + + +normal transform (string tospace, normal x) +{ + return transform (matrix ("common", tospace), x); +} + +normal transform (string fromspace, string tospace, normal x) +{ + return transform (matrix (fromspace, tospace), x); +} + +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)); +} + + + +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 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); +} + + + +// Matrix functions + +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; + + +// Derivatives and area operators + + +// Displacement functions + + +// 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)); } + +// 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, 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, string f) { + return concat(concat(a,b,c,d,e), f); +} + + +// Texture + + +// Closures + +closure color diffuse(normal N) 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 refraction(normal N, float eta) BUILTIN; +closure color dielectric(normal N, float eta) BUILTIN; +closure color transparent() BUILTIN; +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 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; +closure color bssrdf_cubic(color radius) BUILTIN; +closure color emission(float inner_angle, float outer_angle) BUILTIN; +closure color emission(float outer_angle) BUILTIN; +closure color emission() BUILTIN; +closure color debug(string tag) BUILTIN; +closure color background() BUILTIN; +closure color holdout() BUILTIN; +closure color subsurface(float eta, float g, float mfp, float albedo) BUILTIN; + +// Renderer state +int raytype (string typename) BUILTIN; + +#undef BUILTIN +#undef BUILTIN_DERIV +#undef PERCOMP1 +#undef PERCOMP2 +#undef PERCOMP2F + +#endif /* CCL_STDOSL_H */ + -- cgit v1.2.3