├── LICENSE ├── README.asciidoc ├── include └── ptMaterial.h ├── makefile └── material ├── ptDiffuse.osl ├── ptIncandesence.osl ├── ptSpecular.osl ├── ptSurface.osl └── ptVarnishAbsorption.osl /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Image Engine Design Inc. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above 8 | copyright notice, this list of conditions and the following 9 | disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided with 14 | the distribution. 15 | 16 | * Neither the name of Image Engine nor the names of 17 | any other contributors to this software may be used to endorse or 18 | promote products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | -------------------------------------------------------------------------------- /README.asciidoc: -------------------------------------------------------------------------------- 1 | == Patina == 2 | 3 | Some initial experiments in OSL shading. 4 | 5 | === Copyright and License === 6 | © 2015, Image Engine Design Inc. under https://github.com/ImageEngine/patina/blob/master/LICENSE[the BSD license] 7 | -------------------------------------------------------------------------------- /include/ptMaterial.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | struct ptMATERIAL 38 | { 39 | closure color brdf; 40 | color remainingEnergy; 41 | }; 42 | 43 | #define ptMATERIAL_INIT {0,1} 44 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | ########################################################################## 2 | # 3 | # Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are 7 | # met: 8 | # 9 | # * Redistributions of source code must retain the above 10 | # copyright notice, this list of conditions and the following 11 | # disclaimer. 12 | # 13 | # * Redistributions in binary form must reproduce the above 14 | # copyright notice, this list of conditions and the following 15 | # disclaimer in the documentation and/or other materials provided with 16 | # the distribution. 17 | # 18 | # * Neither the name of Image Engine nor the names of 19 | # any other contributors to this software may be used to endorse or 20 | # promote products derived from this software without specific prior 21 | # written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | # 35 | ########################################################################## 36 | 37 | 38 | SOURCES = $(wildcard */*.osl) 39 | INCLUDES = -I./include 40 | 41 | OUTPUTS = $(SOURCES:.osl=.oso) 42 | 43 | %.oso: %.osl 44 | #LD_LIBRARY_PATH=/home/daniel/Downloads/gaffer-0.14.0.0-linux/lib /home/daniel/Downloads/gaffer-0.14.0.0-linux/bin/oslc $(INCLUDES) -o $@ $< 45 | LD_LIBRARY_PATH=$(GAFFER_ROOT)/lib $(GAFFER_ROOT)/bin/oslc $(INCLUDES) -o $@ $< 46 | 47 | all: $(OUTPUTS) 48 | @echo All done 49 | 50 | clean: 51 | rm */*.oso 52 | -------------------------------------------------------------------------------- /material/ptDiffuse.osl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "ptMaterial.h" 38 | 39 | shader ptDiffuse 40 | [[ 41 | string help = "Diffuse surface shader" 42 | ]] 43 | ( 44 | ptMATERIAL in = ptMATERIAL_INIT, 45 | normal dispN = N, 46 | color tint = 0.8 47 | [[ 48 | string help = "Color" 49 | ]], 50 | float roughness = 0.0 51 | [[ 52 | string help = "Surface roughness." 53 | ]], 54 | float weight = 1.0, 55 | int conserve = 1 56 | [[ 57 | string widget = "checkBox" 58 | ]], 59 | 60 | output ptMATERIAL out = ptMATERIAL_INIT 61 | ) 62 | { 63 | out = in; 64 | 65 | float currentWeight = clamp( weight, 0, 1 ); 66 | if( roughness != 0.0 ) 67 | out.brdf += in.remainingEnergy * currentWeight * tint * oren_nayar(dispN, roughness); 68 | else 69 | out.brdf += in.remainingEnergy * currentWeight * tint * diffuse(dispN); 70 | 71 | if( conserve ) 72 | out.remainingEnergy *= 1 - currentWeight; 73 | } 74 | -------------------------------------------------------------------------------- /material/ptIncandesence.osl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "ptMaterial.h" 38 | 39 | shader ptIncandescence 40 | [[ 41 | string help = "Incandescence surface shader" 42 | ]] 43 | ( 44 | ptMATERIAL in = ptMATERIAL_INIT, 45 | color emit = 1, 46 | float weight = 1.0, 47 | int conserve = 1 48 | [[ 49 | string widget = "checkBox" 50 | ]], 51 | 52 | output ptMATERIAL out = ptMATERIAL_INIT 53 | ) 54 | { 55 | out = in; 56 | 57 | float currentWeight = clamp( weight, 0, 1 ); 58 | out.brdf += in.remainingEnergy * currentWeight * emit * emission(); 59 | 60 | if( conserve ) 61 | out.remainingEnergy *= 1 - currentWeight; 62 | } 63 | -------------------------------------------------------------------------------- /material/ptSpecular.osl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "ptMaterial.h" 38 | 39 | shader ptSpecular 40 | [[ 41 | string help = "Specular surface shader" 42 | ]] 43 | ( 44 | ptMATERIAL in = ptMATERIAL_INIT, 45 | 46 | normal dispN = N, 47 | color tint = 0.8 48 | [[ 49 | string help = "Color" 50 | ]], 51 | float roughness = 0.0 52 | [[ 53 | string help = "Surface roughness." 54 | ]], 55 | float weight = 1.0, 56 | float fresnelFacingWeight = 0.04, //TODO 57 | int conserve = 1 58 | [[ 59 | string widget = "checkBox" 60 | ]], 61 | 62 | output ptMATERIAL out = ptMATERIAL_INIT 63 | ) 64 | { 65 | out = in; 66 | float currentWeight = clamp( weight, 0, 1 ) * mix( clamp( fresnelFacingWeight, 0, 1 ), 1, pow(1 - dot( -I, N ), 5 ) ); 67 | out.brdf += in.remainingEnergy * currentWeight * tint * microfacet("ggx", dispN, roughness, 1.3, 0); 68 | 69 | if( conserve ) 70 | out.remainingEnergy *= 1 - currentWeight; 71 | } 72 | -------------------------------------------------------------------------------- /material/ptSurface.osl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "ptMaterial.h" 38 | 39 | surface ptSurface 40 | [[ 41 | string help = "Blah" 42 | ]] 43 | ( 44 | ptMATERIAL in = ptMATERIAL_INIT 45 | ) 46 | { 47 | Ci = in.brdf; 48 | } 49 | -------------------------------------------------------------------------------- /material/ptVarnishAbsorption.osl: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) 2015, Image Engine Design Inc. All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above 10 | // copyright notice, this list of conditions and the following 11 | // disclaimer. 12 | // 13 | // * Redistributions in binary form must reproduce the above 14 | // copyright notice, this list of conditions and the following 15 | // disclaimer in the documentation and/or other materials provided with 16 | // the distribution. 17 | // 18 | // * Neither the name of Image Engine nor the names of 19 | // any other contributors to this software may be used to endorse or 20 | // promote products derived from this software without specific prior 21 | // written permission. 22 | // 23 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | // 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | #include "ptMaterial.h" 38 | 39 | shader ptVarnishAbsorption 40 | [[ 41 | string help = "Imitate the absorption of a colored varnish layer, which gets more saturated at grazing angles." 42 | ]] 43 | ( 44 | ptMATERIAL in = ptMATERIAL_INIT, 45 | 46 | normal dispN = N, 47 | color absorptionColor = 1.0, 48 | float thickness = 1.0, 49 | 50 | output ptMATERIAL out = ptMATERIAL_INIT 51 | ) 52 | { 53 | out = in; 54 | out.remainingEnergy *= pow( absorptionColor, thickness / max( 0.000001, abs( dot( -I, N ) ) ) ); 55 | } 56 | --------------------------------------------------------------------------------