diff --git a/CMakeLists.txt b/CMakeLists.txt index bdc663ecd6..09f8c7d060 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,6 @@ option (WITH_STUDIO "Build appleseed.studio" option (WITH_TOOLS "Build appleseed tools" ON) option (WITH_PYTHON "Build Python bindings" ON) option (WITH_DISNEY_MATERIAL "Build Disney material" OFF) -option (WITH_PARTIO "Build Partio support (used in unit tests)" OFF) option (USE_CPP11 "Use C++11" OFF) option (USE_STATIC_BOOST "Use static Boost libraries" ON) @@ -255,11 +254,6 @@ if (WITH_DISNEY_MATERIAL) endif () endif () -if (WITH_PARTIO) - add_definitions (-DAPPLESEED_WITH_PARTIO) - find_package (Partio REQUIRED) -endif () - #-------------------------------------------------------------------------------------------------- # Include paths. @@ -329,10 +323,6 @@ if (WITH_DISNEY_MATERIAL) endif () endif () -if (WITH_PARTIO) - include_directories (${PARTIO_INCLUDE_DIRS}) -endif () - #-------------------------------------------------------------------------------------------------- # Preprocessor definitions. diff --git a/sandbox/tests/test scenes/bssrdf/ref/79 - osl - gaussian.png b/sandbox/tests/test scenes/bssrdf/ref/79 - osl - gaussian.png index dc3e6ee7d4..5287bab75c 100644 Binary files a/sandbox/tests/test scenes/bssrdf/ref/79 - osl - gaussian.png and b/sandbox/tests/test scenes/bssrdf/ref/79 - osl - gaussian.png differ diff --git a/sandbox/tests/test scenes/bssrdf/ref/80 - osl - stddipole.png b/sandbox/tests/test scenes/bssrdf/ref/80 - osl - stddipole.png index f51f995ee3..be4c47376d 100644 Binary files a/sandbox/tests/test scenes/bssrdf/ref/80 - osl - stddipole.png and b/sandbox/tests/test scenes/bssrdf/ref/80 - osl - stddipole.png differ diff --git a/sandbox/tests/test scenes/bssrdf/ref/81 - osl - betterdipole.png b/sandbox/tests/test scenes/bssrdf/ref/81 - osl - betterdipole.png index 7a959a5c56..2e86de663e 100644 Binary files a/sandbox/tests/test scenes/bssrdf/ref/81 - osl - betterdipole.png and b/sandbox/tests/test scenes/bssrdf/ref/81 - osl - betterdipole.png differ diff --git a/sandbox/tests/test scenes/bssrdf/ref/82 - osl - directionaldipole.png b/sandbox/tests/test scenes/bssrdf/ref/82 - osl - directionaldipole.png index 776acc16ce..1b4ab5f582 100644 Binary files a/sandbox/tests/test scenes/bssrdf/ref/82 - osl - directionaldipole.png and b/sandbox/tests/test scenes/bssrdf/ref/82 - osl - directionaldipole.png differ diff --git a/sandbox/tests/test scenes/bssrdf/ref/83 - osl - normalizeddiff.png b/sandbox/tests/test scenes/bssrdf/ref/83 - osl - normalizeddiff.png index 354bea8116..56679cf7af 100644 Binary files a/sandbox/tests/test scenes/bssrdf/ref/83 - osl - normalizeddiff.png and b/sandbox/tests/test scenes/bssrdf/ref/83 - osl - normalizeddiff.png differ diff --git a/sandbox/tests/test scenes/osl/ref/01 - lambertian osl - ptne.png b/sandbox/tests/test scenes/osl/ref/01 - lambertian osl - ptne.png index a5251a9d07..5df9e049ce 100644 Binary files a/sandbox/tests/test scenes/osl/ref/01 - lambertian osl - ptne.png and b/sandbox/tests/test scenes/osl/ref/01 - lambertian osl - ptne.png differ diff --git a/sandbox/tests/test scenes/osl/ref/02 - simple glass.png b/sandbox/tests/test scenes/osl/ref/02 - simple glass.png index bf8e663034..22308b42f1 100644 Binary files a/sandbox/tests/test scenes/osl/ref/02 - simple glass.png and b/sandbox/tests/test scenes/osl/ref/02 - simple glass.png differ diff --git a/sandbox/tests/test scenes/osl/ref/03 - glass absorption.png b/sandbox/tests/test scenes/osl/ref/03 - glass absorption.png index 2bee79ee89..da924f70c9 100644 Binary files a/sandbox/tests/test scenes/osl/ref/03 - glass absorption.png and b/sandbox/tests/test scenes/osl/ref/03 - glass absorption.png differ diff --git a/sandbox/tests/test scenes/osl/ref/04 - transparency.png b/sandbox/tests/test scenes/osl/ref/04 - transparency.png index 6aa6679a1c..07a1f1a75a 100644 Binary files a/sandbox/tests/test scenes/osl/ref/04 - transparency.png and b/sandbox/tests/test scenes/osl/ref/04 - transparency.png differ diff --git a/sandbox/tests/test scenes/osl/ref/05 - object space.png b/sandbox/tests/test scenes/osl/ref/05 - object space.png index df5b1ce0ea..e6be3caf65 100644 Binary files a/sandbox/tests/test scenes/osl/ref/05 - object space.png and b/sandbox/tests/test scenes/osl/ref/05 - object space.png differ diff --git a/sandbox/tests/test scenes/osl/ref/06 - closure mix.png b/sandbox/tests/test scenes/osl/ref/06 - closure mix.png index bb84bd8e2a..cfcdf248fa 100644 Binary files a/sandbox/tests/test scenes/osl/ref/06 - closure mix.png and b/sandbox/tests/test scenes/osl/ref/06 - closure mix.png differ diff --git a/sandbox/tests/test scenes/osl/ref/08 - point velocity.png b/sandbox/tests/test scenes/osl/ref/08 - point velocity.png index ab91f90177..8279db9986 100644 Binary files a/sandbox/tests/test scenes/osl/ref/08 - point velocity.png and b/sandbox/tests/test scenes/osl/ref/08 - point velocity.png differ diff --git a/sandbox/tests/test scenes/osl/ref/09 - simple texture.png b/sandbox/tests/test scenes/osl/ref/09 - simple texture.png index 51fb6172be..8645ea256b 100644 Binary files a/sandbox/tests/test scenes/osl/ref/09 - simple texture.png and b/sandbox/tests/test scenes/osl/ref/09 - simple texture.png differ diff --git a/sandbox/tests/test scenes/osl/ref/10 - transparent shadows opaque obj.png b/sandbox/tests/test scenes/osl/ref/10 - transparent shadows opaque obj.png index d746a2311c..2bbd559531 100644 Binary files a/sandbox/tests/test scenes/osl/ref/10 - transparent shadows opaque obj.png and b/sandbox/tests/test scenes/osl/ref/10 - transparent shadows opaque obj.png differ diff --git a/sandbox/tests/test scenes/osl/ref/12 - surface area - ptne.png b/sandbox/tests/test scenes/osl/ref/12 - surface area - ptne.png index 6e1533e3d3..d1cb32e100 100644 Binary files a/sandbox/tests/test scenes/osl/ref/12 - surface area - ptne.png and b/sandbox/tests/test scenes/osl/ref/12 - surface area - ptne.png differ diff --git a/sandbox/tests/test scenes/osl/ref/13 - point velocity moving assembly.png b/sandbox/tests/test scenes/osl/ref/13 - point velocity moving assembly.png index ceaf0a70f0..1e51286afa 100644 Binary files a/sandbox/tests/test scenes/osl/ref/13 - point velocity moving assembly.png and b/sandbox/tests/test scenes/osl/ref/13 - point velocity moving assembly.png differ diff --git a/sandbox/tests/test scenes/osl/ref/14 - matrix param.png b/sandbox/tests/test scenes/osl/ref/14 - matrix param.png index 87f38600bb..df5e1601a5 100644 Binary files a/sandbox/tests/test scenes/osl/ref/14 - matrix param.png and b/sandbox/tests/test scenes/osl/ref/14 - matrix param.png differ diff --git a/sandbox/tests/test scenes/osl/ref/15 - bump noise2d.png b/sandbox/tests/test scenes/osl/ref/15 - bump noise2d.png index 8df01703d4..c17d5420e9 100644 Binary files a/sandbox/tests/test scenes/osl/ref/15 - bump noise2d.png and b/sandbox/tests/test scenes/osl/ref/15 - bump noise2d.png differ diff --git a/sandbox/tests/test scenes/osl/ref/16 - rough glass.png b/sandbox/tests/test scenes/osl/ref/16 - rough glass.png index bb31b47246..6093202e2b 100644 Binary files a/sandbox/tests/test scenes/osl/ref/16 - rough glass.png and b/sandbox/tests/test scenes/osl/ref/16 - rough glass.png differ diff --git a/sandbox/tests/test scenes/osl/ref/17 - bump texture.png b/sandbox/tests/test scenes/osl/ref/17 - bump texture.png index a57b4d4aa5..3f708c18cf 100644 Binary files a/sandbox/tests/test scenes/osl/ref/17 - bump texture.png and b/sandbox/tests/test scenes/osl/ref/17 - bump texture.png differ diff --git a/sandbox/tests/test scenes/osl/ref/18 - bump noise3d.png b/sandbox/tests/test scenes/osl/ref/18 - bump noise3d.png index 9725140f05..74d5a4d4e8 100644 Binary files a/sandbox/tests/test scenes/osl/ref/18 - bump noise3d.png and b/sandbox/tests/test scenes/osl/ref/18 - bump noise3d.png differ diff --git a/sandbox/tests/test scenes/osl/ref/19 - bump noise2d diffuse only.png b/sandbox/tests/test scenes/osl/ref/19 - bump noise2d diffuse only.png index 90e6691fe0..100a1e7021 100644 Binary files a/sandbox/tests/test scenes/osl/ref/19 - bump noise2d diffuse only.png and b/sandbox/tests/test scenes/osl/ref/19 - bump noise2d diffuse only.png differ diff --git a/sandbox/tests/test scenes/osl/ref/20 - appleseed osl texture match.png b/sandbox/tests/test scenes/osl/ref/20 - appleseed osl texture match.png index e52618fb3d..928ae10ff6 100644 Binary files a/sandbox/tests/test scenes/osl/ref/20 - appleseed osl texture match.png and b/sandbox/tests/test scenes/osl/ref/20 - appleseed osl texture match.png differ diff --git a/sandbox/tests/test scenes/osl/ref/21 - appleseed osl translucent match.png b/sandbox/tests/test scenes/osl/ref/21 - appleseed osl translucent match.png index 328410f8b5..a71c3f30da 100644 Binary files a/sandbox/tests/test scenes/osl/ref/21 - appleseed osl translucent match.png and b/sandbox/tests/test scenes/osl/ref/21 - appleseed osl translucent match.png differ diff --git a/sandbox/tests/test scenes/osl/ref/23 - osl derivatives.png b/sandbox/tests/test scenes/osl/ref/23 - osl derivatives.png index bde8e0a59d..abd482dfde 100644 Binary files a/sandbox/tests/test scenes/osl/ref/23 - osl derivatives.png and b/sandbox/tests/test scenes/osl/ref/23 - osl derivatives.png differ diff --git a/sandbox/tests/test scenes/osl/ref/24 - osl bump pt nee.png b/sandbox/tests/test scenes/osl/ref/24 - osl bump pt nee.png index 5217818d40..57a3ba9784 100644 Binary files a/sandbox/tests/test scenes/osl/ref/24 - osl bump pt nee.png and b/sandbox/tests/test scenes/osl/ref/24 - osl bump pt nee.png differ diff --git a/src/appleseed.shaders/CMakeLists.txt b/src/appleseed.shaders/CMakeLists.txt index cb20413d23..a5524bce0a 100644 --- a/src/appleseed.shaders/CMakeLists.txt +++ b/src/appleseed.shaders/CMakeLists.txt @@ -138,17 +138,6 @@ source_group ("include\\appleseed\\pattern" FILES ${include_appleseed_pattern_sources} ) -set (include_alshaders_sources - include/alshaders/remap.h - include/alshaders/space.h -) -list (APPEND osl_headers - ${include_alshaders_sources} -) -source_group ("include\\alshaders" FILES - ${include_alshaders_sources} -) - #-------------------------------------------------------------------------------------------------- # Source files. @@ -385,35 +374,6 @@ source_group ("src\\maya" FILES ${src_maya_sources} ) -set (src_alshaders_sources - #src/alshaders/alBlackbody.osl - #src/alshaders/alCellNoise.osl - src/alshaders/alColorSpace.osl - src/alshaders/alCombineColor.osl - src/alshaders/alCombineFloat.osl - #src/alshaders/alCurvature.osl - #src/alshaders/alFlake.osl - src/alshaders/alFlowNoise.osl - src/alshaders/alFractal.osl - src/alshaders/alJitterColor.osl - src/alshaders/alLayerColor.osl - src/alshaders/alLayerFloat.osl - src/alshaders/alLayer.osl - src/alshaders/alPattern.osl - src/alshaders/alRemapColor.osl - src/alshaders/alRemapFloat.osl - src/alshaders/alSurface.osl - src/alshaders/alSwitchColor.osl - src/alshaders/alSwitchFloat.osl - #src/alshaders/alTriplanar.osl -) -list (APPEND osl_sources - ${src_alshaders_sources} -) -source_group ("src\\alshaders" FILES - ${src_alshaders_sources} -) - set (src_appleseed_sources src/appleseed/asDisneyMaterial.osl src/appleseed/asGlass.osl diff --git a/src/appleseed.shaders/include/alshaders/noise.h b/src/appleseed.shaders/include/alshaders/noise.h deleted file mode 100644 index d0f20a74f6..0000000000 --- a/src/appleseed.shaders/include/alshaders/noise.h +++ /dev/null @@ -1,367 +0,0 @@ - -/* srdnoise23, Simplex noise with rotating gradients - * and a true analytic derivative in 2D and 3D. - * - * This is version 2 of srdnoise23 written in early 2008. - * A stupid bug was corrected. Do not use earlier versions. - * - * Author: Stefan Gustavson, 2003-2008 - * - * Contact: stefan.gustavson@gmail.com - */ - - /* -This code was GPL licensed until February 2011. -As the original author of this code, I hereby -release it irrevocably into the public domain. -Please feel free to use it for whatever you want. -Credit is appreciated where appropriate, and I also -appreciate being told where this code finds any use, -but you may do as you like. Alternatively, if you want -to have a familiar OSI-approved license, you may use -This code under the terms of the MIT license: - -Copyright (C) 2003-2005 by Stefan Gustavson. All rights reserved. -This code is licensed to you under the terms of the MIT license: - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ALSHADERS_OSL_NOISE_H -#define ALSHADERS_OSL_NOISE_H - -/** \file - \brief C implementation of Perlin simplex noise with rotating - gradients and analytic derivative over 2 and 3 dimensions. - \author Stefan Gustavson (stefan.gustavson@gmail.com) -*/ - -/* - * This is an implementation of Perlin "simplex noise" over two dimensions - * (x,y) and three dimensions (x,y,z). One extra parameter 't' rotates the - * underlying gradients of the grid, which gives a swirling, flow-like - * motion. The derivative is returned, to make it possible to do pseudo- - * advection and implement "flow noise", as presented by Ken Perlin and - * Fabrice Neyret at Siggraph 2001. - * - * When not animated and presented in one octave only, this noise - * looks exactly the same as the plain version of simplex noise. - * It's nothing magical by itself, although the extra animation - * parameter 't' is useful. Fun stuff starts to happen when you - * do fractal sums of several octaves, with different rotation speeds - * and an advection of smaller scales by larger scales (or even the - * other way around it you feel adventurous). - * - * The gradient rotations that can be performed by this noise function - * and the true analytic derivatives are required to do flow noise. - * You can't do it properly with regular Perlin noise. - * - */ - -/* a = sqrt(2)/sqrt(3) = 0.816496580 */ -#define a 0.81649658 - -/* Skewing factors for 3D simplex grid: -* F3 = 1/3 -* G3 = 1/6 */ -#define F3 0.333333333 -#define G3 0.166666667 - -float srdnoise3( - float x, - float y, - float z, - float angle, - output float dnoise_dx, - output float dnoise_dy, - output float dnoise_dz) -{ - /* - * Gradient tables. These could be programmed the Ken Perlin way with - * some clever bit-twiddling, but this is more clear, and not really slower. - * - * For 3D, we define two orthogonal vectors in the desired rotation plane. - * These vectors are based on the midpoints of the 12 edges of a cube, - * they all rotate in their own plane and are never coincident or collinear. - * A larger array of random vectors would also do the job, but these 12 - * (including 4 repeats to make the array length a power of two) work better. - * They are not random, they are carefully chosen to represent a small - * isotropic set of directions for any rotation angle. - */ - float grad3u[48] = - { - 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, // 12 cube edges - -1.0, 0.0, 1.0, 0.0, -1.0, 1.0, - 1.0, 0.0, -1.0, 0.0, 1.0, -1.0, - -1.0, 0.0, -1.0, 0.0, -1.0, -1.0, - a, a, a, -a, a, -a, - -a, -a, a, a, -a, -a, - -a, a, a, a, -a, a, - a, -a, -a, -a, a, -a - }; - - float grad3v[48] = - { - -a, a, a, -a, -a, a, - a, -a, a, a, a, a, - -a, -a, -a, a, -a, -a, - a, a, -a, -a, a, -a, - 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, - -1.0, 1.0, 0.0, -1.0, -1.0, 0.0, - 1.0, 0.0, 1.0, -1.0, 0.0, 1.0, // 4 repeats to make 16 - 0.0, 1.0, -1.0, 0.0, -1.0, -1.0 - }; - - int perm[512] = - { - 110, 43, 157, 38, 11, 85, 117, 192, 115, 149, 77, 86, 185, 31, 129, 95, 1, 147, 217, 173, 107, 196, 213, 241, 106, 10, 178, 203, 204, 15, 199, 252, 0, 37, 183, 205, 131, 29, 119, 103, 187, 76, 170, 133, 40, 74, 197, 231, 186, 87, 39, 47, 46, 25, 150, 232, 240, 249, 81, 206, 24, 175, 201, 101, 135, 112, 243, 79, 198, 35, 126, 68, 114, 53, 59, 78, 242, 177, 202, 144, 16, 14, 219, 211, 100, 143, 80, 60, 58, 208, 105, 26, 124, 6, 9, 23, 237, 8, 155, 180, 190, 250, 94, 122, 174, 57, 220, 70, 45, 30, 28, 121, 49, 195, 4, 248, 66, 17, 90, 113, 154, 134, 215, 153, 216, 88, 168, 127, 230, 137, 228, 254, 71, 246, 7, 156, 63, 98, 182, 224, 128, 64, 21, 251, 167, 200, 161, 91, 244, 152, 2, 104, 12, 34, 96, 54, 111, 226, 20, 108, 239, 247, 33, 44, 120, 42, 179, 52, 172, 207, 235, 83, 18, 146, 191, 222, 125, 48, 92, 82, 5, 102, 181, 19, 56, 233, 176, 61, 238, 109, 89, 132, 118, 223, 141, 163, 193, 229, 142, 234, 227, 55, 51, 194, 171, 93, 245, 145, 188, 130, 189, 27, 255, 69, 140, 97, 67, 169, 214, 253, 184, 164, 138, 3, 212, 75, 139, 218, 225, 165, 236, 166, 148, 36, 84, 62, 32, 160, 72, 221, 210, 209, 136, 73, 13, 50, 162, 22, 158, 116, 123, 41, 159, 151, 65, 99, - 110, 43, 157, 38, 11, 85, 117, 192, 115, 149, 77, 86, 185, 31, 129, 95, 1, 147, 217, 173, 107, 196, 213, 241, 106, 10, 178, 203, 204, 15, 199, 252, 0, 37, 183, 205, 131, 29, 119, 103, 187, 76, 170, 133, 40, 74, 197, 231, 186, 87, 39, 47, 46, 25, 150, 232, 240, 249, 81, 206, 24, 175, 201, 101, 135, 112, 243, 79, 198, 35, 126, 68, 114, 53, 59, 78, 242, 177, 202, 144, 16, 14, 219, 211, 100, 143, 80, 60, 58, 208, 105, 26, 124, 6, 9, 23, 237, 8, 155, 180, 190, 250, 94, 122, 174, 57, 220, 70, 45, 30, 28, 121, 49, 195, 4, 248, 66, 17, 90, 113, 154, 134, 215, 153, 216, 88, 168, 127, 230, 137, 228, 254, 71, 246, 7, 156, 63, 98, 182, 224, 128, 64, 21, 251, 167, 200, 161, 91, 244, 152, 2, 104, 12, 34, 96, 54, 111, 226, 20, 108, 239, 247, 33, 44, 120, 42, 179, 52, 172, 207, 235, 83, 18, 146, 191, 222, 125, 48, 92, 82, 5, 102, 181, 19, 56, 233, 176, 61, 238, 109, 89, 132, 118, 223, 141, 163, 193, 229, 142, 234, 227, 55, 51, 194, 171, 93, 245, 145, 188, 130, 189, 27, 255, 69, 140, 97, 67, 169, 214, 253, 184, 164, 138, 3, 212, 75, 139, 218, 225, 165, 236, 166, 148, 36, 84, 62, 32, 160, 72, 221, 210, 209, 136, 73, 13, 50, 162, 22, 158, 116, 123, 41, 159, 151, 65, 99 - }; - - void gradrot3( - int hash, - float sin_t, - float cos_t, - output float gx, - output float gy, - output float gz) - { - int h = hash & 15; - float gux = grad3u[h * 3 + 0]; - float guy = grad3u[h * 3 + 1]; - float guz = grad3u[h * 3 + 2]; - float gvx = grad3v[h * 3 + 0]; - float gvy = grad3v[h * 3 + 1]; - float gvz = grad3v[h * 3 + 2]; - gx = cos_t * gux + sin_t * gvx; - gy = cos_t * guy + sin_t * gvy; - gz = cos_t * guz + sin_t * gvz; - } - - float graddotp3(float gx, float gy, float gz, float x, float y, float z) - { - return gx * x + gy * y + gz * z; - } - - float n0, n1, n2, n3; /* Noise contributions from the four simplex corners */ - float noise; /* Return value */ - float gx0, gy0, gz0, gx1, gy1, gz1; /* Gradients at simplex corners */ - float gx2, gy2, gz2, gx3, gy3, gz3; - float sin_t, cos_t; /* Sine and cosine for the gradient rotation angle */ - sin_t = sin(angle); - cos_t = cos(angle); - - /* Skew the input space to determine which simplex cell we're in */ - float s = (x + y + z) * F3; /* Very nice and simple skew factor for 3D */ - float xs = x + s; - float ys = y + s; - float zs = z + s; - int i = int(floor(xs)); - int j = int(floor(ys)); - int k = int(floor(zs)); - - float t = (i + j + k) * G3; - float X0 = i - t; /* Unskew the cell origin back to (x,y,z) space */ - float Y0 = j - t; - float Z0 = k - t; - float x0 = x - X0; /* The x,y,z distances from the cell origin */ - float y0 = y - Y0; - float z0 = z - Z0; - - /* For the 3D case, the simplex shape is a slightly irregular tetrahedron. - * Determine which simplex we are in. */ - int i1, j1, k1; /* Offsets for second corner of simplex in (i,j,k) coords */ - int i2, j2, k2; /* Offsets for third corner of simplex in (i,j,k) coords */ - - /* TODO: This code would benefit from a backport from the GLSL version! */ - if(x0 >= y0) - { - if(y0 >= z0) - { - i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; /* X Y Z order */ - } - else if(x0 >= z0) - { - i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; /* X Z Y order */ - } - else - { - i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; /* Z X Y order */ - } - } - else // x0 < y0 - { - if(y0 < z0) - { - i1 = 0; j1 = 0; k1 = 1; i2 = 0; j2 = 1; k2 = 1; /* Z Y X order */ - } - else if(x0 < z0) - { - i1 = 0; j1 = 1; k1 = 0; i2 = 0; j2 = 1; k2 = 1; /* Y Z X order */ - } - else - { - i1 = 0; j1 = 1; k1 = 0; i2 = 1; j2 = 1; k2 = 0; /* Y X Z order */ - } - } - - /* A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), - * a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and - * a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where - * c = 1/6. */ - - float x1 = x0 - i1 + G3; /* Offsets for second corner in (x,y,z) coords */ - float y1 = y0 - j1 + G3; - float z1 = z0 - k1 + G3; - float x2 = x0 - i2 + 2.0 * G3; /* Offsets for third corner in (x,y,z) coords */ - float y2 = y0 - j2 + 2.0 * G3; - float z2 = z0 - k2 + 2.0 * G3; - float x3 = x0 - 1.0 + 3.0 * G3; /* Offsets for last corner in (x,y,z) coords */ - float y3 = y0 - 1.0 + 3.0 * G3; - float z3 = z0 - 1.0 + 3.0 * G3; - - /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */ - int ii = i % 256; - if (ii < 0) ii = 255 + ii; - - int jj = j % 256; - if (jj < 0) jj = 255 + jj; - - int kk = k % 256; - if (kk < 0) kk = 255 + kk; - - /* Calculate the contribution from the four corners */ - float t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0; - float t20, t40; - - if(t0 < 0.0) - n0 = t0 = t20 = t40 = gx0 = gy0 = gz0 = 0.0; - else - { - int idx = ii + perm[jj + perm[kk]]; - gradrot3(perm[idx], sin_t, cos_t, gx0, gy0, gz0); - t20 = t0 * t0; - t40 = t20 * t20; - n0 = t40 * graddotp3(gx0, gy0, gz0, x0, y0, z0); - } - - float t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1; - float t21, t41; - if(t1 < 0.0) - n1 = t1 = t21 = t41 = gx1 = gy1 = gz1 = 0.0; - else - { - int idx = ii + i1 + perm[jj + j1 + perm[kk + k1]]; - gradrot3(perm[idx], sin_t, cos_t, gx1, gy1, gz1); - t21 = t1 * t1; - t41 = t21 * t21; - n1 = t41 * graddotp3(gx1, gy1, gz1, x1, y1, z1); - } - - float t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2; - float t22, t42; - - if(t2 < 0.0) - n2 = t2 = t22 = t42 = gx2 = gy2 = gz2 = 0.0; - else - { - int idx = ii + i2 + perm[jj + j2 + perm[kk + k2]]; - gradrot3(perm[idx], sin_t, cos_t, gx2, gy2, gz2); - t22 = t2 * t2; - t42 = t22 * t22; - n2 = t42 * graddotp3(gx2, gy2, gz2, x2, y2, z2); - } - - float t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3; - float t23, t43; - - if(t3 < 0.0) - n3 = t3 = t23 = t43 = gx3 = gy3 = gz3 = 0.0; - else - { - int idx = ii + 1 + perm[jj + 1 + perm[kk + 1]]; - gradrot3(perm[idx], sin_t, cos_t, gx3, gy3, gz3); - t23 = t3 * t3; - t43 = t23 * t23; - n3 = t43 * graddotp3(gx3, gy3, gz3, x3, y3, z3); - } - - /* Add contributions from each corner to get the final noise value. - * The result is scaled to return values in the range [-1,1] */ - noise = 28.0 * (n0 + n1 + n2 + n3); - - /* Compute derivatives */ - /* A straight, unoptimised calculation would be like: - * *dnoise_dx = -8.0 * t20 * t0 * x0 * graddotp3(gx0, gy0, gz0, x0, y0, z0) + t40 * gx0; - * *dnoise_dy = -8.0 * t20 * t0 * y0 * graddotp3(gx0, gy0, gz0, x0, y0, z0) + t40 * gy0; - * *dnoise_dz = -8.0 * t20 * t0 * z0 * graddotp3(gx0, gy0, gz0, x0, y0, z0) + t40 * gz0; - * *dnoise_dx += -8.0 * t21 * t1 * x1 * graddotp3(gx1, gy1, gz1, x1, y1, z1) + t41 * gx1; - * *dnoise_dy += -8.0 * t21 * t1 * y1 * graddotp3(gx1, gy1, gz1, x1, y1, z1) + t41 * gy1; - * *dnoise_dz += -8.0 * t21 * t1 * z1 * graddotp3(gx1, gy1, gz1, x1, y1, z1) + t41 * gz1; - * *dnoise_dx += -8.0 * t22 * t2 * x2 * graddotp3(gx2, gy2, gz2, x2, y2, z2) + t42 * gx2; - * *dnoise_dy += -8.0 * t22 * t2 * y2 * graddotp3(gx2, gy2, gz2, x2, y2, z2) + t42 * gy2; - * *dnoise_dz += -8.0 * t22 * t2 * z2 * graddotp3(gx2, gy2, gz2, x2, y2, z2) + t42 * gz2; - * *dnoise_dx += -8.0 * t23 * t3 * x3 * graddotp3(gx3, gy3, gz3, x3, y3, z3) + t43 * gx3; - * *dnoise_dy += -8.0 * t23 * t3 * y3 * graddotp3(gx3, gy3, gz3, x3, y3, z3) + t43 * gy3; - * *dnoise_dz += -8.0 * t23 * t3 * z3 * graddotp3(gx3, gy3, gz3, x3, y3, z3) + t43 * gz3; - */ - float temp0 = t20 * t0 * graddotp3(gx0, gy0, gz0, x0, y0, z0); - dnoise_dx = temp0 * x0; - dnoise_dy = temp0 * y0; - dnoise_dz = temp0 * z0; - - float temp1 = t21 * t1 * graddotp3(gx1, gy1, gz1, x1, y1, z1); - dnoise_dx += temp1 * x1; - dnoise_dy += temp1 * y1; - dnoise_dz += temp1 * z1; - - float temp2 = t22 * t2 * graddotp3(gx2, gy2, gz2, x2, y2, z2); - dnoise_dx += temp2 * x2; - dnoise_dy += temp2 * y2; - dnoise_dz += temp2 * z2; - - float temp3 = t23 * t3 * graddotp3(gx3, gy3, gz3, x3, y3, z3); - dnoise_dx += temp3 * x3; - dnoise_dy += temp3 * y3; - dnoise_dz += temp3 * z3; - dnoise_dx *= -8.0; - dnoise_dy *= -8.0; - dnoise_dz *= -8.0; - - /* This corrects a bug in the original implementation */ - dnoise_dx += t40 * gx0 + t41 * gx1 + t42 * gx2 + t43 * gx3; - dnoise_dy += t40 * gy0 + t41 * gy1 + t42 * gy2 + t43 * gy3; - dnoise_dz += t40 * gz0 + t41 * gz1 + t42 * gz2 + t43 * gz3; - dnoise_dx *= 28.0; /* Scale derivative to match the noise scaling */ - dnoise_dy *= 28.0; - dnoise_dz *= 28.0; - - return noise; -} - -float srdnoise(point p, float t, output vector deriv) -{ - return srdnoise3(p[0], p[1], p[2], t, deriv[0], deriv[1], deriv[2]); -} - -#undef F3 -#undef G3 -#undef a - -#endif // ALSHADERS_OSL_NOISE_H diff --git a/src/appleseed.shaders/include/alshaders/remap.h b/src/appleseed.shaders/include/alshaders/remap.h deleted file mode 100644 index db26d3f099..0000000000 --- a/src/appleseed.shaders/include/alshaders/remap.h +++ /dev/null @@ -1,181 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -#ifndef ALSHADERS_OSL_REMAP_H -#define ALSHADERS_OSL_REMAP_H - -// Params. -#define REMAP_FLOAT_DECLARE_PARAMS(Page) \ -float RMPinputMin = 0 \ -[[ \ - string label = "Input min", \ - string page = Page \ -]], \ -float RMPinputMax = 1 \ -[[ \ - string label = "Input max", \ - string page = Page \ -]], \ -float RMPcontrast = 1 \ -[[ \ - string label = "Contrast", \ - string page = Page \ -]], \ -float RMPcontrastPivot = 0.5 \ -[[ \ - string label = "Pivot", \ - string page = Page \ -]], \ -float RMPbias = 0.5 \ -[[ \ - string label = "Bias", \ - string page = Page \ -]], \ -float RMPgain = 0.5 \ -[[ \ - string label = "Gain", \ - string page = Page \ -]], \ -float RMPoutputMin = 0 \ -[[ \ - string label = "Output min", \ - string page = Page \ -]], \ -float RMPoutputMax = 1 \ -[[ \ - string label = "Output max", \ - string page = Page \ -]], \ -int RMPclampEnable = 1 \ -[[ \ - string label = "Clamp", \ - string widget = "checkBox", \ - string page = Page \ -]], \ -int RMPthreshold = 0 \ -[[ \ - string label = "Expand", \ - string widget = "checkBox", \ - string page = Page \ -]], \ -float RMPclampMin = 0 \ -[[ \ - string label = "Min", \ - string page = Page \ -]], \ -float RMPclampMax = 1 \ -[[ \ - string label = "Max", \ - string page = Page \ -]] - -struct RemapFloatParams -{ - float inputMin; - float inputMax; - float contrastVal; - float contrastPivot; - float bias; - float gain; - float outputMin; - float outputMax; - int clampEnable; - int expand; - float clampMin; - float clampMax; -}; - -#define REMAP_FLOAT_CREATE \ -{ \ - RMPinputMin, \ - RMPinputMax, \ - RMPcontrast, \ - RMPcontrastPivot, \ - RMPbias, \ - RMPgain, \ - RMPoutputMin, \ - RMPoutputMax, \ - RMPclampEnable, \ - RMPthreshold, \ - RMPclampMin, \ - RMPclampMax \ -} - -float contrast(float input, float c, float pivot) -{ - if (c == 1.0) - return input; - - return (input - pivot) * c + pivot; -} - -float bias(float f, float b) -{ - if (b > 0.0) - return pow(f, log(b) / log(0.5)); - - return 0.0; -} - -float biasandgain(float f, float b, float g) -{ - if (f < 0) - return f; - - if (b != 0.5) - f = bias(f, b); - if (g != 0.5) - { - if (f < 0.5) - f = 0.5 * bias(2.0 * f, 1.0 - g); - else - f = 1.0 - bias(2.0 - 2.0 * f, 1.0 - g) * 0.5; - } - - return f; -} - -float remap(float input, RemapFloatParams p) -{ - float f = (input-p.inputMin) / (p.inputMax-p.inputMin); - f = contrast(f, p.contrastVal, p.contrastPivot); - f = biasandgain(f, p.bias, p.gain); - f = mix(p.outputMin, p.outputMax, f); - - if (p.clampEnable) - { - f = min(p.clampMax, f); - f = max(p.clampMin, f); - - if (p.expand) - f = (f - p.clampMin) / (p.clampMax - p.clampMin); - } - - return f; -} - -#endif diff --git a/src/appleseed.shaders/include/alshaders/space.h b/src/appleseed.shaders/include/alshaders/space.h deleted file mode 100644 index c8f7094cde..0000000000 --- a/src/appleseed.shaders/include/alshaders/space.h +++ /dev/null @@ -1,57 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -#ifndef ALSHADERS_OSL_SPACE_H -#define ALSHADERS_OSL_SPACE_H - -// Constants. -#define SPACE_WORLD 0 -#define SPACE_OBJECT 1 -#define SPACE_PREF 2 -#define SPACE_UV 3 - -// Params. -#define SPACE_DECLARE_PARAMS \ -int in_space = 0 \ -[[ \ - string label = "Space", \ - string widget = "mapper", \ - string options = "world:0|object:1|PRef:2|UV:3", \ - string as_maya_attribute_name = "space" \ -]], \ -point in_p = P \ -[[ \ - string label = "P", \ - string as_maya_attribute_name = "P" \ -]], \ -point Pref = P \ -[[ \ - int lockgeom = 0, \ - string widget = "null" \ -]] - -#endif diff --git a/src/appleseed.shaders/src/alshaders/alBlackbody.osl b/src/appleseed.shaders/src/alshaders/alBlackbody.osl deleted file mode 100644 index bdbad769cf..0000000000 --- a/src/appleseed.shaders/src/alshaders/alBlackbody.osl +++ /dev/null @@ -1,82 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -shader alBlackbody -[[ - string help = "Generates a Rec709 color from the blackbody spectrum for the given temperature.", - string description = "Useful for fire, lava, light colors and any self-illuminated object.", - string as_maya_node_name = "alBlackbody" -]] -( - float in_temperature = 1000 - [[ - string label = "Temperature", - float min = 273, - float max = 16000, - string help = "color. From low to high the spectrum goes through red, orange, yellow, white, blue.", - string as_maya_attribute_name = "temperature" - ]], - float in_strength = 1.0 - [[ - string label = "Strength", - float min = 0, - string help = "Multiplier on the brightness of the generated color.", - string as_maya_attribute_name = "strength" - ]], - float in_physicalIntensity = 1.0 - [[ - string label = "Physical intensity", - string page = "Advanced", - string help = "When set to the default of 1, the full range of physical brightness will be preserved. When set to 0, the generated colors will never be brighter than white. When set to a value in between, the brightness will be lerped between the two.", - string as_maya_attribute_name = "physicalIntensity" - ]], - float in_physicalExposure = -20.0 - [[ - string label = "Physical exposure", - string page = "Advanced", - string help = "An overall exposure value to apply to the color. This is useful to preserve the physical brightness curve but get low-temperature colors into a sensible range.", - string as_maya_attribute_name = "physicalExposure" - ]], - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - out_result = blackbody(in_temperature); - - if (in_physicalIntensity > 0) - { - out_result *= mix( - 1, - pow(in_temperature, 4) * 5.67e-8 * pow(2, in_physicalExposure), - in_physicalIntensity); - } - - out_result *= in_strength; -} diff --git a/src/appleseed.shaders/src/alshaders/alCellNoise.osl b/src/appleseed.shaders/src/alshaders/alCellNoise.osl deleted file mode 100644 index 230ca6f90b..0000000000 --- a/src/appleseed.shaders/src/alshaders/alCellNoise.osl +++ /dev/null @@ -1,192 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -#include "alshaders/remap.h" -#include "alshaders/space.h" - -#include "appleseed/fractal/as_fractal_helpers.h" - -shader alCellNoise -[[ - string help = "Cell noise pattern generator.", - string description = "Fractal cell noise with support for both distance-based effects and chips can be useful for a variety of procedural effects.", - string as_maya_node_name = "alCellNoise" -]] -( - SPACE_DECLARE_PARAMS, - float in_frequency = 1 - [[ - string label = "Frequency", - string as_maya_attribute_name = "frequency", - string help = "Frequency of the noise pattern. Larger numbers make it smaller, lower numbers make it bigger." - ]], - int in_mode = 0 - [[ - string label = "Mode", - string help = "Features allows you to measure the distance to features to create veiny textures, chips simply puts a random color in each block.", - string widget = "mapper", - string options = "features:0|chips:1", - string as_maya_attribute_name = "mode" - ]], - float in_randomness = 1 - [[ - string label = "Randomness", - string help = "How much randomness is added to the cel positions.", - string as_maya_attribute_name = "randomness" - ]], - int in_octaves = 1 - [[ - string label = "Octaves", - string help = "Number of octaves to calculate. Higher numbers give more detail but take longer to compute.", - string page = "Features", - string as_maya_attribute_name = "octaves" - ]], - float in_lacunarity = 2.121 - [[ - string label = "Lacunarity", - string help = "How much the frequency is increased with each octave.", - string page = "Features", - string as_maya_attribute_name = "lacunarity" - ]], - color in_color1 = color(0) - [[ - string label = "Color 1", - string help = "Color to use when the noise result is 0.", - string as_maya_attribute_name = "color1" - ]], - color in_color2 = color(0) - [[ - string label = "Color 2", - string help = "Color to use when the noise result is 1.", - string as_maya_attribute_name = "color2" - ]], - int in_smoothChips = 0 - [[ - string label = "Smooth", - string help = "Smooth the chip colors.", - string page = "Chips", - string widget = "checkBox", - string as_maya_attribute_name = "smoothChips" - ]], - int in_randomChips = 0 - [[ - string label = "Randomize", - string help = "Give each chip a randomly-generated color.", - string page = "Chips", - string widget = "checkBox", - string as_maya_attribute_name = "randomChips" - ]], - color in_chipColor1 = color(.383, .318, .252) - [[ - string label = "Chip color 1", - string help = "Color of the first set of chips", - string page = "Chips", - string as_maya_attribute_name = "chipColor1" - ]], - float in_chipProb1 = 1.0 - [[ - string label = "Chip probability 1", - string help = "Probability of the cell being the first color.", - string page = "Chips", - string as_maya_attribute_name = "chipProb1" - ]], - color in_chipColor2 = color(.383, .191, .010) - [[ - string label = "Chip color 2", - string help = "Color of the second set of chips", - string page = "Chips", - string as_maya_attribute_name = "chipColor2" - ]], - float in_chipProb2 = 1.0 - [[ - string label = "Chip probability 2", - string help = "Probability of the cell being the second color.", - string page = "Chips", - string as_maya_attribute_name = "chipProb2" - ]], - color in_chipColor3 = color(.635, .612, .563) - [[ - string label = "Chip color 3", - string help = "Color of the third set of chips", - string page = "Chips", - string as_maya_attribute_name = "chipColor3" - ]], - float in_chipProb3 = 1.0 - [[ - string label = "Chip probability 3", - string help = "Probability of the cell being the third color.", - string page = "Chips", - string as_maya_attribute_name = "chipProb3" - ]], - color in_chipColor4 = color(.509, .361, .213) - [[ - string label = "Chip color 4", - string help = "Color of the fourth set of chips", - string page = "Chips", - string as_maya_attribute_name = "chipColor4" - ]], - float in_chipProb4 = 1.0 - [[ - string label = "Chip probability 4", - string help = "Probability of the cell being the fourth color.", - string page = "Chips", - string as_maya_attribute_name = "chipProb4" - ]], - color in_chipColor5 = color(.593, .472, .248) - [[ - string label = "Chip color 5", - string help = "Color of the fifth set of chips", - string page = "Chips", - string as_maya_attribute_name = "chipColor5" - ]], - float in_chipProb5 = 1.0 - [[ - string label = "Chip probability 5", - string help = "Probability of the cell being the fifth color.", - string page = "Chips", - string as_maya_attribute_name = "chipProb5" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - output color out_result = color(0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - point pp; - if (in_space == SPACE_WORLD) - pp = in_p; - else if (in_space == SPACE_OBJECT) - pp = transform("object", in_p); - else if (in_space == SPACE_PREF) - pp = Pref; - else if (in_space == SPACE_UV) - pp = point(u, v, 0); - - // todo: implement me... -} diff --git a/src/appleseed.shaders/src/alshaders/alColorSpace.osl b/src/appleseed.shaders/src/alshaders/alColorSpace.osl deleted file mode 100644 index dd8ff5af15..0000000000 --- a/src/appleseed.shaders/src/alshaders/alColorSpace.osl +++ /dev/null @@ -1,113 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -// Constants. -#define SRGB 0 -#define CINEON 1 -#define LOGC 2 - -// Utilities. -float sRgbToLin(float c) -{ - if (c > 1.0) - return c; - else if (c <= 0.04045) - return c / 12.92; - else - return pow((c + 0.055) / 1.055, 2.4); -} - -color sRgbToLin(color c) -{ - return color(sRgbToLin(c[0]), sRgbToLin(c[1]), sRgbToLin(c[2])); -} - -float cineonToLin(float c) -{ - float RefWhite = 685.0; - float RefBlack = 95.0; - c *= 1023.0; - float Gain = 1.0 / (1.0 - pow(10.0, (RefBlack - RefWhite) * 0.002 / 0.6)); - float Offset = Gain - 1.0; - c = pow(10.0, (c - RefWhite) * 0.002 / 0.6) * Gain - Offset; - return max(0.0, c); -} - -color cineonToLin(color c) -{ - return color(cineonToLin(c[0]), cineonToLin(c[1]), cineonToLin(c[2])); -} - -float logCToLin(float c) -{ - if (c > 0.1496582) - return (pow(10.0, (c - 0.385537) / 0.2471896) - 0.052272) / 5.555556; - else - return (c - 0.092809) / 5.367655; -} - -color logCToLin(color c) -{ - return color(logCToLin(c[0]), logCToLin(c[1]), logCToLin(c[2])); -} - - -shader alColorSpace -[[ - string help = "Simple color-space transforms.", - string description = "Converts a color to linear Rec.709 from a given color space.", - string as_maya_node_name = "alColorSpace" -]] -( - color in_input = color(0) - [[ - string label = "Input", - string help = "Color to be transformed.", - string as_maya_attribute_name = "input" - ]], - int in_sourceSpace = 0 - [[ - string label = "Source space", - string widget = "mapper", - string options = "sRGB:0|Cineon:1|LogC:2", - string help = "Source color space. The input will be transformed from this space to linear Rec.709.", - string as_maya_attribute_name = "sourceSpace" - ]], - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - if (in_sourceSpace == SRGB) - out_result = sRgbToLin(in_input); - else if (in_sourceSpace == CINEON) - out_result = cineonToLin(in_input); - else if (in_sourceSpace == LOGC) - out_result = logCToLin(in_input); -} diff --git a/src/appleseed.shaders/src/alshaders/alCombineColor.osl b/src/appleseed.shaders/src/alshaders/alCombineColor.osl deleted file mode 100644 index 6eae96e370..0000000000 --- a/src/appleseed.shaders/src/alshaders/alCombineColor.osl +++ /dev/null @@ -1,106 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -// Constants -#define MULTIPLY 0 -#define ADD 1 -#define DIVIDE 2 -#define SUBTRACT 3 -#define LERP 4 -#define DOT 5 -#define DISTANCE 6 -#define CROSS 7 - -shader alCombineColor -[[ - string help = "Combine two colors together.", - string description = "Simple mathematical operations for combining colors: multiplication, addition, division, subtraction and interpolation.", - string as_maya_node_name = "alCombineColor" -]] -( - color in_input1 = color(0) - [[ - string label = "Input 1", - string as_maya_attribute_name = "input1" - ]], - color in_input2 = color(1) - [[ - string label = "Input 2", - string as_maya_attribute_name = "input2" - ]], - float in_input3 = 0 - [[ - string label = "Input 3", - string as_maya_attribute_name = "input3" - ]], - int in_combineOp = 0 - [[ - string label = "Combine Op", - string widget = "mapper", - string options = "multiply 1*2:0|add 1+2:1|divide 1/2:2|subtract 1-2:3|lerp(1, 2, 3):4|dot(1, 2):5|distance(1 -> 2):6|cross(1, 2):7", - string as_maya_attribute_name = "combineOp" - ]], - output color out_result = color(0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - if (in_combineOp == MULTIPLY) - { - out_result = in_input1 * in_input2; - } - else if (in_combineOp == ADD) - { - out_result = in_input1 + in_input2; - } - else if (in_combineOp == DIVIDE) - { - out_result = in_input1 / in_input2; - } - else if (in_combineOp == SUBTRACT) - { - out_result = in_input1 - in_input2; - } - else if (in_combineOp == LERP) - { - out_result = mix(in_input1, in_input2, clamp(in_input3, 0.0, 1.0)); - } - else if (in_combineOp == DOT) - { - out_result = dot(in_input1, in_input2); - } - else if (in_combineOp == DISTANCE) - { - out_result = distance(in_input1, in_input2); - } - else if (in_combineOp == CROSS) - { - out_result = cross(in_input1, in_input2); - } -} diff --git a/src/appleseed.shaders/src/alshaders/alCombineFloat.osl b/src/appleseed.shaders/src/alshaders/alCombineFloat.osl deleted file mode 100644 index 0979360322..0000000000 --- a/src/appleseed.shaders/src/alshaders/alCombineFloat.osl +++ /dev/null @@ -1,90 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -// Constants. -#define MULTIPLY 0 -#define ADD 1 -#define DIVIDE 2 -#define SUBTRACT 3 -#define LERP 4 - -shader alCombineFloat -[[ - string help = "Combine two floats together.", - string description = "Simple mathematical operations for combining floats: multiplication, addition, division, subtraction and interpolation.", - string as_maya_node_name = "alCombineFloat" -]] -( - float in_input1 = 0 - [[ - string label = "Input 1", - string as_maya_attribute_name = "input1" - ]], - float in_input2 = 0 - [[ - string label = "Input 2", - string as_maya_attribute_name = "input2" - ]], - float in_input3 = 0 - [[ - string label = "Input 3", - string as_maya_attribute_name = "input3" - ]], - int in_combineOp = 0 - [[ - string label = "Combine Op", - string widget = "mapper", - string options = "multiply 1*2:0|add 1+2:1|divide 1/2:2|subtract 1-2:3|lerp(1, 2, 3):4", - string as_maya_attribute_name = "combineOp" - ]], - output float out_result = 0 - [[ - string as_maya_attribute_name = "outValue" - ]] -) -{ - if (in_combineOp == MULTIPLY) - { - out_result = in_input1 * in_input2; - } - else if (in_combineOp == ADD) - { - out_result = in_input1 + in_input2; - } - else if (in_combineOp == DIVIDE) - { - out_result = in_input1 / in_input2; - } - else if (in_combineOp == SUBTRACT) - { - out_result = in_input1 - in_input2; - } - else if (in_combineOp == LERP) - { - out_result = mix(in_input1, in_input2, clamp(in_input3, 0.0, 1.0)); - } -} diff --git a/src/appleseed.shaders/src/alshaders/alCurvature.osl b/src/appleseed.shaders/src/alshaders/alCurvature.osl deleted file mode 100644 index 4146cb9246..0000000000 --- a/src/appleseed.shaders/src/alshaders/alCurvature.osl +++ /dev/null @@ -1,72 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -#include "alshaders/remap.h" - -shader alCurvature -[[ - string help = "Measure the local curvature of the surface.", - string description = "Can be used to create effects such as stretch maps and dirt maps, or to simulate wear and tear. For best results remap and combine with a noise function then use it to drive layering effects in your surface shader.", - string as_maya_node_name = "alCurvature" -]] -( - int in_mode = 0 - [[ - string label = "Mode", - string help = "Select the type of curvature to output. positive selects convex regions while negative selects concave regions.", - string widget = "mapper", - string options = "positive:0|negative:1", - string as_maya_attribute_name = "mode" - ]], - int in_samples = 3 - [[ - string label = "Samples", - string help = "The sampling rate for the curvature calculation.", - string as_maya_attribute_name = "samples" - ]], - float in_sampleRadius = 1.0 - [[ - string label = "Radius", - string help = "The radius to consider when estimating the curvature. Smaller values pick out finer detail, while larger values give a smoother result.", - string as_maya_attribute_name = "sampleRadius" - ]], - string in_traceSet = "" - [[ - string label = "Trace set", - string help = "Enter a trace set here to restrict the curvature calculation to only consider that set of objects.", - string as_maya_attribute_name = "traceSet" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - // todo: implement me... -} diff --git a/src/appleseed.shaders/src/alshaders/alFlake.osl b/src/appleseed.shaders/src/alshaders/alFlake.osl deleted file mode 100644 index 8ca0735e0a..0000000000 --- a/src/appleseed.shaders/src/alshaders/alFlake.osl +++ /dev/null @@ -1,127 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -// Constants. -#define TANGENT 0 -#define WORLD 1 - -// Utilities. -vector uniformSampleHemisphere(float u1, float u2) -{ - float y = u1; - float r = sqrt(max(0.0, 1.0 - y * y)); - float phi = 2.0 * M_PI * u2; - float x = r * cos(phi); - float z = r * sin(phi); - return vector(x, y, z); -} - -shader alFlake -[[ - string help = "Generate a normal map of randomly-oriented flakes.", - string description = "Useful for car paint shaders, granite and other polished minerals. To use, connect it as a tangent-space normal map to alSurface, making sure Gamma is set 1. Then connect a smooth normal (alInputVector set to Ns) to the Diffuse and Specular 1 Normal parameters. This will use the flake normal for Specular 2 only and the original smooth normal for Diffuse and Specular 1.", - string as_maya_node_name = "alFlake" -]] -( - int in_space = 0 - [[ - string label = "Space", - string help = "Select the space for normal computation. When world is selected you should plug the output of this node directly into the normal override parameter of your desired lobe on alSurface. When tangent is selected you should use this as a tangent-space normal map with the regular Arnold bump shader.", - string widget = "mapper", - string options = "tangent:0|world:1", - string as_maya_attribute_name = "space" - ]], - float in_amount = 0.7 - [[ - string label = "Amount", - string help = "Proportion of the surface that is covered by flakes", - float min = 0.0, - float max = 1.0, - string as_maya_attribute_name = "amount" - ]], - float in_size = 0.01 - [[ - string label = "Size", - string help = "Size of the flakes", - string as_maya_attribute_name = "size" - ]], - float in_divergence = .5 - [[ - string label = "Divergence", - string help = "How much the flake normals diverge from the surface normal.", - float min = 0.0, - float max = 1.0, - string as_maya_attribute_name = "divergence" - ]], - point in_p = point(0) - [[ - string label = "P", - string help = "Connect a point here to override the space used for flake calculation.", - string as_maya_attribute_name = "P" - ]], - vector Tn = vector(0) - [[ - int lockgeom = 0, - string widget = "null" - ]], - vector Bn = vector(0) - [[ - int lockgeom = 0, - string widget = "null" - ]], - output vector out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - // todo: implement me... - - /* - vector result; - float amount = clamp(in_amount, 0, 1); - float divergence = clamp(in_divergence, 0, 1); - point pp = in_p / in_size; - - // TODO: generate a pseudo random number in a smarter way. - vector uu = noise("uperlin", pp); - - if (uu[0] < amount) - { - vector d = uniformSampleHemisphere(uu[1], uu[2]); - - // blend it in. - result = mix(vector(0, 1, 0), d, divergence); - } - - if (in_space == WORLD) - out_result = Tn * result[0] + N * result[1] + Bn * result[2]; - else - out_result = result * 0.5 + vector(0.5); - */ -} diff --git a/src/appleseed.shaders/src/alshaders/alFlowNoise.osl b/src/appleseed.shaders/src/alshaders/alFlowNoise.osl deleted file mode 100644 index 55528a1634..0000000000 --- a/src/appleseed.shaders/src/alshaders/alFlowNoise.osl +++ /dev/null @@ -1,137 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -#include "alshaders/noise.h" -#include "alshaders/remap.h" -#include "alshaders/space.h" - -shader alFlowNoise -[[ - string help = "Flow noise pattern generator", - string description = "Useful for creating noise patterns that feel similar to fluid flows.", - string as_maya_node_name = "alFlowNoise" -]] -( - SPACE_DECLARE_PARAMS, - float in_frequency = 1.0 - [[ - string label ="Frequency", - string help = "Frequency of the noise pattern. Larger numbers make it smaller, lower numbers make it bigger.", - string as_maya_attribute_name = "frequency" - ]], - int in_octaves = 4 - [[ - string label ="Octaves", - string help = "Number of octaves to calculate. Higher numbers give more detail but take longer to compute.", - string as_maya_attribute_name = "octaves" - ]], - float in_lacunarity = 2.172 - [[ - string label ="Lacunarity", - string help = "How much the frequency is increased with each octave.", - string as_maya_attribute_name = "lacunarity" - ]], - float in_gain = 0.5 - [[ - string label ="Gain", - string help = "How much the intensity of the noise is scaled with each object.", - string as_maya_attribute_name = "gain" - ]], - float in_angle = 0.0 - [[ - string label ="Angle", - string help = "Animate this to control the rolling motion of the noise.", - string as_maya_attribute_name = "angle" - ]], - float in_advection = 0.25 - [[ - string label ="Advection", - string help = "Controls how much the smaller noise features are swept along with the larger ones.", - string as_maya_attribute_name = "advection" - ]], - int in_turbulent = 0 - [[ - string label ="Turbulent", - string help = "Enable this to switch from fBM to Turbulent noise.", - string widget = "checkBox", - string as_maya_attribute_name = "turbulent" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - color in_color1 = 0 - [[ - string label = "Color 1", - string help = "Color to use when the noise value is 0.", - string as_maya_attribute_name = "color1" - ]], - color in_color2 = 1 - [[ - string label = "Color 2", - string help = "Color to use when the noise value is 1.", - string as_maya_attribute_name = "color2" - ]], - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - point pp; - if (in_space == SPACE_WORLD) - pp = in_p; - else if (in_space == SPACE_OBJECT) - pp = transform("object", in_p); - else if (in_space == SPACE_PREF) - pp = Pref; - else if (in_space == SPACE_UV) - pp = point(u, v, 0); - - pp *= in_frequency; - - float n; - float g = 1.0; - float result = 0.0; - vector deriv; - vector advect = 0; - - for (int i = 0; i < in_octaves; ++i) - { - n = srdnoise(pp + advect, in_angle, deriv); - - if (in_turbulent) - n = abs(n); - - result += n * g; - advect -= deriv * in_advection * g; - pp *= in_lacunarity; - g *= in_gain; - } - - RemapFloatParams rmp = REMAP_FLOAT_CREATE; - result = remap(result, rmp); - out_result = mix(in_color1, in_color2, result); -} diff --git a/src/appleseed.shaders/src/alshaders/alFractal.osl b/src/appleseed.shaders/src/alshaders/alFractal.osl deleted file mode 100644 index a5ece717e1..0000000000 --- a/src/appleseed.shaders/src/alshaders/alFractal.osl +++ /dev/null @@ -1,182 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -#include "alshaders/remap.h" -#include "alshaders/space.h" - -// Constants. -#define SCALAR_MODE 0 -#define VECTOR_MODE 1 - -shader alFractal -[[ - string as_maya_node_name = "alFractal" -]] -( - int in_mode = 0 - [[ - string widget = "mapper", - string options = "scalar:0|vector:1", - string as_maya_attribute_name = "mode" - ]], - SPACE_DECLARE_PARAMS, - float in_frequency = 1 - [[ - string label = "Frequency", - string help = "Frequency of the noise pattern. Larger numbers make it smaller, lower numbers make it bigger.", - string as_maya_attribute_name = "frequency" - ]], - vector in_scale = vector(1) - [[ - string label = "Scale", - string help = "Scale values of the noise space for each axis. Use this to stretch the noise along a certain direction.", - string as_maya_attribute_name = "scale" - ]], - float in_t = 0 - [[ - string label = "Time", - string help = "4th dimension of the noise. Connect this to a time value to animate the noise.", - string as_maya_attribute_name = "t" - ]], - int in_octaves = 8 - [[ - string label = "Octaves", - string help = "Number of octaves to calculate. Higher numbers give more detail but take longer to compute.", - string as_maya_attribute_name = "octaves" - ]], - float in_distortion = 0 - [[ - string label = "Distortion", - string help = "Apply a random warp to the noise space.", - string as_maya_attribute_name = "distortion" - ]], - float in_lacunarity = 2.121 - [[ - string label = "Lacunarity", - string help = "How much the frequency is increased with each octave.", - string as_maya_attribute_name = "lacunarity" - ]], - float in_gain = 0.5 - [[ - string label = "Gain", - string help = "How much the intensity of the noise is scaled with each object.", - string as_maya_attribute_name = "gain" - ]], - int in_turbulent = 0 - [[ - string widget = "checkBox", - string label = "Turbulent", - string help = "Enable this to switch from fBM to Turbulent noise.", - string as_maya_attribute_name = "turbulent" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - color in_color1 = color(0) - [[ - string label = "Color 1", - string help = "Color to use when the noise result is 0.", - string as_maya_attribute_name = "color1" - ]], - color in_color2 = color(1) - [[ - string label = "Color 2", - string help = "Color to use when the noise result is 1.", - string as_maya_attribute_name = "color2" - ]], - output color out_result = color(0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - point pp; - if (in_space == SPACE_WORLD) - pp = in_p; - else if (in_space == SPACE_OBJECT) - pp = transform("object", in_p); - else if (in_space == SPACE_PREF) - pp = Pref; - else if (in_space == SPACE_UV) - pp = point(u, v, 0); - - pp *= in_scale * in_frequency; - - if (in_mode == SCALAR_MODE) - { - float n = 0; - float amp = 1; - float weight = 1; - float vv; - for (int i=0; i < in_octaves; ++i) - { - if (in_distortion != 0) - { - vector vd = noise("snoise", in_p); - pp += in_distortion * vd; - } - vv = noise("snoise", pp, in_t); - if (in_turbulent) - vv = abs(vv); - - n += vv * amp; - amp *= in_gain; - pp *= in_lacunarity; - } - - RemapFloatParams rmp = REMAP_FLOAT_CREATE; - n = remap(n, rmp); - out_result = mix(in_color1, in_color2, n); - } - else // if (in_mode == VECTOR_MODE) - { - color n = color(0, 0, 0); - float amp = 1.0; - color weight = color(0, 0, 0); - color vv; - for (int i=0; i < in_octaves; ++i) - { - if (in_distortion != 0) - { - vector vd = noise("snoise", in_p); - pp += in_distortion * vd; - } - vv = noise("snoise", pp, in_t); - if (in_turbulent) - vv = abs(vv); - - n += vv * amp; - amp *= in_gain; - pp *= in_lacunarity; - } - - RemapFloatParams rmp = REMAP_FLOAT_CREATE; - n[0] = remap(n[0], rmp); - n[1] = remap(n[1], rmp); - n[2] = remap(n[2], rmp); - out_result = n; - } -} diff --git a/src/appleseed.shaders/src/alshaders/alJitterColor.osl b/src/appleseed.shaders/src/alshaders/alJitterColor.osl deleted file mode 100644 index b6d5648d66..0000000000 --- a/src/appleseed.shaders/src/alshaders/alJitterColor.osl +++ /dev/null @@ -1,121 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -shader alJitterColor -[[ - string as_maya_node_name = "alJitterColor", - string help = "Applies random color variation within a range.", - string description = "Use this in a network attached to multiple objects to add random color variation to each object." -]] -( - color in_input = color(1) - [[ - string label = "Input", - string help = "The input color to be jittered.", - string as_maya_attribute_name = "input" - ]], - float in_minSaturation = 0.0 - [[ - string label = "Min Saturation", - string help = "Minimum random saturation scale to apply.", - string as_maya_attribute_name = "minSaturation" - ]], - float in_maxSaturation = 1.0 - [[ - string label = "Max Saturation", - string help = "Maximum random saturation scale to apply.", - string as_maya_attribute_name = "maxSaturation" - ]], - float in_minHueOffset = -1.0 - [[ - string label = "Min Hue Offset", - string help = "Minimum hue offset to apply.", - string as_maya_attribute_name = "minHueOffset" - ]], - float in_maxHueOffset = 1.0 - [[ - string label = "Max Hue Offset", - string help = "Maximum hue offset to apply.", - string as_maya_attribute_name = "maxHueOffset" - ]], - float in_minGain = 0.0 - [[ - string label = "Min Gain", - string help = "Minimum random gain to apply.", - string as_maya_attribute_name = "minGain" - ]], - float in_maxGain = 1.0 - [[ - string label = "Max Gain", - string help = "Maximum random gain to apply.", - string as_maya_attribute_name = "maxGain" - ]], - float in_clampResult = 1 - [[ - string label = "Clamp", - string help = "If enabled, the output color will be clamped to 0-1.", - string as_maya_attribute_name = "clampResult" - ]], - float in_signal = 0.0 - [[ - string label = "Signal", - string help = "Signal to use to drive the randomization. This wants to be a unique value per object such as the object id.", - string as_maya_attribute_name = "signal" - ]], - output color out_result = color(0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - out_result = in_input; - - float saturation = noise("cell", in_signal, 51731.132151); - saturation = mix(in_minSaturation, in_maxSaturation, saturation); - if (saturation != 1) - { - float l = luminance(out_result); - out_result = mix(color(l), out_result, saturation); - } - - float hueOffset = noise("cell", in_signal, 173.1231); - hueOffset = mix(in_minHueOffset, in_maxHueOffset, hueOffset); - if (hueOffset != 0) - { - color hsv = transformc("hsv", out_result); - hsv[0] += hueOffset; - out_result = transformc("rgb", hsv); - } - - float gain = noise("cell", in_signal, 413.7254); - gain = mix(in_minGain, in_maxGain, gain); - out_result *= gain; - - if (in_clampResult) - out_result = clamp(out_result, color(0), color(1)); -} diff --git a/src/appleseed.shaders/src/alshaders/alLayer.osl b/src/appleseed.shaders/src/alshaders/alLayer.osl deleted file mode 100644 index 03e91b4556..0000000000 --- a/src/appleseed.shaders/src/alshaders/alLayer.osl +++ /dev/null @@ -1,83 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -// Constants. -#define kOff 0 -#define kLayer1 1 -#define kLayer2 2 -#define kMixer 3 - -shader alLayer -[[ - string help = "Layer two shaders together", - string description = "Simply blends two surface shaders, including all their AOVs.", - - string as_maya_node_name = "alLayer" -]] -( - closure color in_layer1 = 0 - [[ - string label = "Layer 1", - string help = "The bottom layer to blend.", - string as_maya_attribute_name = "layer1" - ]], - closure color in_layer2 = 0 - [[ - string label = "Layer 2", - string help = "The top layer to blend.", - string as_maya_attribute_name = "layer2" - ]], - float in_mix = 0.0 - [[ - string label = "Mix", - string help = "The amount to blend from the bottom layer to the top.", - string as_maya_attribute_name = "mix" - ]], - int in_debug = 0 - [[ - string label = "Debug", - string help = "Allows you to quickly preview each layer and the mix value.", - string widget = "mapper", - string options = "off:0|layer1:1|layer2:2|mixer:3", - string as_maya_attribute_name = "debug" - ]], - output closure color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - if (in_debug == kOff) - out_result = mix(in_layer1, in_layer2, in_mix); - else if (in_debug == kLayer1) - out_result = in_layer1; - else if (in_debug == kLayer2) - out_result = in_layer2; - else if (in_debug == kMixer) - out_result = in_mix * emission(); -} diff --git a/src/appleseed.shaders/src/alshaders/alLayerColor.osl b/src/appleseed.shaders/src/alshaders/alLayerColor.osl deleted file mode 100644 index ede1406b0d..0000000000 --- a/src/appleseed.shaders/src/alshaders/alLayerColor.osl +++ /dev/null @@ -1,612 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -// Constants. -#define NORMAL 0 -#define LIGHTEN 1 -#define DARKEN 2 -#define MULTIPLY 3 -#define AVERAGE 4 -#define ADD 5 -#define SUBTRACT 6 -#define DIFFERENCE 7 -#define NEGATION 8 -#define EXCLUSION 9 -#define SCREEN 10 -#define OVERLAY 11 -#define SOFTLIGHT 12 -#define HARDLIGHT 13 -#define COLORDODGE 14 -#define COLORBURN 15 -#define LINEARDODGE 16 -#define LINEARBURN 17 -#define LINEARLIGHT 18 -#define VIVIDLIGHT 19 -#define PINLIGHT 20 -#define HARDMIX 21 -#define REFLECT 22 -#define GLOW 23 -#define PHOENIX 24 - -color overlay(color l1, color l2) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - l1[i] < 0.5 - ? out_result[i] = 2.0 * l1[i] * l2[i] - : out_result[i] = (1.0 - 2.0 * (1.0 - l1[i]) * (1.0 - l2[i])); - } - - return out_result; -} - -color softlight(color l1, color l2) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - if (l2[i] < 0.5) - out_result[i] = 2.0 * l1[i] * l2[i] + (l1[i]*l1[i]) * (1.0 - 2.0 * l2[i]); - else - out_result[i] = sqrt(l1[i]) * (2.0 * l2[i] - 1.0) + 2.0 * l1[i] * (1.0 - l2[i]); - } - - return out_result; -} - -float colordodgef(float l1, float l2, int clamp_result) -{ - float result; - - if (l2 == 1.0) - result = l2; - else - result = min(l1 / (1.0 - l2), 1.0); - - if (clamp_result) - result = min(result, 1.0); - - return result; -} - -color colordodge(color l1, color l2, int clamp_result) -{ - color out_result; - for (int i=0; i < 3; ++i) - out_result[i] = colordodgef(l1[i], l2[i], clamp_result); - - return out_result; -} - -float colorburnf(float l1, float l2) -{ - if (l2 == 0.0) - return l2; - else - return max(1.0 - (1.0 - l1) / l2, 0.0); -} - -color colorburn(color l1, color l2) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - out_result[i] = colorburnf(l1[i], l2[i]); - } - - return out_result; -} - -color linearlight(color l1, color l2, int clamp_result) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - if (l2[i] < 0.5) - out_result[i] = max(l1[i] + 2.0 * l2[i] - 1.0, 0.0); - else - out_result[i] = min(l1[i] + 2.0 * (l2[i] - 0.5), 1.0); - } - - if (clamp_result) - out_result = clamp(out_result, color(0), color(1)); - - return out_result; -} - -color vividlight(color l1, color l2, int clamp_result) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - if (l2[i] < 0.5) - out_result[i] = colorburnf(l1[i], 2.0 * l2[i]); - else - out_result[i] = colordodgef(l1[i], 2.0 * (l2[i] - 0.5), clamp_result); - } - - return out_result; -} - -color pinlight(color l1, color l2) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - if (l2[i] < 0.5) - out_result[i] = min(l1[i], 2.0 * l2[i]); - else - out_result[i] = max(l1[i], 2.0 * (l2[i] - 0.5)); - } - - return out_result; -} - -color hardmix(color l1, color l2, int clamp_result) -{ - color out_result = vividlight(l1, l2, clamp_result); - for (int i=0; i < 3; ++i) - out_result[i] < 0.5 ? out_result[i] = 0.0 : out_result[i] = 1.0; - - return out_result; -} - -color reflect(color l1, color l2, int clamp_result) -{ - color out_result; - for (int i=0; i < 3; ++i) - { - if (l2[i] == 1.0) - out_result[i] = l2[i]; - else - out_result[i] = min((l1[i]*l1[i]) / (1.0 - l2[i]), 1.0); - } - - if (clamp_result) - out_result = clamp(out_result, color(0), color(1)); - - return out_result; -} - -color blend(color l1, color l2, float a, int mode, int clamp_result) -{ - color out_result = l2; - if (mode == LIGHTEN) - out_result = max(l1, l2); - else if (mode == DARKEN) - out_result = min(l1, l2); - else if (mode == MULTIPLY) - out_result = l1 * l2; - else if (mode == AVERAGE) - out_result = (l1 + l2) * 0.5; - else if (mode == ADD || mode == LINEARDODGE) - { - out_result = min(l1 + l2, color(1)); - if (clamp_result) - out_result = min(out_result, color(1)); - } - else if (mode == SUBTRACT || mode == LINEARBURN) - { - out_result = max(l1 + l2 - color(1), color(0)); - if (clamp_result) - out_result = max(out_result, color(0)); - } - else if (mode == DIFFERENCE) - out_result = fabs(l1 - l2); - else if (mode == NEGATION) - out_result = color(1) - fabs(color(1) - l1 - l2); - else if (mode == EXCLUSION) - out_result = l1 + l2 - (2.0 * l1 * l2); - else if (mode == SCREEN) - out_result = color(1) - ((color(1) - l1) * (color(1) - l2)); - else if (mode == OVERLAY) - out_result = overlay(l1, l2); - else if (mode == SOFTLIGHT) - out_result = softlight(l1, l2); - else if (mode == HARDLIGHT) - out_result = overlay(l2, l1); - else if (mode == COLORDODGE) - out_result = colordodge(l1, l2, clamp_result); - else if (mode == COLORBURN) - out_result = colorburn(l1, l2); - else if (mode == LINEARLIGHT) - out_result = linearlight(l1, l2, clamp_result); - else if (mode == VIVIDLIGHT) - out_result = vividlight(l1, l2, clamp_result); - else if (mode == PINLIGHT) - out_result = pinlight(l1, l2); - else if (mode == HARDMIX) - out_result = hardmix(l1, l2, clamp_result); - else if (mode == REFLECT) - out_result = reflect(l1, l2, clamp_result); - else if (mode == GLOW) - out_result = reflect(l2, l1, clamp_result); - else if (mode == PHOENIX) - out_result = min(l1, l2) - max(l1, l2) + color(1); - - return mix(l1, out_result, a); -} - -shader alLayerColor -[[ - string as_maya_node_name = "alLayerColor", - string help = "Layer multiple colors together.", - string description = "Layer up to eight color channels together with a variety of Photoshop-styl blending modes." -]] -( - int in_clamp_result = 0 - [[ - string label = "Clamp", - string widget = "checkBox", - string help = "Clamp the result of the blend operations", - string as_maya_attribute_name = "clamp_result" - ]], - - string in_layer1name = "" - [[ - string page = "Background", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer1name" - ]], - int in_layer1enabled = 1 - [[ - string page = "Background", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer1enabled" - ]], - color in_layer1 = color(0) - [[ - string page = "Background", - string label = "Input", - string help = "The background layer (will be blended over black if its alpha is not 1.)", - string as_maya_attribute_name = "layer1" - ]], - float in_layer1a = 0 - [[ - string page = "Background", - string label = "Alpha", - string help = "The alpha of the background layer", - string as_maya_attribute_name = "layer1a" - ]], - int in_layer1blend = 0 - [[ - string page = "Background", - string label = "Mode", - string help = "Blend mode for the background layer.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer1blend" - ]], - - string in_layer2name = "" - [[ - string page = "Layer 2", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer2name" - ]], - int in_layer2enabled = 1 - [[ - string page = "Layer 2", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer2enabled" - ]], - color in_layer2 = color(0) - [[ - string page = "Layer 2", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer2" - ]], - float in_layer2a = 0 - [[ - string page = "Layer 2", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer2a" - ]], - int in_layer2blend = 0 - [[ - string page = "Layer 2", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer2blend" - ]], - - string in_layer3name = "" - [[ - string page = "Layer 3", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer3name" - ]], - int in_layer3enabled = 1 - [[ - string page = "Layer 3", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer3enabled" - ]], - color in_layer3 = color(0) - [[ - string page = "Layer 3", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer3" - ]], - float in_layer3a = 0 - [[ - string page = "Layer 3", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer3a" - ]], - int in_layer3blend = 0 - [[ - string page = "Layer 3", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer3blend" - ]], - - string in_layer4name = "" - [[ - string page = "Layer 4", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer4name" - ]], - int in_layer4enabled = 1 - [[ - string page = "Layer 4", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer4enabled" - ]], - color in_layer4 = color(0) - [[ - string page = "Layer 4", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer4" - ]], - float in_layer4a = 0 - [[ - string page = "Layer 4", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer4a" - ]], - int in_layer4blend = 0 - [[ - string page = "Layer 4", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer4blend" - ]], - - string in_layer5name = "" - [[ - string page = "Layer 5", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer5name" - ]], - int in_layer5enabled = 1 - [[ - string page = "Layer 5", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer5enabled" - ]], - color in_layer5 = color(0) - [[ - string page = "Layer 5", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer5" - ]], - float in_layer5a = 0 - [[ - string page = "Layer 5", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer5a" - ]], - int in_layer5blend = 0 - [[ - string page = "Layer 5", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer5blend" - ]], - - string in_layer6name = "" - [[ - string page = "Layer 6", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer6name" - ]], - int in_layer6enabled = 1 - [[ - string page = "Layer 6", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer6enabled" - ]], - color in_layer6 = color(0) - [[ - string page = "Layer 6", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer6" - ]], - float in_layer6a = 0 - [[ - string page = "Layer 6", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer6a" - ]], - int in_layer6blend = 0 - [[ - string page = "Layer 6", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer6blend" - ]], - - string in_layer7name = "" - [[ - string page = "Layer 7", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer7name" - ]], - int in_layer7enabled = 1 - [[ - string page = "Layer 7", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer7enabled" - ]], - color in_layer7 = color(0) - [[ - string page = "Layer 7", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer7" - ]], - float in_layer7a = 0 - [[ - string page = "Layer 7", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer7a" - ]], - int in_layer7blend = 0 - [[ - string page = "Layer 7", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer7blend" - ]], - - string in_layer8name = "" - [[ - string page = "Layer 8", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer8name" - ]], - int in_layer8enabled = 1 - [[ - string page = "Layer 8", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer8enabled" - ]], - color in_layer8 = color(0) - [[ - string page = "Layer 8", - string label = "Input", - string help = "The color to be layered", - string as_maya_attribute_name = "layer8" - ]], - float in_layer8a = 0 - [[ - string page = "Layer 8", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer8a" - ]], - int in_layer8blend = 0 - [[ - string page = "Layer 8", - string label = "Mode", - string help = "The blend mode used to blend this layer over the layers below.", - string widget = "mapper", - string options = "Normal:0|Lighten:1|Darken:2|Multiply:3|Average:4|Add:5|Subtract:6|Difference:7|Negation:8|Exclusion:9|Screen:10|Overlay:11|Soft Light:12|Hard Light:13|Color Dodge:14|Color Burn:15|Linear Dodge:16|Linear Burn:17|Linear Light:18|Vivid Light:19|Pin Light:20|Hard Mix:21|Reflect:22|Glow:23|Phoenix:24", - string as_maya_attribute_name = "layer8blend" - ]], - - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - if (in_layer1enabled) - out_result = blend(out_result, in_layer1, in_layer1a, in_layer1blend, in_clamp_result); - - if (in_layer2enabled) - out_result = blend(out_result, in_layer2, in_layer2a, in_layer2blend, in_clamp_result); - - if (in_layer3enabled) - out_result = blend(out_result, in_layer3, in_layer3a, in_layer3blend, in_clamp_result); - - if (in_layer4enabled) - out_result = blend(out_result, in_layer4, in_layer4a, in_layer4blend, in_clamp_result); - - if (in_layer5enabled) - out_result = blend(out_result, in_layer5, in_layer5a, in_layer5blend, in_clamp_result); - - if (in_layer6enabled) - out_result = blend(out_result, in_layer6, in_layer6a, in_layer6blend, in_clamp_result); - - if (in_layer7enabled) - out_result = blend(out_result, in_layer7, in_layer7a, in_layer7blend, in_clamp_result); - - if (in_layer8enabled) - out_result = blend(out_result, in_layer8, in_layer8a, in_layer8blend, in_clamp_result); -} diff --git a/src/appleseed.shaders/src/alshaders/alLayerFloat.osl b/src/appleseed.shaders/src/alshaders/alLayerFloat.osl deleted file mode 100644 index ab8192c8ee..0000000000 --- a/src/appleseed.shaders/src/alshaders/alLayerFloat.osl +++ /dev/null @@ -1,302 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -shader alLayerFloat -[[ - string as_maya_node_name = "alLayerFloat" -]] -( - string in_layer1name = "" - [[ - string page = "Background", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer1name" - ]], - int in_layer1enabled = 1 - [[ - string page = "Background", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer1enabled" - ]], - float in_layer1 = 0 - [[ - string page = "Background", - string label = "Input", - string help = "The value of the background layer", - string as_maya_attribute_name = "layer1" - ]], - float in_layer1a = 0 - [[ - string page = "Background", - string label = "Alpha", - string help = "The alpha of the background layer", - string as_maya_attribute_name = "layer1a" - ]], - - string in_layer2name = "" - [[ - string page = "Layer 2", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer2name" - ]], - int in_layer2enabled = 1 - [[ - string page = "Layer 2", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer2enabled" - ]], - float in_layer2 = 0 - [[ - string page = "Layer 2", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer2" - ]], - float in_layer2a = 0 - [[ - string page = "Layer 2", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer2a" - ]], - - string in_layer3name = "" - [[ - string page = "Layer 3", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer3name" - ]], - int in_layer3enabled = 1 - [[ - string page = "Layer 3", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer3enabled" - ]], - float in_layer3 = 0 - [[ - string page = "Layer 3", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer3" - ]], - float in_layer3a = 0 - [[ - string page = "Layer 3", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer3a" - ]], - - string in_layer4name = "" - [[ - string page = "Layer 4", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer4name" - ]], - int in_layer4enabled = 1 - [[ - string page = "Layer 4", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer4enabled" - ]], - float in_layer4 = 0 - [[ - string page = "Layer 4", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer4" - ]], - float in_layer4a = 0 - [[ - string page = "Layer 4", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer4a" - ]], - - string in_layer5name = "" - [[ - string page = "Layer 5", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer5name" - ]], - int in_layer5enabled = 1 - [[ - string page = "Layer 5", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer5enabled" - ]], - float in_layer5 = 0 - [[ - string page = "Layer 5", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer5" - ]], - float in_layer5a = 0 - [[ - string page = "Layer 5", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer5a" - ]], - - string in_layer6name = "" - [[ - string page = "Layer 6", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer6name" - ]], - int in_layer6enabled = 1 - [[ - string page = "Layer 6", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer6enabled" - ]], - float in_layer6 = 0 - [[ - string page = "Layer 6", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer6" - ]], - float in_layer6a = 0 - [[ - string page = "Layer 6", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer6a" - ]], - - string in_layer7name = "" - [[ - string page = "Layer 7", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer7name" - ]], - int in_layer7enabled = 1 - [[ - string page = "Layer 7", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer7enabled" - ]], - float in_layer7 = 0 - [[ - string page = "Layer 7", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer7" - ]], - float in_layer7a = 0 - [[ - string page = "Layer 7", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer7a" - ]], - - string in_layer8name = "" - [[ - string page = "Layer 8", - string label = "Name", - string help = "A descriptive name for this layer", - string as_maya_attribute_name = "layer8name" - ]], - int in_layer8enabled = 1 - [[ - string page = "Layer 8", - string label = "Enabled", - string widget = "checkBox", - string help = "Toggle this layer on or off", - string as_maya_attribute_name = "layer8enabled" - ]], - float in_layer8 = 0 - [[ - string page = "Layer 8", - string label = "Input", - string help = "The value to be layered", - string as_maya_attribute_name = "layer8" - ]], - float in_layer8a = 0 - [[ - string page = "Layer 8", - string label = "Alpha", - string help = "The alpha used to blend this layer over the layers below", - string as_maya_attribute_name = "layer8a" - ]], - - output float out_result = 0 - [[ - string as_maya_attribute_name = "outValue" - ]] -) -{ - if (in_layer1enabled) - out_result = mix(out_result, in_layer1, in_layer1a); - - if (in_layer2enabled) - out_result = mix(out_result, in_layer2, in_layer2a); - - if (in_layer3enabled) - out_result = mix(out_result, in_layer3, in_layer3a); - - if (in_layer4enabled) - out_result = mix(out_result, in_layer4, in_layer4a); - - if (in_layer5enabled) - out_result = mix(out_result, in_layer5, in_layer5a); - - if (in_layer6enabled) - out_result = mix(out_result, in_layer6, in_layer6a); - - if (in_layer7enabled) - out_result = mix(out_result, in_layer7, in_layer7a); - - if (in_layer8enabled) - out_result = mix(out_result, in_layer8, in_layer8a); -} diff --git a/src/appleseed.shaders/src/alshaders/alPattern.osl b/src/appleseed.shaders/src/alshaders/alPattern.osl deleted file mode 100644 index cb548eb164..0000000000 --- a/src/appleseed.shaders/src/alshaders/alPattern.osl +++ /dev/null @@ -1,125 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -#include "alshaders/remap.h" -#include "alshaders/space.h" - -// Constants. -#define SINE 0 -#define SQUARE 1 -#define SAW 2 - -shader alPattern -[[ - string help = "Simple pattern generator.", - string description = "Generate different periodic wave signals to be used as the basis for other effects.", - string as_maya_node_name = "alPattern" -]] -( - SPACE_DECLARE_PARAMS, - int in_axis = 0 - [[ - string label = "Axis", - string widget = "mapper", - string options = "X:0|Y:1|Z:2", - string as_maya_attribute_name = "axis" - ]], - int in_shape = 0 - [[ - string label = "Shape", - string widget = "mapper", - string options = "sin:0|square:1|saw:2", - string help = "Pattern to generate.", - string as_maya_attribute_name = "shape" - ]], - float in_frequency = 5 - [[ - string label = "Frequency", - string help = "Frequency of the pattern.", - string as_maya_attribute_name = "frequency" - ]], - float in_offset = 0 - [[ - string label = "offset", - string help = "Offset of the pattern. You can plug a noise in here to get warped patterns.", - string as_maya_attribute_name = "offset" - ]], - color in_color1 = 0 - [[ - string label = "Color 1", - string help = "Color to use when the pattern value is 0.", - string as_maya_attribute_name = "color1" - ]], - color in_color2 = 1 - [[ - string label = "Color 2", - string help = "Color to use when the pattern value is 1.", - string as_maya_attribute_name = "color2" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - output color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - point pp; - if (in_space == SPACE_WORLD) - pp = in_p; - else if (in_space == SPACE_OBJECT) - pp = transform("object", in_p); - else if (in_space == SPACE_PREF) - pp = Pref; - else if (in_space == SPACE_UV) - pp = point(u, v, 0); - - pp *= in_frequency; - - float x; - - if (in_axis == 0) - x = pp[0]; - else if (in_axis == 1) - x = pp[1]; - else // if (in_axis == 2) - x = pp[2]; - - x += in_offset; - - float r = 0; - if (in_shape == SINE) - r = sin(x); - else if (in_shape == SQUARE) - r = sin(x) > 0 ? 1 : 0; - else if (in_shape == SAW) - r = mod(x * 0.25, 1); - - RemapFloatParams rmp = REMAP_FLOAT_CREATE; - r = remap(r, rmp); - out_result = mix(in_color1, in_color2, r); -} diff --git a/src/appleseed.shaders/src/alshaders/alRemapColor.osl b/src/appleseed.shaders/src/alshaders/alRemapColor.osl deleted file mode 100644 index 44b7dd14d6..0000000000 --- a/src/appleseed.shaders/src/alshaders/alRemapColor.osl +++ /dev/null @@ -1,79 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -shader alRemapColor -[[ - string as_maya_node_name = "alRemapColor" -]] -( - color input = color(0.18, 0.18, 0.18), - float gamma = 1, - float saturation = 1, - float hueOffset = 0, - float contrastVal = 1, - float contrastPivot = 0.18, - float gain = 1, - float exposure = 0, - float mask = 1, - output color result = color(0,0,0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - result = input; - - if (mask > 0) - { - if (gamma != 1) - result = pow(result, 1 / gamma); - - if (saturation != 1) - { - float l = luminance(result); - result = mix(color(l), result, saturation); - } - - if (hueOffset != 0) - { - color hsv = transformc("hsv", result); - hsv[0] += hueOffset; - result = transformc("rgb", result); - } - - if (contrastVal != 1) - { - result = (result-color(contrastPivot))*contrastVal + color(contrastPivot); - } - - result = result * gain * pow(2, exposure); - - if (mask < 1) - result = mix(input, result, mask); - } -} diff --git a/src/appleseed.shaders/src/alshaders/alRemapFloat.osl b/src/appleseed.shaders/src/alshaders/alRemapFloat.osl deleted file mode 100644 index 76314c9283..0000000000 --- a/src/appleseed.shaders/src/alshaders/alRemapFloat.osl +++ /dev/null @@ -1,49 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -#include "alshaders/remap.h" - -shader alRemapFloat -[[ - string as_maya_node_name = "alRemapFloat" -]] -( - float in_input = 0 - [[ - string as_maya_attribute_name = "input" - ]], - REMAP_FLOAT_DECLARE_PARAMS("Remap"), - - output float out_result = 0 - [[ - string as_maya_attribute_name = "outValue" - ]] -) -{ - RemapFloatParams rmp = REMAP_FLOAT_CREATE; - out_result = remap(in_input, rmp); -} diff --git a/src/appleseed.shaders/src/alshaders/alSurface.osl b/src/appleseed.shaders/src/alshaders/alSurface.osl deleted file mode 100644 index 65ba5d983b..0000000000 --- a/src/appleseed.shaders/src/alshaders/alSurface.osl +++ /dev/null @@ -1,537 +0,0 @@ - -// -// This source file is part of appleseed. -// Visit http://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#include "appleseed/color/as_color_helpers.h" -#include "appleseed/material/as_material_helpers.h" - -// Constants. -#define BSSRDF_MODE_CUBIC 0 -#define BSSRDF_MODE_DIFFUSION 1 -#define BSSRDF_MODE_DIRECTIONAL 2 -#define BSSRDF_MODE_EMPIRICAL 3 - -shader alSurface -[[ - string help = "A physically plausible, energy-conserving, general-purpose surface shader.", - string description = "Suitable for any dielectric or metallic material including skin, plastic, wood, metal, glass, etc.", - string as_maya_node_name = "alSurface" -]] -( - normal in_globalNormal = N - [[ - string as_maya_attribute_name = "normalCamera", - string as_maya_attribute_name = "n" - ]], - vector Tn = 0 - [[ - int lockgeom = 0, - string widget = "null" - ]], - - normal in_diffuseNormal = normal(0) - [[ - string as_maya_attribute_name = "diffuseNormal" - ]], - float in_diffuseStrength = 1 - [[ - string as_maya_attribute_name = "diffuseStrength" - ]], - color in_diffuseColor = color(0.5) - [[ - string as_maya_attribute_name = "diffuseColor" - ]], - float in_diffuseRoughness = 0 - [[ - string as_maya_attribute_name = "diffuseRoughness" - ]], - - float in_backlightStrength = 0 - [[ - string as_maya_attribute_name = "backlightStrength" - ]], - color in_backlightColor = color(0.18) - [[ - string as_maya_attribute_name = "backlightColor" - ]], - - float in_sssMix = 0 - [[ - string as_maya_attribute_name = "sssMix" - ]], - int in_sssMode = 0 - [[ - string as_maya_attribute_name = "sssMode" - ]], - float in_sssRadius = 1.5 - [[ - string as_maya_attribute_name = "sssRadius" - ]], - float in_sssWeight1 = 1 - [[ - string as_maya_attribute_name = "sssWeight1" - ]], - color in_sssRadiusColor = color(0.439, 0.156, 0.078) - [[ - string as_maya_attribute_name = "sssRadiusColor" - ]], - float in_sssRadius2 = 4.0 - [[ - string as_maya_attribute_name = "sssRadius2" - ]], - float in_sssWeight2 = 0 - [[ - string as_maya_attribute_name = "sssWeight2" - ]], - color in_sssRadiusColor2 = color(0.439, 0.08, 0.018) - [[ - string as_maya_attribute_name = "sssRadiusColor2" - ]], - float in_sssRadius3 = 0.75 - [[ - string as_maya_attribute_name = "sssRadius3" - ]], - float in_sssWeight3 = 0 - [[ - string as_maya_attribute_name = "sssWeight3" - ]], - color in_sssRadiusColor3 = color(0.523, 0.637, 0.667) - [[ - string as_maya_attribute_name = "sssRadiusColor3" - ]], - float in_sssDensityScale = 1 - [[ - string as_maya_attribute_name = "sssDensityScale" - ]], - - normal in_specular1Normal = normal(0) - [[ - string as_maya_attribute_name = "specular1Normal" - ]], - float in_specular1Strength = 1 - [[ - string as_maya_attribute_name = "specular1Strength" - ]], - color in_specular1Color = color(1) - [[ - string as_maya_attribute_name = "specular1Color" - ]], - float in_specular1Roughness = 0.3 - [[ - string as_maya_attribute_name = "specular1Roughness" - ]], - float in_specular1Anisotropy = 0 - [[ - string as_maya_attribute_name = "specular1Anisotropy" - ]], - float in_specular1Rotation = 0 - [[ - string as_maya_attribute_name = "specular1Rotation" - ]], - int in_specular1FresnelMode = 0 - [[ - string as_maya_attribute_name = "specular1FresnelMode" - ]], - float in_specular1Ior= 1.4 - [[ - string as_maya_attribute_name = "specular1Ior" - ]], - color in_specular1Reflectivity = color(0.548, 0.549, 0.570) - [[ - string as_maya_attribute_name = "specular1Reflectivity" - ]], - color in_specular1EdgeTint = color(0.579, 0.598, 0.620) - [[ - string as_maya_attribute_name = "specular1EdgeTint" - ]], - float in_specular1RoughnessDepthScale = 1 - [[ - string as_maya_attribute_name = "specular1RoughnessDepthScale" - ]], - int in_specular1Distribution = 0 - [[ - string as_maya_attribute_name = "specular1Distribution" - ]], - - normal in_specular2Normal = normal(0) - [[ - string as_maya_attribute_name = "specular2Normal" - ]], - float in_specular2Strength = 0 - [[ - string as_maya_attribute_name = "specular2Strength" - ]], - color in_specular2Color = color(1) - [[ - string as_maya_attribute_name = "specular2Color" - ]], - float in_specular2Roughness = 0 - [[ - string as_maya_attribute_name = "specular2Roughness" - ]], - float in_specular2Anisotropy = 0 - [[ - string as_maya_attribute_name = "specular2Anisotropy" - ]], - float in_specular2Rotation = 0 - [[ - string as_maya_attribute_name = "specular2Rotation" - ]], - int in_specular2FresnelMode = 0 - [[ - string as_maya_attribute_name = "specular2FresnelMode" - ]], - float in_specular2Ior = 1.4 - [[ - string as_maya_attribute_name = "specular2Ior" - ]], - color in_specular2Reflectivity = color(0.548, 0.549, 0.570) - [[ - string as_maya_attribute_name = "specular2Reflectivity" - ]], - color in_specular2EdgeTint = color(0.579, 0.598, 0.620) - [[ - string as_maya_attribute_name = "specular2EdgeTint" - ]], - float in_specular2RoughnessDepthScale = 1 - [[ - string as_maya_attribute_name = "specular2RoughnessDepthScale" - ]], - int in_specular2Distribution = 0 - [[ - string as_maya_attribute_name = "specular2Distribution" - ]], - - normal in_transmissionNormal = normal(0) - [[ - string as_maya_attribute_name = "transmissionNormal" - ]], - float in_transmissionStrength = 0 - [[ - string as_maya_attribute_name = "transmissionStrength" - ]], - color in_transmissionColor = color(1) - [[ - string as_maya_attribute_name = "transmissionColor" - ]], - int in_transmissionLinkToSpecular1 = 1 - [[ - string as_maya_attribute_name = "transmissionLinkToSpecular1" - ]], - float in_transmissionRoughness = 0 - [[ - string as_maya_attribute_name = "transmissionRoughness" - ]], - float in_transmissionIor = 1.4 - [[ - string as_maya_attribute_name = "transmissionIor" - ]], - float in_transmissionRoughnessDepthScale = 1 - [[ - string as_maya_attribute_name = "transmissionRoughnessDepthScale" - ]], - - color in_ssAttenuationColor = color(1) - [[ - string as_maya_attribute_name = "ssAttenuationColor" - ]], - float in_ssDensityScale = 1 - [[ - string as_maya_attribute_name = "ssDensityScale" - ]], - - float in_emissionStrength = 0 - [[ - string as_maya_attribute_name = "emissionStrength" - ]], - color in_emissionColor = color(1) - [[ - string as_maya_attribute_name = "emissionColor" - ]], - - color in_opacity = 1 - [[ - string as_maya_attribute_name = "opacity" - ]], - - output closure color out_result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - int do_diffuse = 1; - int do_backlight = 1; - int do_sss = 1; - int do_transmission = 1; - int do_emission = 1; - int do_glossy2 = 1; - int do_glossy = 1; - - if (raytype("transparency") || raytype("shadow")) - { - if (min(in_opacity) < 1.0) - out_result = (color(1) - in_opacity) * transparent(); - } - - if (raytype("transparency")) - return; - - if (raytype("shadow")) - { - do_diffuse = 0; - do_backlight = 0; - do_sss = 0; - do_transmission = 1; - do_emission = 0; - do_glossy2 = 0; - do_glossy = 0; - } - else if (raytype("light")) - { - do_diffuse = 0; - do_backlight = 0; - do_sss = 0; - do_transmission = 0; - do_emission = 1; - do_glossy2 = 0; - do_glossy = 0; - } - - // Balance diffuse, transmission and backlight - color transmissionColor = in_transmissionColor * in_transmissionStrength; - color diffuseColor = in_diffuseColor * in_diffuseStrength; - color backlightColor = in_backlightColor * in_backlightStrength; - float t_sum = max(transmissionColor) + max(diffuseColor) + max(backlightColor); - - if (t_sum > 1.0) - { - float t_sum_inv = 1.0 / t_sum; - transmissionColor *= t_sum_inv; - diffuseColor *= t_sum_inv; - backlightColor *= t_sum_inv; - } - - // Disable closures we don't need. - if (max(diffuseColor) < IMPORTANCE_THRESHOLD || in_sssMix == 1.0) - do_diffuse = 0; - - if (max(backlightColor) < IMPORTANCE_THRESHOLD || in_sssMix == 1.0) - do_backlight = 0; - - if (in_sssMix == 0.0 || max(diffuseColor) < IMPORTANCE_THRESHOLD) - do_sss = 0; - - if (max(transmissionColor) < IMPORTANCE_THRESHOLD || in_sssMix == 1.0) - do_transmission = 0; - - color emissionColor = in_emissionColor * in_emissionStrength; - if (max(emissionColor) < IMPORTANCE_THRESHOLD) - do_emission = 0; - - color specular1Color = in_specular1Color * in_specular1Strength; - if (max(specular1Color) < IMPORTANCE_THRESHOLD) - do_glossy = 0; - - color specular2Color = in_specular2Color * in_specular2Strength; - if (max(specular2Color) < IMPORTANCE_THRESHOLD) - do_glossy2 = 0; - - // Normals. - normal globalNormal = normalize(in_globalNormal); - normal diffuseNormal = globalNormal; - normal transmissionNormal = globalNormal; - normal specular2Normal = globalNormal; - normal specular1Normal = globalNormal; - - if (isconnected(in_diffuseNormal)) - diffuseNormal = normalize(in_diffuseNormal); - - if (isconnected(in_transmissionNormal)) - transmissionNormal = normalize(in_transmissionNormal); - - if (isconnected(in_specular2Normal)) - specular2Normal = normalize(in_specular2Normal); - - if (isconnected(in_specular1Normal)) - specular1Normal = normalize(in_specular1Normal); - - // Create closures. - if (do_diffuse) - out_result += diffuseColor * - (1.0 - in_sssMix) * oren_nayar(diffuseNormal, in_diffuseRoughness); - - if (do_backlight) - out_result += backlightColor * - (1.0 - in_sssMix) * translucent(diffuseNormal); - - if (do_sss) - { - color sssColor = diffuseColor * in_sssMix; - float sssIor = 1.3; - - // Normalize the SSS weights. - float weights[3] = {in_sssWeight1, in_sssWeight2, in_sssWeight3}; - float rcpSumWeight = 1.0 / (weights[0] + weights[1] + weights[2]); - weights[0] *= rcpSumWeight; - weights[1] *= rcpSumWeight; - weights[2] *= rcpSumWeight; - - // Zero small weights. - weights[0] = weights[0] > IMPORTANCE_THRESHOLD ? weights[0] : 0.0; - weights[1] = weights[1] > IMPORTANCE_THRESHOLD ? weights[1] : 0.0; - weights[2] = weights[2] > IMPORTANCE_THRESHOLD ? weights[2] : 0.0; - - string profile; - if (in_sssMode == BSSRDF_MODE_CUBIC) - profile = "gaussian"; - else if (in_sssMode == BSSRDF_MODE_DIFFUSION) - profile = "better_dipole"; - else - profile = "normalized_diffusion"; - - color radii[3]; - radii[0] = max(color(0.0001), in_sssRadius * in_sssRadiusColor / (in_sssDensityScale * 7.0)); - radii[1] = max(color(0.0001), in_sssRadius2 * in_sssRadiusColor2 / (in_sssDensityScale * 7.0)); - radii[2] = max(color(0.0001), in_sssRadius3 * in_sssRadiusColor3 / (in_sssDensityScale * 7.0)); - - // Add the SSS closures. - for (int i = 0; i < 3; ++i) - { - if (weights[i] > 0.0) - { - out_result += sssColor * weights[i] * - as_subsurface( - profile, - diffuseNormal, - color(1.0), - radii[i], - sssIor, - "fresnel_weight", 0.0); - } - } - } - - if (do_transmission) - { - float transmissionRoughness = in_transmissionRoughness; - float transmissionIor = in_transmissionIor; - - if (in_transmissionLinkToSpecular1) - { - transmissionRoughness = in_specular1Roughness; - transmissionIor = in_specular1Ior; - } - - color volumeTransmittanceColor = color(1); - float volumeTransmittanceDistance = 0.0; - - if (min(in_ssAttenuationColor) < 1.0) - { - // Compute absorption. - color sigmaA = (color(1) - clamp( - in_ssAttenuationColor, - color(0), color(0.999))) * in_ssDensityScale; - - // Convert to transmittance. - volumeTransmittanceColor = exp(-sigmaA); - volumeTransmittanceDistance = 1.0; - } - - out_result += (1.0 - in_sssMix) * as_glass( - "beckmann", - transmissionNormal, - vector(0), - transmissionColor, - color(0), // transmission only - color(1), - transmissionRoughness, - 0.5, // highlight falloff - 0, // anisotropy - transmissionIor, - volumeTransmittanceColor, - volumeTransmittanceDistance); - } - - if (do_emission) - out_result += emissionColor * emission(); - - if (do_glossy2) - { - vector T = Tn; - - if (in_specular2Rotation != 0) - { - T = rotate( - T, - -in_specular2Rotation * M_PI, - point(0), - point(specular2Normal)); - } - - out_result = as_alsurface_layer( - out_result, - in_specular2Distribution, - specular2Normal, - T, - specular2Color, - in_specular2Roughness, - in_specular2Anisotropy, - in_specular2FresnelMode, - in_specular2Ior, - in_specular2Reflectivity, - in_specular2EdgeTint); - } - - if (do_glossy) - { - vector T = Tn; - - if (in_specular1Rotation != 0) - { - T = rotate( - T, - -in_specular1Rotation * M_PI, - point(0), - point(specular1Normal)); - } - - out_result = as_alsurface_layer( - out_result, - in_specular1Distribution, - specular1Normal, - T, - specular1Color, - in_specular1Roughness, - in_specular1Anisotropy, - in_specular1FresnelMode, - in_specular1Ior, - in_specular1Reflectivity, - in_specular1EdgeTint); - } -} diff --git a/src/appleseed.shaders/src/alshaders/alSwitchColor.osl b/src/appleseed.shaders/src/alshaders/alSwitchColor.osl deleted file mode 100644 index 60977e9747..0000000000 --- a/src/appleseed.shaders/src/alshaders/alSwitchColor.osl +++ /dev/null @@ -1,65 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -shader alSwitchColor -[[ - string as_maya_node_name = "alSwitchColor" -]] -( - color inputA = 0, - color inputB = 1, - color inputC = 0.15, - color inputD = 0.3, - color inputE = 0.45, - color inputF = 0.6, - color inputG = 0.75, - color inputH = 0.9, - float mixer=1, - float threshold=0.5, - output color result = 0 - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - float input = floor(mixer); - - if (mixer - input >= threshold) - input++; - - input = clamp(input, 0, 7); - - if (input == 0) result = inputA; - else if (input == 1) result = inputB; - else if (input == 2) result = inputC; - else if (input == 3) result = inputD; - else if (input == 4) result = inputE; - else if (input == 5) result = inputF; - else if (input == 6) result = inputG; - else if (input == 7) result = inputH; -} diff --git a/src/appleseed.shaders/src/alshaders/alSwitchFloat.osl b/src/appleseed.shaders/src/alshaders/alSwitchFloat.osl deleted file mode 100644 index 757e2af896..0000000000 --- a/src/appleseed.shaders/src/alshaders/alSwitchFloat.osl +++ /dev/null @@ -1,63 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2013 Anders Langlands -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code comes from alshaders OSL branch, with minimal changes. -// https://bitbucket.org/anderslanglands/alshaders/branch/osl - -shader alSwitchFloat -[[ - string as_maya_node_name = "alSwitchFloat" -]] -( - float inputA = 0, - float inputB = 1, - float inputC = 0.15, - float inputD = 0.3, - float inputE = 0.45, - float inputF = 0.6, - float inputG = 0.75, - float inputH = 0.9, - float mixer=1, - float threshold=0.5, - output float result = 0 - [[ - string as_maya_attribute_name = "outValue" - ]] -) -{ - float input = floor(mixer); - if (mixer - input >= threshold) - input++; - - input = clamp(input, 0, 7); - - if (input == 0) result = inputA; - else if (input == 1) result = inputB; - else if (input == 2) result = inputC; - else if (input == 3) result = inputD; - else if (input == 4) result = inputE; - else if (input == 5) result = inputF; - else if (input == 6) result = inputG; - else if (input == 7) result = inputH; -} diff --git a/src/appleseed.shaders/src/alshaders/alTriplanar.osl b/src/appleseed.shaders/src/alshaders/alTriplanar.osl deleted file mode 100644 index ed4a986187..0000000000 --- a/src/appleseed.shaders/src/alshaders/alTriplanar.osl +++ /dev/null @@ -1,314 +0,0 @@ - -// -// This software is released under the MIT licence -// -// Copyright (c) 2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -// This code is ported from alshaders original C++ implementation. -// https://bitbucket.org/anderslanglands/alshaders - -// Constants. -#define NS_WORLD 0 -#define NS_OBJECT 1 -#define NS_PREF 2 -#define N_GEOMETRIC 0 -#define N_SMOOTH 1 -#define N_SMOOTHNOBUMP 2 -#define TM_REGULAR 0 -#define TM_CELLNOISE 1 - -vector computeBlendWeights(normal inNormal, float blendSoftness) -{ - vector weights = fabs(inNormal); - float weightsum = 0; - for (int i = 0; i < 3; i++) - { - weights[i] = weights[i] - (1.0 - blendSoftness) / 2.0; - weights[i] = max(weights[i], 0.0); - weightsum += weights[i]; - } - - if (weightsum != 0) - weights /= weightsum; - - return weights; -} - -point rotateUVs(point uvs, float degrees) -{ - float phi = degrees / 360.0 * M_PI * 2.0; - - vector orientVectorX = vector(cos(phi), sin(phi), 0.0); - vector orientVectorZ = vector(0.0, 0.0, 1.0); - vector orientVectorY = cross(orientVectorX, orientVectorZ); - - return point( - dot(uvs, orientVectorX), - dot(uvs, orientVectorY), - dot(uvs, orientVectorZ)); -} - -color lookupRegular( - string textureMap, - point PP, - float scale, - float rot, - float weight, - output float a) -{ - if (weight > 0.0) - { - point ProjP = rotateUVs(PP, rot); - point dProjPx = Dx(ProjP); - point dProjPy = Dy(ProjP); - float dudx = dProjPx[2] * scale; - float dudy = dProjPy[2] * scale; - float dvdx = dProjPx[1] * scale; - float dvdy = dProjPy[1] * scale; - - color col = texture( - textureMap, - ProjP[0], - ProjP[1], - dudx, - dudy, - dvdx, - dvdy, - "wrap", "periodic", - "missingcolor", color(0.0), - "missingalpha", 1.0, - "alpha", a); - a *= weight; - return col * weight; - } - else - { - a = 0.0; - return color(0); - } -} - -/* -bool lookupCellNoise( - float u, - float v, - float dudx, - float dudy, - float dvdx, - float dvdy, - float cellSoftness, - float rot, - float rotjitter, - AtShaderGlobals *sg, - AtTextureHandle *handle, - AtTextureParams *params, - AtRGBA *textureResult) -{ - point PP = point(u, v, 0); - - int samples = (cellSoftness == 0) ? 1 : 3; - // run cellnoise - float weights[3]; - float f[3]; - AtVector delta[3]; - AtUInt32 id[3]; - AiCellular(P, samples, 1, 1.92, 1, f, delta, id); - - if(samples == 1) - { - weights[0] = 1; - } - else - { - // find closest cell - float closestDistance = 100000; - float distances[3]; - for(int i = 0; i < samples; i++) - { - distances[i] = AiV3Length(delta[i]); - closestDistance = MIN(distances[i], closestDistance); - } - - float weightsum = 0; - for(int i=0; idudx = dudx; - sg->dudy = dudy; - sg->dvdx = dvdx; - sg->dvdy = dvdy; - for(int i=0; i 0){ - // pick direction for orientation - AtVector orientVectorX; - double jitter = (random(id[i])-0.5) * rotjitter; - double phi = modulo(rot/360. + jitter, 1) * AI_PI * 2.; - orientVectorX.x = cosf(phi); - orientVectorX.y = sinf(phi); - orientVectorX.z = 0; - - AtVector orientVectorZ; - orientVectorZ.x = 0; - orientVectorZ.y = 0; - orientVectorZ.z = 1; - - AtVector orientVectorY = AiV3Cross(orientVectorX, orientVectorZ); - - AiV3RotateToFrame(delta[i], orientVectorX, orientVectorY, orientVectorZ); - - // find new uv coordinates, set the center of the cell to be 0.5/0.5; - sg->u = delta[i].x * 0.75 - 0.5; - sg->v = delta[i].y * 0.75 - 0.5; - - // texture lookup - bool currentSuccess = false; - *textureResult += AiTextureHandleAccess(sg, handle, params, &success) * weights[i]; - success |= currentSuccess; - } - } - - return success; -} -*/ - -shader alTriplanar -[[ - string as_maya_node_name = "alTriplanar", - string help = "Useful for quickly adding bombing patterns of texture to objects to add variation and breakup." -]] -( - color input = color(0), - int space = 0, - int normalType = 0 - [[ - string as_maya_attribute_name = "normal" - ]], - int tiling = 0, - float frequency = 1.0, - string textureMap = "" - [[ - string as_maya_attribute_name = "texture" - ]], - float blendSoftness = 0.1, - float cellSoftness = 0.1, - float scalex = 1.0, - float scaley = 1.0, - float scalez = 1.0, - float offsetx = 0.0, - float offsety = 0.0, - float offsetz = 0.0, - float rotx = 0.0, - float roty = 0.0, - float rotz = 0.0, - float rotjitterx = 1.0, - float rotjittery = 1.0, - float rotjitterz = 1.0, - int mipMapBias = 0, - output color result = color(0) - [[ - string as_maya_attribute_name = "outColor", - string as_maya_attribute_short_name = "oc" - ]] -) -{ - point PP; - - if (space == NS_WORLD) - PP = P; - else if (space == NS_OBJECT) - PP = transform("object", P); - else if (space == NS_PREF) - { - // We don't have Pref yet. - PP = transform("object", P); - } - - vector dpdx = Dx(PP); - vector dpdy = Dy(PP); - - normal NN; - if (normalType == N_GEOMETRIC) - NN = Ng; - else // N_SMOOTH and N_SMOOTHNOBUMP - NN = N; - - vector scale = vector(1.0 / scalex, 1.0 / scaley, 1.0 / scalez); - vector offset = vector(offsetx, offsety, offsetz); - vector rot = vector(rotx, roty, rotz); - vector rotjitter = vector(rotjitterx, rotjittery, rotjitterz); - - vector weights = computeBlendWeights(NN, blendSoftness); - - PP *= frequency; - result = input; - - color colx, coly, colz; - float ax, ay, az; - - if (tiling == TM_REGULAR) - { - // lookup X - point ProjP = point( - (PP[2] + 123.94 + offset[0]) * scale[0], - (PP[1] + 87.22 + offset[0]) * scale[0], - 0.0); - colx = lookupRegular(textureMap, ProjP, scale[0], rot[0], weights[0], ax); - - // lookup Y - ProjP = point( - (PP[0] + 74.1 + offset[1]) * scale[1], - (PP[2] + 9.2 + offset[1]) * scale[1], - 0.0); - coly = lookupRegular(textureMap, ProjP, scale[1], rot[1], weights[1], ay); - - // lookup Z - ProjP = point( - (PP[0] + 123.94 + offset[2]) * scale[2], - (PP[1] + 87.22 + offset[2]) * scale[2], - 0.0); - colz = lookupRegular(textureMap, ProjP, scale[2], rot[2], weights[2], az); - } - else if (tiling == TM_CELLNOISE) - { - // todo: implement this. - colx = coly = colz = color(0); - ax = ay = az = 0.0; - } - - result = colx + coly + colz; - - int num_channels; - gettextureinfo(textureMap, "channels", num_channels); - if (num_channels == 2 || num_channels == 4) - result = mix(input, result, ax + ay + az); -} diff --git a/src/appleseed/CMakeLists.txt b/src/appleseed/CMakeLists.txt index 7c3059cdd1..5e7b542193 100644 --- a/src/appleseed/CMakeLists.txt +++ b/src/appleseed/CMakeLists.txt @@ -787,12 +787,6 @@ if (WITH_DISNEY_MATERIAL) foundation/utility/seexpr.h ) endif () -if (WITH_PARTIO) - list (APPEND foundation_utility_sources - foundation/utility/partiofile.cpp - foundation/utility/partiofile.h - ) -endif () list (APPEND appleseed_sources ${foundation_utility_sources} ) @@ -1262,8 +1256,6 @@ source_group ("renderer\\modeling\\aov" FILES ) set (renderer_modeling_bsdf_sources - renderer/modeling/bsdf/alsurfacelayerbrdf.cpp - renderer/modeling/bsdf/alsurfacelayerbrdf.h renderer/modeling/bsdf/ashikhminbrdf.cpp renderer/modeling/bsdf/ashikhminbrdf.h renderer/modeling/bsdf/backfacingpolicy.h @@ -1874,10 +1866,6 @@ if (WITH_DISNEY_MATERIAL) link_against_seexpr (appleseed) endif () -if (WITH_PARTIO) - link_against_partio (appleseed) -endif () - target_link_libraries (appleseed ${Boost_LIBRARIES} lz4 diff --git a/src/appleseed/foundation/math/cdf.h b/src/appleseed/foundation/math/cdf.h index a4a18f925f..2649d3b105 100644 --- a/src/appleseed/foundation/math/cdf.h +++ b/src/appleseed/foundation/math/cdf.h @@ -104,11 +104,11 @@ class CDF // Sampling and inversion functions. // -template -size_t sample_cdf( - RandomAccessIter begin, - RandomAccessIter end, - const Weight x); +template +size_t sample_pdf_linear_search( + const T* pdf, + const size_t size, + const T x); template size_t sample_cdf_linear_search( @@ -116,6 +116,12 @@ size_t sample_cdf_linear_search( const size_t size, const T x); +template +size_t sample_cdf( + RandomAccessIter begin, + RandomAccessIter end, + const Weight x); + // Numerically invert the CDF function cdf, with corresponding PDF pdf, // using a combination of bisection and Newton's method. template @@ -129,7 +135,6 @@ T invert_cdf_function( const T eps, // root precision const size_t max_iterations); // max root refinement iterations - // // CDF class implementation. // @@ -233,20 +238,25 @@ inline const std::pair& CDF::sample(const Weight x) // Functions implementation. // -template -inline size_t sample_cdf( - RandomAccessIter begin, - RandomAccessIter end, - const Weight x) +template +inline size_t sample_pdf_linear_search( + const T* pdf, + const size_t size, + const T x) { - assert(begin != end); - assert(x >= Weight(0.0)); - assert(x < Weight(1.0)); + assert(size > 0); + assert(x >= T(0.0)); + assert(x < T(1.0)); - const RandomAccessIter i = std::upper_bound(begin, end, x); - assert(i < end); + T u = T(0.0); - return i - begin; + for (size_t i = 0; i < size; ++i) + { + u += pdf[i]; + if (x < u) return i; + } + + return size - 1; } template @@ -265,6 +275,22 @@ inline size_t sample_cdf_linear_search( return i; } +template +inline size_t sample_cdf( + RandomAccessIter begin, + RandomAccessIter end, + const Weight x) +{ + assert(begin != end); + assert(x >= Weight(0.0)); + assert(x < Weight(1.0)); + + const RandomAccessIter i = std::upper_bound(begin, end, x); + assert(i < end); + + return i - begin; +} + template T invert_cdf_function( CDF cdf, diff --git a/src/appleseed/foundation/utility/partiofile.cpp b/src/appleseed/foundation/utility/partiofile.cpp deleted file mode 100644 index 6a8ce34b2b..0000000000 --- a/src/appleseed/foundation/utility/partiofile.cpp +++ /dev/null @@ -1,79 +0,0 @@ - -// -// This source file is part of appleseed. -// Visit http://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2015-2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -// Interface header. -#include "partiofile.h" - -// Standard headers. -#include - -using namespace std; - -namespace foundation -{ - -// -// PartioFile class implementation. -// - -PartioFile::PartioFile() -{ - m_particles = Partio::create(); -} - -PartioFile::~PartioFile() -{ - m_particles->release(); -} - -Partio::ParticleAttribute PartioFile::add_float_attribute(const char* name) -{ - return m_particles->addAttribute(name, Partio::FLOAT, 1); -} - -Partio::ParticleAttribute PartioFile::add_vector_attribute(const char* name) -{ - return m_particles->addAttribute(name, Partio::VECTOR, 3); -} - -Partio::ParticleAttribute PartioFile::add_color_attribute(const char* name) -{ - return m_particles->addAttribute(name, Partio::VECTOR, 3); -} - -Partio::ParticleIndex PartioFile::add_particle() -{ - return m_particles->addParticle(); -} - -void PartioFile::write(const char* filepath) const -{ - Partio::write(filepath, *m_particles); -} - -} // namespace foundation diff --git a/src/appleseed/foundation/utility/partiofile.h b/src/appleseed/foundation/utility/partiofile.h deleted file mode 100644 index fae74d0b98..0000000000 --- a/src/appleseed/foundation/utility/partiofile.h +++ /dev/null @@ -1,121 +0,0 @@ - -// -// This source file is part of appleseed. -// Visit http://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2015-2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#ifndef APPLESEED_FOUNDATION_UTILITY_PARTIOFILE_H -#define APPLESEED_FOUNDATION_UTILITY_PARTIOFILE_H - -// appleseed.foundation headers. -#include "foundation/core/concepts/noncopyable.h" -#include "foundation/image/color.h" -#include "foundation/math/vector.h" - -// Partio headers. -#include - -namespace foundation -{ - -class PartioFile - : public NonCopyable -{ - public: - PartioFile(); - ~PartioFile(); - - Partio::ParticleAttribute add_float_attribute(const char* name); - Partio::ParticleAttribute add_vector_attribute(const char* name); - Partio::ParticleAttribute add_color_attribute(const char* name); - - Partio::ParticleIndex add_particle(); - - template - void set_float_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const T value); - - template - void set_vector_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const foundation::Vector& value); - - template - void set_color_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const foundation::Color& value); - - void write(const char* filepath) const; - - private: - Partio::ParticlesDataMutable* m_particles; -}; - - -// -// PartioFile class implementation. -// - -template -inline void PartioFile::set_float_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const T value) -{ - float* data = m_particles->dataWrite(attribute, particle); - *data = static_cast(value); -} - -template -inline void PartioFile::set_vector_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const foundation::Vector& value) -{ - float* data = m_particles->dataWrite(attribute, particle); - data[0] = static_cast(value[0]); - data[1] = static_cast(value[1]); - data[2] = static_cast(value[2]); -} - -template -inline void PartioFile::set_color_attribute( - const Partio::ParticleIndex particle, - const Partio::ParticleAttribute& attribute, - const foundation::Color& value) -{ - float* data = m_particles->dataWrite(attribute, particle); - data[0] = static_cast(value[0]); - data[1] = static_cast(value[1]); - data[2] = static_cast(value[2]); -} - -} // namespace foundation - -#endif // !APPLESEED_FOUNDATION_UTILITY_PARTIOFILE_H diff --git a/src/appleseed/renderer/kernel/shading/closures.cpp b/src/appleseed/renderer/kernel/shading/closures.cpp index 5bb436e54c..de9c9fa85b 100644 --- a/src/appleseed/renderer/kernel/shading/closures.cpp +++ b/src/appleseed/renderer/kernel/shading/closures.cpp @@ -31,7 +31,6 @@ // appleseed.renderer headers. #include "renderer/global/globallogger.h" -#include "renderer/modeling/bsdf/alsurfacelayerbrdf.h" #include "renderer/modeling/bsdf/ashikhminbrdf.h" #include "renderer/modeling/bsdf/blinnbrdf.h" #include "renderer/modeling/bsdf/diffusebtdf.h" @@ -94,7 +93,7 @@ namespace // Closure functions. // - typedef void(*convert_closure_fun)( + typedef void (*convert_closure_fun)( CompositeSurfaceClosure& composite_closure, const Basis3f& shading_basis, const void* osl_params, @@ -112,6 +111,15 @@ namespace { } + typedef int (*closure_get_modes)(); + + closure_get_modes g_closure_get_modes_funs[NumClosuresIDs]; + + int closure_no_modes() + { + return 0; + } + // // Closures. // @@ -139,6 +147,11 @@ namespace return AshikhminShirleyID; } + static int modes() + { + return ScatteringMode::Diffuse | ScatteringMode::Glossy; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -156,6 +169,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -232,6 +246,11 @@ namespace return BlinnID; } + static int modes() + { + return ScatteringMode::Glossy; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -245,6 +264,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -315,6 +335,11 @@ namespace return DiffuseID; } + static int modes() + { + return ScatteringMode::Diffuse; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -326,6 +351,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -380,6 +406,11 @@ namespace return DisneyID; } + static int modes() + { + return ScatteringMode::Diffuse | ScatteringMode::Glossy; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -403,6 +434,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -480,6 +512,7 @@ namespace values->m_radiance.set_intent(Spectrum::Illuminance); values->m_radiance = weight / max_weight_component; values->m_radiance_multiplier = max_weight_component; + values->m_exposure = 0.0f; } }; @@ -511,6 +544,11 @@ namespace return GlassID; } + static int modes() + { + return ScatteringMode::Glossy | ScatteringMode::Specular; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -533,6 +571,11 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + + g_closure_get_modes_funs[id()] = &modes; + g_closure_get_modes_funs[GlassBeckmannID] = &modes; + g_closure_get_modes_funs[GlassGGXID] = &modes; + g_closure_get_modes_funs[GlassSTDID] = &modes; } static void convert_closure( @@ -606,6 +649,11 @@ namespace return GlossyID; } + static int modes() + { + return ScatteringMode::Glossy | ScatteringMode::Specular; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -623,6 +671,11 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + + g_closure_get_modes_funs[id()] = &modes; + g_closure_get_modes_funs[GlossyBeckmannID] = &modes; + g_closure_get_modes_funs[GlossyGGXID] = &modes; + g_closure_get_modes_funs[GlossySTDID] = &modes; } static void convert_closure( @@ -719,6 +772,11 @@ namespace return MetalID; } + static int modes() + { + return ScatteringMode::Glossy | ScatteringMode::Specular; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -737,6 +795,11 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + + g_closure_get_modes_funs[id()] = &modes; + g_closure_get_modes_funs[MetalBeckmannID] = &modes; + g_closure_get_modes_funs[MetalGGXID] = &modes; + g_closure_get_modes_funs[MetalSTDID] = &modes; } static void convert_closure( @@ -800,6 +863,11 @@ namespace return OrenNayarID; } + static int modes() + { + return ScatteringMode::Diffuse; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -812,6 +880,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -855,6 +924,11 @@ namespace return PhongID; } + static int modes() + { + return ScatteringMode::Glossy; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -867,6 +941,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -914,6 +989,11 @@ namespace return ReflectionID; } + static int modes() + { + return ScatteringMode::Specular; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -926,6 +1006,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -970,6 +1051,11 @@ namespace return SheenID; } + static int modes() + { + return ScatteringMode::Diffuse; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -981,6 +1067,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -1163,6 +1250,11 @@ namespace return TranslucentID; } + static int modes() + { + return ScatteringMode::Diffuse; + } + static void register_closure(OSL::ShadingSystem& shading_system) { const OSL::ClosureParam params[] = @@ -1174,6 +1266,7 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); g_closure_convert_funs[id()] = &convert_closure; + g_closure_get_modes_funs[id()] = &modes; } static void convert_closure( @@ -1224,113 +1317,6 @@ namespace shading_system.register_closure(name(), id(), params, 0, 0); } }; - - // - // Layered closures. - // - - struct LayeredClosureBaseParams - { - void* substrate; - }; - - struct AlSurfaceLayerClosure - { - typedef AlSurfaceLayerBRDFInputValues InputValues; - - struct Params - : public LayeredClosureBaseParams - { - int distribution; - OSL::Vec3 N; - OSL::Vec3 T; - OSL::Color3 reflectance; - float roughness; - float anisotropy; - int fresnel_mode; - float ior; - OSL::Color3 normal_reflectance; - OSL::Color3 edge_tint; - }; - - static const char* name() - { - return "as_alsurface_layer"; - } - - static ClosureID id() - { - return AlSurfaceLayerID; - } - - static void register_closure(OSL::ShadingSystem& shading_system) - { - const OSL::ClosureParam params[] = - { - CLOSURE_CLOSURE_PARAM(Params, substrate), - CLOSURE_INT_PARAM(Params, distribution), - CLOSURE_VECTOR_PARAM(Params, N), - CLOSURE_VECTOR_PARAM(Params, T), - CLOSURE_COLOR_PARAM(Params, reflectance), - CLOSURE_FLOAT_PARAM(Params, roughness), - CLOSURE_FLOAT_PARAM(Params, anisotropy), - CLOSURE_INT_PARAM(Params, fresnel_mode), - CLOSURE_FLOAT_PARAM(Params, ior), - CLOSURE_COLOR_PARAM(Params, normal_reflectance), - CLOSURE_COLOR_PARAM(Params, edge_tint), - CLOSURE_FINISH_PARAM(Params) - }; - - shading_system.register_closure(name(), id(), params, 0, 0); - - g_closure_convert_funs[id()] = &convert_closure; - } - - static void convert_closure( - CompositeSurfaceClosure& composite_closure, - const Basis3f& shading_basis, - const void* osl_params, - const Color3f& weight, - Arena& arena) - { - const Params* p = static_cast(osl_params); - - InputValues* values = - composite_closure.add_closure( - AlSurfaceLayerID, - shading_basis, - weight, - p->N, - p->T, - arena); - - values->m_substrate = p->substrate; - values->m_substrate_closure_data = 0; - values->m_osl_bsdf = 0; - - values->m_distribution = p->distribution; - values->m_reflectance = p->reflectance; - values->m_roughness = p->roughness; - values->m_anisotropy = saturate(p->anisotropy); - - values->m_fresnel_mode = p->fresnel_mode; - values->m_ior = p->ior; - values->m_normal_reflectance = p->normal_reflectance; - values->m_edge_tint = p->edge_tint; - } - }; - - const OSL::ClosureColor* get_nested_closure_color( - const size_t closure_id, - const void* params) - { - assert(closure_id >= FirstLayeredClosure); - - const LayeredClosureBaseParams* p = - static_cast(params); - - return static_cast(p->substrate); - } } @@ -1343,53 +1329,6 @@ CompositeClosure::CompositeClosure() { } -void CompositeClosure::compute_cdf() -{ - const size_t closure_count = get_closure_count(); - - if (closure_count == 1) - { - m_pdf_weights[0] = 1.0f; - m_cdf[0] = 1.0f; - } - else if (closure_count > 1) - { - float total_weight = 0.0f; - for (size_t i = 0; i < closure_count; ++i) - { - total_weight += m_pdf_weights[i]; - m_cdf[i] = total_weight; - } - - const float rcp_total_weight = 1.0f / total_weight; - - for (size_t i = 0; i < closure_count; ++i) - m_pdf_weights[i] *= rcp_total_weight; - - for (size_t i = 0; i < closure_count - 1; ++i) - m_cdf[i] *= rcp_total_weight; - - m_cdf[closure_count - 1] = 1.0f; - } -} - -size_t CompositeClosure::choose_closure(SamplingContext& sampling_context) const -{ - assert(get_closure_count() > 0); - - if (get_closure_count() == 1) - return 0; - - sampling_context.split_in_place(1, 1); - const float s = sampling_context.next2(); - return choose_closure(s); -} - -size_t CompositeClosure::choose_closure(const float w) const -{ - return sample_cdf_linear_search(m_cdf, w); -} - void CompositeClosure::compute_closure_shading_basis( const Vector3f& normal, const Basis3f& original_shading_basis) @@ -1500,8 +1439,8 @@ InputValues* CompositeClosure::do_add_closure( const float w = luminance(weight); assert(w > 0.0f); - m_pdf_weights[m_closure_count] = w; m_weights[m_closure_count] = weight; + m_scalar_weights[m_closure_count] = w; if (!has_tangent) compute_closure_shading_basis(normal, original_shading_basis); @@ -1517,6 +1456,26 @@ InputValues* CompositeClosure::do_add_closure( return values; } +void CompositeClosure::compute_pdfs(float pdfs[MaxClosureEntries]) +{ + const size_t closure_count = get_closure_count(); + + float total_weight = 0.0f; + for (size_t i = 0; i < closure_count; ++i) + { + pdfs[i] = m_scalar_weights[i]; + total_weight += pdfs[i]; + } + + if (total_weight != 0.0f) + { + const float rcp_total_weight = 1.0f / total_weight; + + for (size_t i = 0; i < closure_count; ++i) + pdfs[i] *= rcp_total_weight; + } +} + // // CompositeSurfaceClosure class implementation. @@ -1529,7 +1488,6 @@ CompositeSurfaceClosure::CompositeSurfaceClosure( : m_ior_count(0) { process_closure_tree(ci, original_shading_basis, Color3f(1.0f), arena); - compute_cdf(); if (m_ior_count == 0) { @@ -1557,6 +1515,51 @@ CompositeSurfaceClosure::CompositeSurfaceClosure( } } +int CompositeSurfaceClosure::compute_pdfs( + const int modes, + float pdfs[MaxClosureEntries]) const +{ + memset(pdfs, 0, sizeof(float) * MaxClosureEntries); + + int num_closures = 0; + float sum_weights = 0.0f; + + for (size_t i = 0, e = get_closure_count(); i < e; ++i) + { + const ClosureID cid = m_closure_types[i]; + const int closure_modes = g_closure_get_modes_funs[cid](); + + if (closure_modes & modes) + { + pdfs[i] = m_scalar_weights[i]; + sum_weights += m_scalar_weights[i]; + ++num_closures; + } + else + pdfs[i] = 0.0f; + } + + if (sum_weights != 0.0f) + { + const float rcp_sum_weights = 1.0f / sum_weights; + for (size_t i = 0, e = get_closure_count(); i < e; ++i) + pdfs[i] *= rcp_sum_weights; + } + + return num_closures; +} + +size_t CompositeSurfaceClosure::choose_closure( + const float w, + const size_t num_closures, + float pdfs[MaxClosureEntries]) const +{ + assert(num_closures > 0); + assert(num_closures < MaxClosureEntries); + + return sample_pdf_linear_search(pdfs, num_closures, w); +} + void CompositeSurfaceClosure::add_ior( const foundation::Color3f& weight, const float ior) @@ -1631,7 +1634,13 @@ CompositeSubsurfaceClosure::CompositeSubsurfaceClosure( Arena& arena) { process_closure_tree(ci, original_shading_basis, Color3f(1.0f), arena); - compute_cdf(); + compute_pdfs(m_pdfs); +} + +size_t CompositeSubsurfaceClosure::choose_closure(const float w) const +{ + assert(get_closure_count() > 0); + return sample_pdf_linear_search(m_pdfs, get_closure_count(), w); } void CompositeSubsurfaceClosure::process_closure_tree( @@ -1677,12 +1686,6 @@ void CompositeSubsurfaceClosure::process_closure_tree( arena); } } - else if (c->id >= FirstLayeredClosure) - { - // For now, we just recurse. - const OSL::ClosureColor* nested = get_nested_closure_color(c->id, c->data()); - process_closure_tree(nested, original_shading_basis, weight * Color3f(c->w), arena); - } } break; } @@ -1698,7 +1701,13 @@ CompositeEmissionClosure::CompositeEmissionClosure( Arena& arena) { process_closure_tree(ci, Color3f(1.0f), arena); - compute_cdf(); + compute_pdfs(m_pdfs); +} + +size_t CompositeEmissionClosure::choose_closure(const float w) const +{ + assert(get_closure_count() > 0); + return sample_pdf_linear_search(m_pdfs, get_closure_count(), w); } template @@ -1717,7 +1726,7 @@ InputValues* CompositeEmissionClosure::add_closure( m_closure_types[m_closure_count] = closure_type; m_weights[m_closure_count] = weight; - m_pdf_weights[m_closure_count] = max_weight_component; + m_pdfs[m_closure_count] = max_weight_component; InputValues* values = arena.allocate(); m_input_values[m_closure_count] = values; @@ -1770,12 +1779,6 @@ void CompositeEmissionClosure::process_closure_tree( max_weight_component, arena); } - else if (c->id >= FirstLayeredClosure) - { - // For now, we just recurse. - const OSL::ClosureColor* nested = get_nested_closure_color(c->id, c->data()); - process_closure_tree(nested, w, arena); - } } } break; @@ -1818,12 +1821,6 @@ namespace if (c->id == closure_id) return Color3f(c->w); - else if (c->id >= FirstLayeredClosure) - { - // Recurse inside the layered closure. - const OSL::ClosureColor* nested = get_nested_closure_color(c->id, c->data()); - return Color3f(c->w) * do_process_closure_id_tree(nested, closure_id); - } else return Color3f(0.0f); } break; @@ -1851,27 +1848,6 @@ Color3f process_background_tree(const OSL::ClosureColor* ci) return do_process_closure_id_tree(ci, BackgroundID); } -void inject_layered_closure_values( - const size_t closure_id, - const BSDF* osl_bsdf, - void* data) -{ - assert(closure_id >= FirstLayeredClosure); - - switch (closure_id) - { - case AlSurfaceLayerID: - { - AlSurfaceLayerBRDFInputValues* values = - static_cast(data); - values->m_osl_bsdf = osl_bsdf; - } - break; - - assert_otherwise; - } -} - namespace { template @@ -1885,9 +1861,11 @@ namespace void register_closures(OSL::ShadingSystem& shading_system) { for (size_t i = 0; i < NumClosuresIDs; ++i) + { g_closure_convert_funs[i] = &convert_closure_nop; + g_closure_get_modes_funs[i] = &closure_no_modes; + } - register_closure(shading_system); register_closure(shading_system); register_closure(shading_system); register_closure(shading_system); diff --git a/src/appleseed/renderer/kernel/shading/closures.h b/src/appleseed/renderer/kernel/shading/closures.h index 90d492da80..7e74806bb3 100644 --- a/src/appleseed/renderer/kernel/shading/closures.h +++ b/src/appleseed/renderer/kernel/shading/closures.h @@ -80,6 +80,7 @@ enum ClosureID GlassBeckmannID, GlassGGXID, GlassSTDID, + LastGlassClosure = GlassSTDID, GlossyID, GlossyBeckmannID, @@ -108,10 +109,6 @@ enum ClosureID HoldoutID, TransparentID, - // Layered BSDF closures. (Must be last.) - FirstLayeredClosure, - AlSurfaceLayerID = FirstLayeredClosure, - NumClosuresIDs }; @@ -138,14 +135,15 @@ class APPLESEED_ALIGN(16) CompositeClosure : public foundation::NonCopyable { public: + enum { MaxClosureEntries = 16 }; + size_t get_closure_count() const; + ClosureID get_closure_type(const size_t index) const; - const Spectrum& get_closure_weight(const size_t index) const; - float get_closure_pdf_weight(const size_t index) const; void* get_closure_input_values(const size_t index) const; - size_t choose_closure(SamplingContext& sampling_context) const; - size_t choose_closure(const float w) const; + const Spectrum& get_closure_weight(const size_t index) const; + float get_closure_scalar_weight(const size_t index) const; const foundation::Basis3f& get_closure_shading_basis(const size_t index) const; @@ -176,20 +174,15 @@ class APPLESEED_ALIGN(16) CompositeClosure foundation::Arena& arena); protected: - enum { MaxClosureEntries = 16 }; - size_t m_closure_count; void* m_input_values[MaxClosureEntries]; ClosureID m_closure_types[MaxClosureEntries]; Spectrum m_weights[MaxClosureEntries]; - float m_cdf[MaxClosureEntries]; - float m_pdf_weights[MaxClosureEntries]; + float m_scalar_weights[MaxClosureEntries]; foundation::Basis3f m_bases[MaxClosureEntries]; CompositeClosure(); - void compute_cdf(); - template InputValues* do_add_closure( const ClosureID closure_type, @@ -199,6 +192,8 @@ class APPLESEED_ALIGN(16) CompositeClosure const bool has_tangent, const foundation::Vector3f& tangent, foundation::Arena& arena); + + void compute_pdfs(float pdfs[MaxClosureEntries]); }; @@ -215,6 +210,15 @@ class APPLESEED_ALIGN(16) CompositeSurfaceClosure const OSL::ClosureColor* ci, foundation::Arena& arena); + int compute_pdfs( + const int modes, + float pdf[MaxClosureEntries]) const; + + size_t choose_closure( + const float w, + const size_t num_closures, + float pdfs[MaxClosureEntries]) const; + void add_ior( const foundation::Color3f& weight, const float ior); @@ -247,13 +251,18 @@ class APPLESEED_ALIGN(16) CompositeSubsurfaceClosure const OSL::ClosureColor* ci, foundation::Arena& arena); + float get_closure_pdf(const size_t index) const; + + size_t choose_closure(const float w) const; + private: + float m_pdfs[MaxClosureEntries]; + void process_closure_tree( const OSL::ClosureColor* closure, const foundation::Basis3f& original_shading_basis, const foundation::Color3f& weight, foundation::Arena& arena); - }; @@ -276,7 +285,13 @@ class APPLESEED_ALIGN(16) CompositeEmissionClosure const float max_weight_component, foundation::Arena& arena); + float get_closure_pdf(const size_t index) const; + + size_t choose_closure(const float w) const; + private: + float m_pdfs[MaxClosureEntries]; + void process_closure_tree( const OSL::ClosureColor* closure, const foundation::Color3f& weight, @@ -292,11 +307,6 @@ void process_transparency_tree(const OSL::ClosureColor* ci, Alpha& alpha); float process_holdout_tree(const OSL::ClosureColor* ci); foundation::Color3f process_background_tree(const OSL::ClosureColor* ci); -void inject_layered_closure_values( - const size_t closure_id, - const BSDF* osl_bsdf, - void* data); - void register_closures(OSL::ShadingSystem& shading_system); @@ -315,22 +325,22 @@ inline ClosureID CompositeClosure::get_closure_type(const size_t index) const return m_closure_types[index]; } -inline const Spectrum& CompositeClosure::get_closure_weight(const size_t index) const +inline void* CompositeClosure::get_closure_input_values(const size_t index) const { assert(index < get_closure_count()); - return m_weights[index]; + return m_input_values[index]; } -inline float CompositeClosure::get_closure_pdf_weight(const size_t index) const +inline const Spectrum& CompositeClosure::get_closure_weight(const size_t index) const { assert(index < get_closure_count()); - return m_pdf_weights[index]; + return m_weights[index]; } -inline void* CompositeClosure::get_closure_input_values(const size_t index) const +inline float CompositeClosure::get_closure_scalar_weight(const size_t index) const { assert(index < get_closure_count()); - return m_input_values[index]; + return m_scalar_weights[index]; } inline const foundation::Basis3f& CompositeClosure::get_closure_shading_basis(const size_t index) const @@ -339,6 +349,28 @@ inline const foundation::Basis3f& CompositeClosure::get_closure_shading_basis(co return m_bases[index]; } + +// +// CompositeSubsurfaceClosure class implementation. +// + +inline float CompositeSubsurfaceClosure::get_closure_pdf(const size_t index) const +{ + assert(index < get_closure_count()); + return m_pdfs[index]; +} + + +// +// CompositeEmissionClosure class implementation. +// + +inline float CompositeEmissionClosure::get_closure_pdf(const size_t index) const +{ + assert(index < get_closure_count()); + return m_pdfs[index]; +} + } // namespace renderer #endif // !APPLESEED_RENDERER_KERNEL_SHADING_CLOSURES_H diff --git a/src/appleseed/renderer/kernel/shading/oslshadergroupexec.cpp b/src/appleseed/renderer/kernel/shading/oslshadergroupexec.cpp index 4139314f0a..a4a02edf1b 100644 --- a/src/appleseed/renderer/kernel/shading/oslshadergroupexec.cpp +++ b/src/appleseed/renderer/kernel/shading/oslshadergroupexec.cpp @@ -33,6 +33,7 @@ #include "renderer/kernel/shading/closures.h" #include "renderer/kernel/shading/shadingpoint.h" #include "renderer/kernel/shading/shadingray.h" +#include "renderer/modeling/bsdf/bsdf.h" #include "renderer/modeling/shadergroup/shadergroup.h" // Standard headers. @@ -182,20 +183,6 @@ Color3f OSLShaderGroupExec::execute_background( return process_background_tree(sg.Ci); } -void OSLShaderGroupExec::execute_surface_shader( - const ShaderGroup& shader_group, - const ShadingPoint& shading_point, - const Color3f& color, - const float alpha) const -{ - shading_point.m_surface_shader_color = color; - shading_point.m_surface_shader_alpha = alpha; - do_execute( - shader_group, - shading_point, - shading_point.get_ray().m_flags); -} - void OSLShaderGroupExec::do_execute( const ShaderGroup& shader_group, const ShadingPoint& shading_point, @@ -224,12 +211,14 @@ void OSLShaderGroupExec::choose_bsdf_closure_shading_basis( shading_point.get_osl_shader_globals().Ci, m_arena); - if (c.get_closure_count() > 0) - { - const size_t index = c.choose_closure(s[1]); - shading_point.set_shading_basis( - Basis3d(c.get_closure_shading_basis(index))); - } + float pdfs[CompositeSurfaceClosure::MaxClosureEntries]; + const size_t num_closures = c.compute_pdfs(ScatteringMode::All, pdfs); + if (num_closures == 0) + return; + + const size_t index = c.choose_closure(s[1], num_closures, pdfs); + shading_point.set_shading_basis( + Basis3d(c.get_closure_shading_basis(index))); } } // namespace renderer diff --git a/src/appleseed/renderer/kernel/shading/oslshadergroupexec.h b/src/appleseed/renderer/kernel/shading/oslshadergroupexec.h index 1669f1a9ce..7f00436c10 100644 --- a/src/appleseed/renderer/kernel/shading/oslshadergroupexec.h +++ b/src/appleseed/renderer/kernel/shading/oslshadergroupexec.h @@ -110,12 +110,6 @@ class OSLShaderGroupExec const ShaderGroup& shader_group, const foundation::Vector3f& outgoing) const; - void execute_surface_shader( - const ShaderGroup& shader_group, - const ShadingPoint& shading_point, - const foundation::Color3f& color, - const float alpha) const; - void do_execute( const ShaderGroup& shader_group, const ShadingPoint& shading_point, diff --git a/src/appleseed/renderer/kernel/shading/shadingcontext.cpp b/src/appleseed/renderer/kernel/shading/shadingcontext.cpp index 6c42e8f9b3..19dacb895e 100644 --- a/src/appleseed/renderer/kernel/shading/shadingcontext.cpp +++ b/src/appleseed/renderer/kernel/shading/shadingcontext.cpp @@ -145,19 +145,6 @@ void ShadingContext::execute_osl_background( outgoing); } -void ShadingContext::execute_osl_surface_shader( - const ShaderGroup& shader_group, - const ShadingPoint& shading_point, - const Color3f& color, - const float alpha) const -{ - m_shadergroup_exec.execute_surface_shader( - shader_group, - shading_point, - color, - alpha); -} - void ShadingContext::choose_bsdf_closure_shading_basis( const ShadingPoint& shading_point, const Vector2f& s) const diff --git a/src/appleseed/renderer/kernel/shading/shadingcontext.h b/src/appleseed/renderer/kernel/shading/shadingcontext.h index 80239dc864..96c71b7040 100644 --- a/src/appleseed/renderer/kernel/shading/shadingcontext.h +++ b/src/appleseed/renderer/kernel/shading/shadingcontext.h @@ -132,12 +132,6 @@ class ShadingContext const foundation::Vector3f& outgoing, Spectrum& value) const; - void execute_osl_surface_shader( - const ShaderGroup& shader_group, - const ShadingPoint& shading_point, - const foundation::Color3f& color, - const float alpha) const; - // Choose one of the bsdf closures and set its shading basis in shading point. void choose_bsdf_closure_shading_basis( const ShadingPoint& shading_point, diff --git a/src/appleseed/renderer/meta/tests/test_sss.cpp b/src/appleseed/renderer/meta/tests/test_sss.cpp index 31c937eea7..b79232d0e3 100644 --- a/src/appleseed/renderer/meta/tests/test_sss.cpp +++ b/src/appleseed/renderer/meta/tests/test_sss.cpp @@ -56,9 +56,6 @@ #include "foundation/utility/arena.h" #include "foundation/utility/autoreleaseptr.h" #include "foundation/utility/gnuplotfile.h" -#ifdef APPLESEED_WITH_PARTIO -#include "foundation/utility/partiofile.h" -#endif #include "foundation/utility/poison.h" #include "foundation/utility/string.h" #include "foundation/utility/test.h" @@ -696,76 +693,6 @@ TEST_SUITE(Renderer_Modeling_BSSRDF_SSS) plotfile.write("unit tests/outputs/test_sss_normalized_diffusion_cdf.gnuplot"); } -#ifdef APPLESEED_WITH_PARTIO - - TEST_CASE(NormalizedDiffusion_GeneratePartioFile) - { - const float A = 1.0f; - const float L = 1; - const float s = normalized_diffusion_s_dmfp(A); - - const size_t SampleCount = 1000; - MersenneTwister rng; - - PartioFile particles; - Partio::ParticleAttribute pos_attr = particles.add_vector_attribute("position"); - Partio::ParticleAttribute col_attr = particles.add_color_attribute("color"); - - for (size_t i = 0; i < SampleCount; ++i) - { - const float u = rand_double2(rng); - const float r = normalized_diffusion_sample(u, L, s); - const float phi = TwoPi() * rand_double2(rng); - const Vector3d sample(r * cos(phi), 0.0f, r * sin(phi)); - - Partio::ParticleIndex p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, sample); - particles.set_color_attribute(p, col_attr, Color3d(1.0, 1.0, 1.0)); - } - - // Add a circle of particles of radius max_radius. - const size_t CircleCount = 100; - const float max_radius = normalized_diffusion_max_radius(L, s); - - for (size_t i = 0; i < CircleCount; ++i) - { - const float phi = fit(i, 0, CircleCount - 1, 0.0f, TwoPi()); - const Vector3d c(max_radius * cos(phi), 0.0f, max_radius * sin(phi)); - - Partio::ParticleIndex p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, c); - particles.set_color_attribute(p, col_attr, Color3d(0.0, 0.0, 1.0)); - } - - // Add particles with the value of the profile. - const size_t ProfileCount = 500; - for (size_t i = 0; i < ProfileCount; ++i) - { - const float r = fit(i, 0, ProfileCount - 1, 0.0f, max_radius); - const float v = normalized_diffusion_profile(r, L, s, A) * r; - - Partio::ParticleIndex p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, Vector3d(r, v, 0.0f)); - particles.set_color_attribute(p, col_attr, Color3d(1.0, 0.0, 0.0)); - - p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, Vector3d(-r, v, 0.0f)); - particles.set_color_attribute(p, col_attr, Color3d(1.0, 0.0, 0.0)); - - p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, Vector3d(0.0f, v, r)); - particles.set_color_attribute(p, col_attr, Color3d(1.0, 0.0, 0.0)); - - p = particles.add_particle(); - particles.set_vector_attribute(p, pos_attr, Vector3d(0.0f, v, -r)); - particles.set_color_attribute(p, col_attr, Color3d(1.0, 0.0, 0.0)); - } - - particles.write("unit tests/outputs/test_sss_nd_sampling_particles.bgeo"); - } - -#endif - TEST_CASE(NormalizedDiffusion_MaxRadius) { MersenneTwister rng; diff --git a/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.cpp b/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.cpp deleted file mode 100644 index 429d5dc884..0000000000 --- a/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.cpp +++ /dev/null @@ -1,504 +0,0 @@ - -// -// This source file is part of appleseed. -// Visit http://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -// Interface header. -#include "alsurfacelayerbrdf.h" - -// appleseed.renderer headers. -#include "renderer/kernel/lighting/scatteringmode.h" -#include "renderer/kernel/shading/closures.h" -#include "renderer/kernel/shading/shadingcontext.h" -#include "renderer/modeling/bsdf/bsdf.h" -#include "renderer/modeling/bsdf/bsdfwrapper.h" -#include "renderer/modeling/bsdf/fresnel.h" -#include "renderer/modeling/bsdf/microfacethelper.h" -#include "renderer/modeling/bsdf/specularhelper.h" -#include "renderer/utility/messagecontext.h" -#include "renderer/utility/paramarray.h" - -// appleseed.foundation headers. -#include "foundation/math/basis.h" -#include "foundation/math/microfacet.h" -#include "foundation/math/minmax.h" -#include "foundation/math/sampling/mappings.h" -#include "foundation/math/vector.h" -#include "foundation/utility/api/specializedapiarrays.h" -#include "foundation/utility/arena.h" -#include "foundation/utility/containers/dictionary.h" -#include "foundation/utility/makevector.h" -#include "foundation/utility/otherwise.h" - -// Standard headers. -#include -#include -#include -#include - -// Forward declarations. -namespace foundation { class IAbortSwitch; } -namespace renderer { class Assembly; } -namespace renderer { class Project; } - -using namespace foundation; -using namespace std; - -namespace renderer -{ - -namespace -{ - // - // AlSurfaceLayer BRDF. - // - // References: - // - // https://bitbucket.org/anderslanglands/alshaders/wiki/Home - // http://blog.selfshadow.com/publications/s2014-shading-course/langlands/s2014_pbs_alshaders_notes.pdf - // - - const char* Model = "al_surface_layer_brdf"; - - class AlSurfaceLayerBRDFImpl - : public BSDF - { - public: - AlSurfaceLayerBRDFImpl( - const char* name, - const ParamArray& params) - : BSDF(name, AllBSDFTypes, ScatteringMode::All, params) - { - } - - virtual void release() APPLESEED_OVERRIDE - { - delete this; - } - - virtual const char* get_model() const APPLESEED_OVERRIDE - { - return Model; - } - - virtual size_t compute_input_data_size() const APPLESEED_OVERRIDE - { - return sizeof(InputValues); - } - - virtual void prepare_inputs( - Arena& arena, - const ShadingPoint& shading_point, - void* data) const APPLESEED_OVERRIDE - { - InputValues* values = static_cast(data); - - new (&values->m_precomputed) InputValues::Precomputed(); - - const float alpha = square(values->m_roughness); - values->m_precomputed.m_alpha_x = alpha; - values->m_precomputed.m_alpha_y = alpha; - - if (values->m_anisotropy != 0.5f) - { - const float t = square(2.0f * values->m_anisotropy - 1.0f); - - if (values->m_anisotropy < 0.5f) - values->m_precomputed.m_alpha_x = lerp(alpha, 1.0f, t); - else - values->m_precomputed.m_alpha_y = lerp(alpha, 1.0f, t); - } - - values->m_precomputed.m_alpha_x = clamp(values->m_precomputed.m_alpha_x, 0.001f, 0.999f); - values->m_precomputed.m_alpha_y = clamp(values->m_precomputed.m_alpha_y, 0.001f, 0.999f); - - // Allocate memory and initialize the nested closure tree. - values->m_substrate_closure_data = arena.allocate(sizeof(CompositeSurfaceClosure)); - CompositeSurfaceClosure* c = static_cast(values->m_substrate_closure_data); - new (c) CompositeSurfaceClosure( - Basis3f(shading_point.get_shading_basis()), - static_cast(values->m_substrate), - arena); - - // Inject values into any children layered closures. - assert(values->m_osl_bsdf); - for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) - { - const ClosureID cid = c->get_closure_type(i); - - if (cid >= FirstLayeredClosure) - inject_layered_closure_values(cid, values->m_osl_bsdf, c->get_closure_input_values(i)); - } - - // Prepare the inputs of children BSDFs. - values->m_osl_bsdf->prepare_inputs( - arena, - shading_point, - values->m_substrate_closure_data); - } - - virtual void sample( - SamplingContext& sampling_context, - const void* data, - const bool adjoint, - const bool cosine_mult, - const int modes, - BSDFSample& sample) const APPLESEED_OVERRIDE - { - const InputValues* values = static_cast(data); - - const Basis3f& shading_basis(sample.m_shading_basis); - Vector3f wo = shading_basis.transform_to_local(sample.m_outgoing.get_value()); - - // Compute the microfacet normal by sampling the MDF. - const MDF& mdf = pick_mdf(values->m_distribution); - sampling_context.split_in_place(4, 1); - const Vector4f s = sampling_context.next2(); - Vector3f m = mdf.sample( - wo, - Vector3f(s[0], s[1], s[2]), - values->m_precomputed.m_alpha_x, - values->m_precomputed.m_alpha_y, - 0.0f); - assert(m.y > 0.0f); - - float layer_weight; - fresnel_term(*values, wo, m, sample.m_value, layer_weight); - - // Choose between layer and substrate. - if (s[3] < layer_weight) - { - // Compute the reflected direction. - const Vector3f wi = improve_normalization(reflect(wo, m)); - if (wi.y * wo.y <= 0.0f) - return; - - evaluate_reflection( - *values, - mdf, - wi, - wo, - m, - sample.m_value); - - sample.m_probability = reflection_pdf(*values, mdf, wo, m) * layer_weight; - sample.m_mode = ScatteringMode::Glossy; - sample.m_incoming = Dual3f(shading_basis.transform_to_parent(wi)); - sample.compute_reflected_differentials(); - } - else - { - values->m_osl_bsdf->sample( - sampling_context, - values->m_substrate_closure_data, - adjoint, - false, // do not multiply by |cos(incoming, normal)| - modes, - sample); - sample.m_value *= 1.0f - layer_weight; - sample.m_probability *= 1.0f - layer_weight; - } - } - - virtual float evaluate( - const void* data, - const bool adjoint, - const bool cosine_mult, - const Vector3f& geometric_normal, - const Basis3f& shading_basis, - const Vector3f& outgoing, - const Vector3f& incoming, - const int modes, - Spectrum& value) const APPLESEED_OVERRIDE - { - const InputValues* values = static_cast(data); - - const Vector3f wi = shading_basis.transform_to_local(incoming); - const Vector3f wo = shading_basis.transform_to_local(outgoing); - - const Vector3f m = half_reflection_vector(wi, wo); - - float probability = 0.0f; - value.resize(values->m_reflectance.size()); - value.set(0.0f); - - float layer_weight; - Spectrum f_value; - fresnel_term(*values, wo, m, f_value, layer_weight); - - if (ScatteringMode::has_glossy(modes) && (wi.y * wo.y >= 0.0f)) - { - const MDF& mdf = pick_mdf(values->m_distribution); - value = f_value; - evaluate_reflection(*values, mdf, wi, wo, m, value); - probability = layer_weight * reflection_pdf(*values, mdf, wo, m); - } - - const float substrate_weight = 1.0f - layer_weight; - - if (substrate_weight > 0.0f) - { - Spectrum substrate_value; - probability += values->m_osl_bsdf->evaluate( - values->m_substrate_closure_data, - adjoint, - false, // do not multiply by |cos(incoming, normal)| - geometric_normal, - shading_basis, - outgoing, - incoming, - modes, - substrate_value) * substrate_weight; - madd(value, substrate_value, substrate_weight); - } - - return probability; - } - - virtual float evaluate_pdf( - const void* data, - const Vector3f& geometric_normal, - const Basis3f& shading_basis, - const Vector3f& outgoing, - const Vector3f& incoming, - const int modes) const APPLESEED_OVERRIDE - { - const InputValues* values = static_cast(data); - - const Vector3f wi = shading_basis.transform_to_local(incoming); - const Vector3f wo = shading_basis.transform_to_local(outgoing); - const Vector3f m = half_reflection_vector(wi, wo); - - float layer_weight; - Spectrum value; - fresnel_term(*values, wo, m, value, layer_weight); - - float probability = 0.0f; - - if (ScatteringMode::has_glossy(modes) && (wi.y * wo.y >= 0.0f)) - { - const MDF& mdf = pick_mdf(values->m_distribution); - probability = layer_weight * reflection_pdf(*values, mdf, wo, m); - } - - const float substrate_weight = 1.0f - layer_weight; - - if (substrate_weight > 0.0f) - { - probability += values->m_osl_bsdf->evaluate_pdf( - values->m_substrate_closure_data, - geometric_normal, - shading_basis, - outgoing, - incoming, - modes) * substrate_weight; - } - - return probability; - } - - float sample_ior( - SamplingContext& sampling_context, - const void* data) const APPLESEED_OVERRIDE - { - // Forward to substrate. - const InputValues* values = static_cast(data); - return values->m_osl_bsdf->sample_ior( - sampling_context, - values->m_substrate_closure_data); - } - - void compute_absorption( - const void* data, - const float distance, - Spectrum& absorption) const APPLESEED_OVERRIDE - { - // Forward to substrate. - const InputValues* values = static_cast(data); - values->m_osl_bsdf->compute_absorption( - values->m_substrate_closure_data, - distance, - absorption); - } - - private: - typedef AlSurfaceLayerBRDFInputValues InputValues; - - enum MicrofacetDistribution - { - Beckmann = 0, - GGX - }; - - enum FresnelMode - { - Dielectric = 0, - Metallic - }; - - static const MDF& pick_mdf(int distribution) - { - if (distribution == Beckmann) - return m_beckmann_mdf; - else return m_ggx_mdf; - } - - static void fresnel_term( - const InputValues& values, - Vector3f wo, - const Vector3f& m, - Spectrum& value, - float& weight) - { - if (wo.y < 0.0f) - wo = -wo; - - if (values.m_fresnel_mode == Dielectric) - { - value.resize(values.m_reflectance.size()); - - const float cos_wom = dot(wo, m); - if (cos_wom < 0.0f) - { - value.set(0.0f); - weight = 0.0f; - return; - } - - float f; - fresnel_reflectance_dielectric( - f, - 1.0f / values.m_ior, - min(cos_wom, 1.0f)); - - value = values.m_reflectance; - value *= f; - } - else - { - const Vector3f n(0.0f, 1.0f, 0.0f); - const FresnelFriendlyConductorFun f( - values.m_normal_reflectance, - values.m_edge_tint, - 1.0f); - f(wo, m, n, value); - value *= values.m_reflectance; - } - - weight = saturate(max_value(value)); - } - - static Vector3f half_reflection_vector( - const Vector3f& wi, - const Vector3f& wo) - { - const Vector3f h = normalize(wi + wo); - return h.y < 0.0f ? -h : h; - } - - static void evaluate_reflection( - const InputValues& values, - const MDF& mdf, - const Vector3f& wi, - const Vector3f& wo, - const Vector3f& m, - Spectrum& value) - { - const float denom = abs(4.0f * wo.y * wi.y); - if (denom == 0.0f) - { - value.set(0.0f); - return; - } - - const float D = mdf.D(m, values.m_precomputed.m_alpha_x, values.m_precomputed.m_alpha_y, 0.0f); - const float G = mdf.G(wi, wo, m, values.m_precomputed.m_alpha_x, values.m_precomputed.m_alpha_y, 0.0f); - value *= D * G / denom; - } - - static float reflection_pdf( - const InputValues& values, - const MDF& mdf, - const Vector3f& wo, - const Vector3f& m) - { - const float cos_wom = dot(wo, m); - if (cos_wom == 0.0f) - return 0.0f; - - const float jacobian = 1.0f / (4.0f * abs(cos_wom)); - return jacobian * mdf.pdf(wo, m, values.m_precomputed.m_alpha_x, values.m_precomputed.m_alpha_y, 0.0f); - } - - static GGXMDF m_ggx_mdf; - static BeckmannMDF m_beckmann_mdf; - }; - - GGXMDF AlSurfaceLayerBRDFImpl::m_ggx_mdf; - BeckmannMDF AlSurfaceLayerBRDFImpl::m_beckmann_mdf; - - typedef BSDFWrapper AlSurfaceLayerBRDF; -} - - -// -// AlSurfaceLayerBRDFFactory class implementation. -// - -const char* AlSurfaceLayerBRDFFactory::get_model() const -{ - return Model; -} - -Dictionary AlSurfaceLayerBRDFFactory::get_model_metadata() const -{ - return - Dictionary() - .insert("name", Model) - .insert("label", "AlSurface Layer BRDF"); -} - -DictionaryArray AlSurfaceLayerBRDFFactory::get_input_metadata() const -{ - DictionaryArray metadata; - return metadata; -} - -auto_release_ptr AlSurfaceLayerBRDFFactory::create( - const char* name, - const ParamArray& params) const -{ - return auto_release_ptr(new AlSurfaceLayerBRDF(name, params)); -} - -auto_release_ptr AlSurfaceLayerBRDFFactory::static_create( - const char* name, - const ParamArray& params) -{ - return auto_release_ptr(new AlSurfaceLayerBRDF(name, params)); -} - -} // namespace renderer diff --git a/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.h b/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.h deleted file mode 100644 index 71e150eb65..0000000000 --- a/src/appleseed/renderer/modeling/bsdf/alsurfacelayerbrdf.h +++ /dev/null @@ -1,113 +0,0 @@ - -// -// This source file is part of appleseed. -// Visit http://appleseedhq.net/ for additional information and resources. -// -// This software is released under the MIT license. -// -// Copyright (c) 2017 Esteban Tovagliari, The appleseedhq Organization -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#ifndef APPLESEED_RENDERER_MODELING_BSDF_ALSURFACELAYERBRDF_H -#define APPLESEED_RENDERER_MODELING_BSDF_ALSURFACELAYERBRDF_H - -// appleseed.renderer headers. -#include "renderer/global/globaltypes.h" -#include "renderer/modeling/bsdf/ibsdffactory.h" -#include "renderer/modeling/input/inputarray.h" - -// appleseed.foundation headers. -#include "foundation/platform/compiler.h" -#include "foundation/utility/autoreleaseptr.h" - -// Forward declarations. -namespace foundation { class Dictionary; } -namespace foundation { class DictionaryArray; } -namespace renderer { class BSDF; } -namespace renderer { class ParamArray; } - -namespace renderer -{ - -// -// AlSurface layer BRDF input values. -// - -APPLESEED_DECLARE_INPUT_VALUES(AlSurfaceLayerBRDFInputValues) -{ - // Substrate. - void* m_substrate; - void* m_substrate_closure_data; - const BSDF* m_osl_bsdf; - - // Microfacet. - int m_distribution; - Spectrum m_reflectance; - float m_roughness; - float m_anisotropy; - - // Fresnel. - int m_fresnel_mode; - float m_ior; - Spectrum m_normal_reflectance; - Spectrum m_edge_tint; - - struct Precomputed - { - float m_alpha_x; - float m_alpha_y; - }; - - Precomputed m_precomputed; -}; - - -// -// AlSurface layer BRDF factory. -// - -class APPLESEED_DLLSYMBOL AlSurfaceLayerBRDFFactory - : public IBSDFFactory -{ - public: - // Return a string identifying this BSDF model. - virtual const char* get_model() const APPLESEED_OVERRIDE; - - // Return metadata for this BSDF model. - virtual foundation::Dictionary get_model_metadata() const APPLESEED_OVERRIDE; - - // Return metadata for the inputs of this BSDF model. - virtual foundation::DictionaryArray get_input_metadata() const APPLESEED_OVERRIDE; - - // Create a new BSDF instance. - virtual foundation::auto_release_ptr create( - const char* name, - const ParamArray& params) const APPLESEED_OVERRIDE; - - // Static variant of the create() method above. - static foundation::auto_release_ptr static_create( - const char* name, - const ParamArray& params); -}; - -} // namespace renderer - -#endif // !APPLESEED_RENDERER_MODELING_BSDF_ALSURFACELAYERBRDF_H diff --git a/src/appleseed/renderer/modeling/bsdf/oslbsdf.cpp b/src/appleseed/renderer/modeling/bsdf/oslbsdf.cpp index ee11973d84..6c481734a3 100644 --- a/src/appleseed/renderer/modeling/bsdf/oslbsdf.cpp +++ b/src/appleseed/renderer/modeling/bsdf/oslbsdf.cpp @@ -35,7 +35,6 @@ #include "renderer/kernel/shading/closures.h" #include "renderer/kernel/shading/shadingcontext.h" #include "renderer/kernel/shading/shadingpoint.h" -#include "renderer/modeling/bsdf/alsurfacelayerbrdf.h" #include "renderer/modeling/bsdf/blinnbrdf.h" #include "renderer/modeling/bsdf/bsdf.h" #include "renderer/modeling/bsdf/bsdffactoryregistrar.h" @@ -130,8 +129,6 @@ namespace m_sheen_brdf = create_and_register_bsdf(SheenID, "sheen_brdf"); - - m_alsurface_layer_brdf = create_and_register_alsurface_layer_bsdf(); } virtual void release() APPLESEED_OVERRIDE @@ -169,36 +166,15 @@ namespace const ShadingContext& shading_context, const ShadingPoint& shading_point) const APPLESEED_OVERRIDE { + Arena& arena = shading_context.get_arena(); + CompositeSurfaceClosure* c = - shading_context.get_arena().allocate_noinit(); + arena.allocate_noinit(); new (c) CompositeSurfaceClosure( Basis3f(shading_point.get_shading_basis()), shading_point.get_osl_shader_globals().Ci, - shading_context.get_arena()); - - // Inject values into any children layered closures. - for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) - { - const ClosureID cid = c->get_closure_type(i); - if (cid >= FirstLayeredClosure) - inject_layered_closure_values(cid, this, c->get_closure_input_values(i)); - } - - prepare_inputs( - shading_context.get_arena(), - shading_point, - c); - - return c; - } - - virtual void prepare_inputs( - Arena& arena, - const ShadingPoint& shading_point, - void* data) const APPLESEED_OVERRIDE - { - CompositeSurfaceClosure* c = static_cast(data); + arena); for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) { @@ -208,6 +184,8 @@ namespace shading_point, c->get_closure_input_values(i)); } + + return c; } virtual void sample( @@ -220,24 +198,63 @@ namespace { const CompositeSurfaceClosure* c = static_cast(data); - if (c->get_closure_count() > 0) + float pdfs[CompositeSurfaceClosure::MaxClosureEntries]; + const int num_matching_closures = c->compute_pdfs(modes, pdfs); + + if (num_matching_closures == 0) + return; + + sampling_context.split_in_place(1, 1); + const size_t closure_index = c->choose_closure( + sampling_context.next2(), + num_matching_closures, + pdfs); + const Basis3f& modified_basis = c->get_closure_shading_basis(closure_index); + + sample.m_shading_basis = modified_basis; + sample.m_shading_point->set_shading_basis(Basis3d(modified_basis)); + + bsdf_from_closure_id(c->get_closure_type(closure_index)) + .sample( + sampling_context, + c->get_closure_input_values(closure_index), + adjoint, + false, + modes, + sample); + sample.m_value *= c->get_closure_weight(closure_index); + + if (sample.m_mode == ScatteringMode::Specular || sample.m_probability == 0.0f) + return; + + sample.m_probability *= pdfs[closure_index]; + pdfs[closure_index] = 0.0f; + + // Evaluate the closures we didn't sample. + for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) { - const size_t closure_index = c->choose_closure(sampling_context); - const Basis3f& modified_basis = c->get_closure_shading_basis(closure_index); - - sample.m_shading_basis = modified_basis; - sample.m_shading_point->set_shading_basis(Basis3d(modified_basis)); - - bsdf_from_closure_id(c->get_closure_type(closure_index)) - .sample( - sampling_context, - c->get_closure_input_values(closure_index), - adjoint, - false, - modes, - sample); - - sample.m_value *= c->get_closure_weight(closure_index); + if (pdfs[i] > 0.0f) + { + Spectrum s; + const float pdf = + bsdf_from_closure_id(c->get_closure_type(i)) + .evaluate( + c->get_closure_input_values(i), + adjoint, + false, + sample.m_geometric_normal, + c->get_closure_shading_basis(closure_index), + sample.m_outgoing.get_value(), + sample.m_incoming.get_value(), + modes, + s) * pdfs[i]; + + if (pdf > 0.0f) + { + madd(sample.m_value, s, c->get_closure_weight(i)); + sample.m_probability += pdf; + } + } } } @@ -254,29 +271,35 @@ namespace { const CompositeSurfaceClosure* c = static_cast(data); + float pdfs[CompositeSurfaceClosure::MaxClosureEntries]; + c->compute_pdfs(modes, pdfs); + float prob = 0.0f; value.set(0.0f); for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) { - Spectrum s; - const float bsdf_prob = - bsdf_from_closure_id(c->get_closure_type(i)) - .evaluate( - c->get_closure_input_values(i), - adjoint, - false, - geometric_normal, - c->get_closure_shading_basis(i), - outgoing, - incoming, - modes, - s); - - if (bsdf_prob > 0.0f) + if (pdfs[i] > 0.0f) { - madd(value, s, c->get_closure_weight(i)); - prob += bsdf_prob * c->get_closure_pdf_weight(i); + Spectrum s; + const float pdf = + bsdf_from_closure_id(c->get_closure_type(i)) + .evaluate( + c->get_closure_input_values(i), + adjoint, + false, + geometric_normal, + c->get_closure_shading_basis(i), + outgoing, + incoming, + modes, + s) * pdfs[i]; + + if (pdf > 0.0f) + { + madd(value, s, c->get_closure_weight(i)); + prob += pdf; + } } } @@ -293,22 +316,25 @@ namespace { const CompositeSurfaceClosure* c = static_cast(data); + float pdfs[CompositeSurfaceClosure::MaxClosureEntries]; + c->compute_pdfs(modes, pdfs); + float prob = 0.0f; for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) { - const float bsdf_prob = - bsdf_from_closure_id(c->get_closure_type(i)) - .evaluate_pdf( - c->get_closure_input_values(i), - geometric_normal, - c->get_closure_shading_basis(i), - outgoing, - incoming, - modes); - - if (bsdf_prob > 0.0f) - prob += bsdf_prob * c->get_closure_pdf_weight(i); + if (pdfs[i] > 0.0f) + { + prob += + bsdf_from_closure_id(c->get_closure_type(i)) + .evaluate_pdf( + c->get_closure_input_values(i), + geometric_normal, + c->get_closure_shading_basis(i), + outgoing, + incoming, + modes) * pdfs[i]; + } } return prob; @@ -330,29 +356,27 @@ namespace { const CompositeSurfaceClosure* c = static_cast(data); - absorption.set(0.0f); + absorption.set(1.0f); for (size_t i = 0, e = c->get_closure_count(); i < e; ++i) { - Spectrum a; - bsdf_from_closure_id(c->get_closure_type(i)) - .compute_absorption( - c->get_closure_input_values(i), - distance, - a); - const float w = c->get_closure_pdf_weight(i); - - // absorption += lerp(1.0f, a, w) - a *= w; - absorption += a; - a.set(1.0f - w); - absorption += a; + const ClosureID cid = c->get_closure_type(i); + if (cid > GlassID && cid <= LastGlassClosure) + { + const float w = c->get_closure_scalar_weight(i); + Spectrum a; + bsdf_from_closure_id(cid) + .compute_absorption( + c->get_closure_input_values(i), + distance * w, + a); + absorption *= a; + } } } private: BSDF* m_all_bsdfs[NumClosuresIDs]; - auto_release_ptr m_alsurface_layer_brdf; auto_release_ptr m_ashikhmin_shirley_brdf; auto_release_ptr m_blinn_brdf; auto_release_ptr m_diffuse_btdf; @@ -439,17 +463,6 @@ namespace return bsdf; } - auto_release_ptr create_and_register_alsurface_layer_bsdf() - { - auto_release_ptr bsdf = - AlSurfaceLayerBRDFFactory().create( - "alsurface_layer", - ParamArray()); - - m_all_bsdfs[AlSurfaceLayerID] = bsdf.get(); - return bsdf; - } - const BSDF& bsdf_from_closure_id(const ClosureID cid) const { const BSDF* bsdf = m_all_bsdfs[cid]; diff --git a/src/appleseed/renderer/modeling/bsdf/plasticbrdf.cpp b/src/appleseed/renderer/modeling/bsdf/plasticbrdf.cpp index d5c4241f19..a655beea88 100644 --- a/src/appleseed/renderer/modeling/bsdf/plasticbrdf.cpp +++ b/src/appleseed/renderer/modeling/bsdf/plasticbrdf.cpp @@ -289,7 +289,7 @@ namespace const float Fi = fresnel_reflectance(wi, m, values->m_precomputed.m_eta); const float specular_probability = choose_specular_probability(*values, Fo); - float pdf_glossy, pdf_diffuse; + float pdf_glossy = 0.0f, pdf_diffuse = 0.0f; value.resize(values->m_specular_reflectance.size()); value.set(0.0f); @@ -360,7 +360,7 @@ namespace const float F = fresnel_reflectance(wo, m, values->m_precomputed.m_eta); const float specular_probability = choose_specular_probability(*values, F); - float pdf_glossy, pdf_diffuse; + float pdf_glossy = 0.0f, pdf_diffuse = 0.0f; if (ScatteringMode::has_glossy(modes)) pdf_glossy = specular_pdf(*m_mdf, alpha, gamma, wo, m); diff --git a/src/appleseed/renderer/modeling/bssrdf/oslbssrdf.cpp b/src/appleseed/renderer/modeling/bssrdf/oslbssrdf.cpp index 1e7d23ec2d..99c0d030c2 100644 --- a/src/appleseed/renderer/modeling/bssrdf/oslbssrdf.cpp +++ b/src/appleseed/renderer/modeling/bssrdf/oslbssrdf.cpp @@ -167,7 +167,10 @@ namespace if (c->get_closure_count() > 0) { - const size_t closure_index = c->choose_closure(sampling_context); + sampling_context.split_in_place(1, 1); + const size_t closure_index = c->choose_closure( + sampling_context.next2()); + const Basis3f& modified_basis = c->get_closure_shading_basis(closure_index); outgoing_point.set_shading_basis(Basis3d(modified_basis)); @@ -186,7 +189,7 @@ namespace if (result) { bssrdf_sample.m_value *= c->get_closure_weight(closure_index); - bssrdf_sample.m_probability *= c->get_closure_pdf_weight(closure_index); + bssrdf_sample.m_probability *= c->get_closure_pdf(closure_index); } return result; diff --git a/src/appleseed/renderer/modeling/edf/coneedf.cpp b/src/appleseed/renderer/modeling/edf/coneedf.cpp index 6073875f75..c30225eed8 100644 --- a/src/appleseed/renderer/modeling/edf/coneedf.cpp +++ b/src/appleseed/renderer/modeling/edf/coneedf.cpp @@ -52,6 +52,7 @@ namespace renderer { class Assembly; } namespace renderer { class Project; } using namespace foundation; +using namespace std; namespace renderer { @@ -75,6 +76,7 @@ namespace { m_inputs.declare("radiance", InputFormatSpectralIlluminance); m_inputs.declare("radiance_multiplier", InputFormatFloat, "1.0"); + m_inputs.declare("exposure", InputFormatFloat, "0.0"); m_inputs.declare("angle", InputFormatFloat, "90.0"); } @@ -121,7 +123,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); probability = sample_cone_uniform_pdf(m_cos_half_angle); assert(probability > 0.0f); @@ -147,7 +149,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); } virtual void evaluate( @@ -172,7 +174,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); probability = sample_cone_uniform_pdf(m_cos_half_angle); } @@ -196,7 +198,7 @@ namespace virtual float get_uncached_max_contribution() const APPLESEED_OVERRIDE { - return get_max_contribution("radiance", "radiance_multiplier"); + return get_max_contribution("radiance", "radiance_multiplier", "exposure"); } private: @@ -250,6 +252,17 @@ DictionaryArray ConeEDFFactory::get_input_metadata() const .insert("use", "optional") .insert("default", "1.0")); + metadata.push_back( + Dictionary() + .insert("name", "exposure") + .insert("label", "Exposure") + .insert("type", "numeric") + .insert("use", "optional") + .insert("default", "0.0") + .insert("min_value", "-64.0") + .insert("max_value", "64.0") + .insert("help", "Exposure")); + metadata.push_back( Dictionary() .insert("name", "angle") diff --git a/src/appleseed/renderer/modeling/edf/coneedf.h b/src/appleseed/renderer/modeling/edf/coneedf.h index 4421d9adc6..f80c953d38 100644 --- a/src/appleseed/renderer/modeling/edf/coneedf.h +++ b/src/appleseed/renderer/modeling/edf/coneedf.h @@ -59,6 +59,7 @@ APPLESEED_DECLARE_INPUT_VALUES(ConeEDFInputValues) { Spectrum m_radiance; // emitted radiance in W.m^-2.sr^-1 float m_radiance_multiplier; // emitted radiance multiplier + float m_exposure; // emitted radiance exposure float m_angle; // cone angle }; diff --git a/src/appleseed/renderer/modeling/edf/diffuseedf.cpp b/src/appleseed/renderer/modeling/edf/diffuseedf.cpp index 40cadb364b..42a0b0fafa 100644 --- a/src/appleseed/renderer/modeling/edf/diffuseedf.cpp +++ b/src/appleseed/renderer/modeling/edf/diffuseedf.cpp @@ -44,6 +44,7 @@ // Standard headers. #include +#include // Forward declarations. namespace foundation { class IAbortSwitch; } @@ -51,6 +52,7 @@ namespace renderer { class Assembly; } namespace renderer { class Project; } using namespace foundation; +using namespace std; namespace renderer { @@ -74,6 +76,7 @@ namespace { m_inputs.declare("radiance", InputFormatSpectralIlluminance); m_inputs.declare("radiance_multiplier", InputFormatFloat, "1.0"); + m_inputs.declare("exposure", InputFormatFloat, "0.0"); } virtual void release() APPLESEED_OVERRIDE @@ -117,7 +120,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); probability = wo.y * RcpPi(); assert(probability > 0.0f); @@ -144,7 +147,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); } virtual void evaluate( @@ -170,7 +173,7 @@ namespace const InputValues* values = static_cast(data); value = values->m_radiance; - value *= values->m_radiance_multiplier; + value *= values->m_radiance_multiplier * pow(2.0f, values->m_exposure); probability = cos_on * RcpPi(); } @@ -195,7 +198,7 @@ namespace virtual float get_uncached_max_contribution() const APPLESEED_OVERRIDE { - return get_max_contribution("radiance", "radiance_multiplier"); + return get_max_contribution("radiance", "radiance_multiplier", "exposure"); } private: @@ -248,6 +251,17 @@ DictionaryArray DiffuseEDFFactory::get_input_metadata() const .insert("use", "optional") .insert("default", "1.0")); + metadata.push_back( + Dictionary() + .insert("name", "exposure") + .insert("label", "Exposure") + .insert("type", "numeric") + .insert("use", "optional") + .insert("default", "0.0") + .insert("min_value", "-64.0") + .insert("max_value", "64.0") + .insert("help", "Exposure")); + add_common_input_metadata(metadata); return metadata; diff --git a/src/appleseed/renderer/modeling/edf/diffuseedf.h b/src/appleseed/renderer/modeling/edf/diffuseedf.h index 108bbe0064..fb1ac4ea0f 100644 --- a/src/appleseed/renderer/modeling/edf/diffuseedf.h +++ b/src/appleseed/renderer/modeling/edf/diffuseedf.h @@ -59,6 +59,7 @@ APPLESEED_DECLARE_INPUT_VALUES(DiffuseEDFInputValues) { Spectrum m_radiance; // emitted radiance in W.m^-2.sr^-1 float m_radiance_multiplier; // emitted radiance multiplier + float m_exposure; // emitted radiance exposure }; diff --git a/src/appleseed/renderer/modeling/edf/edf.cpp b/src/appleseed/renderer/modeling/edf/edf.cpp index 82c5bd5dc5..47a7adbcab 100644 --- a/src/appleseed/renderer/modeling/edf/edf.cpp +++ b/src/appleseed/renderer/modeling/edf/edf.cpp @@ -41,6 +41,7 @@ #include "foundation/utility/arena.h" // Standard headers. +#include #include using namespace foundation; @@ -158,7 +159,10 @@ float EDF::get_max_contribution_spectrum(const Source* source) const return max_value(spectrum); } -float EDF::get_max_contribution(const Source* input, const Source* multiplier) const +float EDF::get_max_contribution( + const Source* input, + const Source* multiplier, + const Source* exposure) const { const float max_contribution_input = get_max_contribution_spectrum(input); @@ -170,15 +174,24 @@ float EDF::get_max_contribution(const Source* input, const Source* multiplier) c if (max_contribution_multiplier == numeric_limits::max()) return numeric_limits::max(); - return max_contribution_input * max_contribution_multiplier; + const float max_contribution_exposure = get_max_contribution_scalar(exposure); + + if (max_contribution_exposure == numeric_limits::max()) + return numeric_limits::max(); + + return max_contribution_input * max_contribution_multiplier * pow(2.0f, max_contribution_exposure); } -float EDF::get_max_contribution(const char* input_name, const char* multiplier_name) const +float EDF::get_max_contribution( + const char* input_name, + const char* multiplier_name, + const char* exposure_name) const { return get_max_contribution( m_inputs.source(input_name), - m_inputs.source(multiplier_name)); + m_inputs.source(multiplier_name), + m_inputs.source(exposure_name)); } } // namespace renderer diff --git a/src/appleseed/renderer/modeling/edf/edf.h b/src/appleseed/renderer/modeling/edf/edf.h index ee8cc19581..08a00b50bf 100644 --- a/src/appleseed/renderer/modeling/edf/edf.h +++ b/src/appleseed/renderer/modeling/edf/edf.h @@ -153,8 +153,14 @@ class APPLESEED_DLLSYMBOL EDF float get_max_contribution_scalar(const Source* source) const; float get_max_contribution_spectrum(const Source* source) const; - float get_max_contribution(const Source* source, const Source* multiplier) const; - float get_max_contribution(const char* input_name, const char* multiplier_name) const; + float get_max_contribution( + const Source* source, + const Source* multiplier, + const Source* exposure) const; + float get_max_contribution( + const char* input_name, + const char* multiplier_name, + const char* exposure_name) const; // Retrieve the approximate contribution. virtual float get_uncached_max_contribution() const = 0; diff --git a/src/appleseed/renderer/modeling/edf/osledf.cpp b/src/appleseed/renderer/modeling/edf/osledf.cpp index 65940b5ea1..95bf7eb293 100644 --- a/src/appleseed/renderer/modeling/edf/osledf.cpp +++ b/src/appleseed/renderer/modeling/edf/osledf.cpp @@ -111,7 +111,10 @@ namespace if (c->get_closure_count() > 0) { - const size_t closure_index = c->choose_closure(sampling_context); + sampling_context.split_in_place(1, 1); + const size_t closure_index = c->choose_closure( + sampling_context.next2()); + const EDF& edf = edf_from_closure_id(c->get_closure_type(closure_index)); edf.sample( sampling_context, @@ -184,7 +187,7 @@ namespace if (edf_prob > 0.0f) { value += s; - probability += edf_prob * c->get_closure_pdf_weight(i); + probability += edf_prob * c->get_closure_pdf(i); } } } @@ -211,7 +214,7 @@ namespace outgoing); if (edf_prob > 0.0f) - probability += edf_prob * c->get_closure_pdf_weight(i); + probability += edf_prob * c->get_closure_pdf(i); } return probability; diff --git a/src/cmake/Modules/FindPartio.cmake b/src/cmake/Modules/FindPartio.cmake deleted file mode 100644 index 186c6f5d17..0000000000 --- a/src/cmake/Modules/FindPartio.cmake +++ /dev/null @@ -1,64 +0,0 @@ - -# -# This source file is part of appleseed. -# Visit http://appleseedhq.net/ for additional information and resources. -# -# This software is released under the MIT license. -# -# Copyright (c) 2015-2017 Esteban Tovagliari, The appleseedhq Organization -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - - -# -# Find Partio headers and libraries. -# -# This module defines the following variables: -# -# PARTIO_FOUND True if Partio was found -# PARTIO_INCLUDE_DIRS Where to find Partio header files -# PARTIO_LIBRARIES List of Partio libraries to link against -# - -include (FindPackageHandleStandardArgs) - -find_path (PARTIO_INCLUDE_DIR NAMES Partio.h) - -find_library (PARTIO_LIBRARY NAMES partio) - -# Handle the QUIETLY and REQUIRED arguments and set PARTIO_FOUND. -find_package_handle_standard_args (PARTIO DEFAULT_MSG - PARTIO_INCLUDE_DIR - PARTIO_LIBRARY -) - -# Set the output variables. -if (PARTIO_FOUND) - set (PARTIO_INCLUDE_DIRS ${PARTIO_INCLUDE_DIR}) - set (PARTIO_LIBRARIES ${PARTIO_LIBRARY}) -else () - set (PARTIO_INCLUDE_DIRS) - set (PARTIO_LIBRARIES) -endif () - -mark_as_advanced ( - PARTIO_INCLUDE_DIR - PARTIO_LIBRARY -) diff --git a/src/cmake/config/linux-gcc.txt b/src/cmake/config/linux-gcc.txt index 0dd95a205d..d6106f723b 100644 --- a/src/cmake/config/linux-gcc.txt +++ b/src/cmake/config/linux-gcc.txt @@ -262,10 +262,6 @@ macro (link_against_seexpreditor target) target_link_libraries (${target} ${SEEXPREDITOR_LIBRARIES}) endmacro () -macro (link_against_partio target) - target_link_libraries (${target} ${PARTIO_LIBRARIES}) -endmacro () - #-------------------------------------------------------------------------------------------------- # Copy a target binary to the sandbox. diff --git a/src/cmake/config/mac-clang.txt b/src/cmake/config/mac-clang.txt index 725c580e2c..89a7b9a7ab 100644 --- a/src/cmake/config/mac-clang.txt +++ b/src/cmake/config/mac-clang.txt @@ -194,10 +194,6 @@ macro (link_against_seexpreditor target) target_link_libraries (${target} ${SEEXPREDITOR_LIBRARIES}) endmacro () -macro (link_against_partio target) - target_link_libraries (${target} ${PARTIO_LIBRARIES}) -endmacro () - #-------------------------------------------------------------------------------------------------- # Copy a target binary to the sandbox. diff --git a/src/cmake/config/win-vs.txt b/src/cmake/config/win-vs.txt index 4ec5b17be0..51f71db9dd 100644 --- a/src/cmake/config/win-vs.txt +++ b/src/cmake/config/win-vs.txt @@ -336,10 +336,6 @@ macro (link_against_seexpreditor target) endif () endmacro () -macro (link_against_partio target) - target_link_libraries (${target} ${PARTIO_LIBRARIES}) -endmacro () - #-------------------------------------------------------------------------------------------------- # Copy a target binary to the sandbox.