Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderMan coshaders #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Added support for shader parameters of type "shader" in the RenderManShader node - these are mapped to plugs which accept connections to other RenderManShaders, allowing the creation of networks of coshaders.

0.54.0
======

* Added base classes Executable and Despatcher and two derived Node classes: ExecutableNode and ExecutableOpHolder.

* Added an enabled/disabled plug to all SceneNodes. Nodes with no inputs output an empty scene when disabled, and SceneProcessors output the first input unchanged. The enabled/disabled state can be toggled using the node right click menu or the "d" hotkey in the Graph Editor.
Expand Down
4 changes: 3 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,9 @@ libraries = {

"GafferRenderManUI" : {},

"GafferRenderManTest" : {},
"GafferRenderManTest" : {
"additionalFiles" : glob.glob( "python/GafferRenderManTest/*/*" ),
},

"apps" : {
"additionalFiles" : glob.glob( "apps/*/*-1.py" ),
Expand Down
2 changes: 2 additions & 0 deletions include/GafferRenderMan/RenderManShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class RenderManShader : public GafferScene::Shader

protected :

virtual bool acceptsInput( const Gaffer::Plug *plug, const Gaffer::Plug *inputPlug ) const;

virtual void shaderHash( IECore::MurmurHash &h ) const;
virtual IECore::ShaderPtr shader( NetworkBuilder &network ) const;

Expand Down
14 changes: 0 additions & 14 deletions python/GafferArnoldUI/ArnoldShaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@
import GafferUI
import GafferArnold

## \todo This will belong with a Shader base class node at some point, probably in
# GafferScene.
def __nodeGadgetCreator( node ) :

return GafferUI.StandardNodeGadget( node, GafferUI.LinearContainer.Orientation.Y )

GafferUI.NodeGadget.registerNodeGadget( GafferArnold.ArnoldShader.staticTypeId(), __nodeGadgetCreator )

def __parametersNoduleCreator( plug ) :

return GafferUI.CompoundNodule( plug, GafferUI.LinearContainer.Orientation.Y )

GafferUI.Nodule.registerNodule( GafferArnold.ArnoldShader.staticTypeId(), "parameters", __parametersNoduleCreator )

def __parameterNoduleCreator( plug ) :

if isinstance( plug, ( Gaffer.BoolPlug, Gaffer.IntPlug, Gaffer.StringPlug ) ) :
Expand Down
49 changes: 48 additions & 1 deletion python/GafferRenderManTest/RenderManShaderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
#
##########################################################################

import os
import unittest

import IECore

import Gaffer
import GafferRenderMan
import GafferRenderManTest

class RenderManShaderTest( unittest.TestCase ) :
class RenderManShaderTest( GafferRenderManTest.RenderManTestCase ) :

def test( self ) :

Expand Down Expand Up @@ -127,6 +129,51 @@ def testParameterOrdering( self ) :

self.assertEqual( n["parameters"][0].getName(), "Ka" )
self.assertEqual( n["parameters"][1].getName(), "Kd" )

def testCoshader( self ) :

shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshaderParameter.sl" )

shaderNode = GafferRenderMan.RenderManShader()
shaderNode.loadShader( shader )

self.assertTrue( "coshaderParameter" in shaderNode["parameters"] )
self.assertEqual( shaderNode["parameters"]["coshaderParameter"].typeId(), Gaffer.Plug.staticTypeId() )

coshader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshader.sl" )

coshaderNode = GafferRenderMan.RenderManShader()
coshaderNode.loadShader( coshader )

shaderNode["parameters"]["coshaderParameter"].setInput( coshaderNode["out"] )

s = shaderNode.state()
self.assertEqual( len( s ), 2 )

self.assertEqual( s[0].name, coshader )
self.assertEqual( s[1].name, shader )
self.assertEqual( s[0].parameters["__handle"], s[1].parameters["coshaderParameter"] )

def testInputAcceptance( self ) :

shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshaderParameter.sl" )
shaderNode = GafferRenderMan.RenderManShader()
shaderNode.loadShader( shader )

coshader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshader.sl" )
coshaderNode = GafferRenderMan.RenderManShader()
coshaderNode.loadShader( coshader )

random = Gaffer.Random()

self.assertTrue( shaderNode["parameters"]["coshaderParameter"].acceptsInput( coshaderNode["out"] ) )
self.assertFalse( shaderNode["parameters"]["coshaderParameter"].acceptsInput( random["outFloat"] ) )

self.assertTrue( shaderNode["parameters"]["floatParameter"].acceptsInput( random["outFloat"] ) )
self.assertFalse( shaderNode["parameters"]["floatParameter"].acceptsInput( coshaderNode["out"] ) )

self.assertTrue( coshaderNode["parameters"]["colorParameter"].acceptsInput( random["outColor"] ) )
self.assertFalse( coshaderNode["parameters"]["colorParameter"].acceptsInput( coshaderNode["out"] ) )

if __name__ == "__main__":
unittest.main()
66 changes: 66 additions & 0 deletions python/GafferRenderManTest/RenderManTestCase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
##########################################################################
#
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import os

import GafferSceneTest

class RenderManTestCase( GafferSceneTest.SceneTestCase ) :

def setUp( self ) :

self.__compiledShaders = set()

def compileShader( self, sourceFileName ) :

# perhaps one day we'll need to implement this for other renderman
# renderers, in which case we'll be glad we put all the calls in one
# place.

shaderName = os.path.splitext( os.path.basename( sourceFileName ) )[0]
outputFileName = "/tmp/" + shaderName + ".sdl"

os.system( "shaderdl -o %s %s" % ( outputFileName, sourceFileName ) )

self.__compiledShaders.add( outputFileName )

return os.path.splitext( outputFileName )[0]

def tearDown( self ) :

for f in self.__compiledShaders :
if os.path.exists( f ) :
os.remove( f )
1 change: 1 addition & 0 deletions python/GafferRenderManTest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#
##########################################################################

from RenderManTestCase import RenderManTestCase
from RenderManShaderTest import RenderManShaderTest
from RenderManAttributesTest import RenderManAttributesTest
from RenderManOptionsTest import RenderManOptionsTest
Expand Down
50 changes: 50 additions & 0 deletions python/GafferRenderManTest/shaders/coshader.sl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

class coshader(

float floatParameter = 10;
color colorParameter = ( 1, 1, 1 );

)
{

public color aMethodYouWillPayDearlyToCall()
{
return floatParameter * colorParameter;
}

}
45 changes: 45 additions & 0 deletions python/GafferRenderManTest/shaders/coshaderParameter.sl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

surface coshaderParameter(
float floatParameter = 1;
string stringParameter = "";
shader coshaderParameter = null;
)
{
Ci = 1;
Oi = 1;
}
57 changes: 57 additions & 0 deletions python/GafferRenderManUI/RenderManShaderUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
##########################################################################
#
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import fnmatch

import Gaffer
import GafferUI

import GafferRenderMan

##########################################################################
# Nodules
##########################################################################

def __parameterNoduleCreator( plug ) :

# only coshader parameters should be connectable in the node
# graph.
if plug.typeId() == Gaffer.Plug.staticTypeId() :
return GafferUI.StandardNodule( plug )

return None

GafferUI.Nodule.registerNodule( GafferRenderMan.RenderManShader.staticTypeId(), fnmatch.translate( "parameters.*" ), __parameterNoduleCreator )
1 change: 1 addition & 0 deletions python/GafferRenderManUI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
import RenderManRenderUI
import RenderManAttributesUI
import RenderManOptionsUI
import RenderManShaderUI
import Menus
2 changes: 0 additions & 2 deletions python/GafferSceneUI/OpenGLShaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
# Nodules
##########################################################################

GafferUI.Nodule.registerNodule( GafferScene.OpenGLShader.staticTypeId(), "parameters", GafferUI.CompoundNodule )

def __parameterNoduleCreator( plug ) :

if isinstance( plug, ( GafferImage.ImagePlug ) ) :
Expand Down
5 changes: 0 additions & 5 deletions python/GafferSceneUI/SceneNodeUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ def __noduleCreator( plug ) :
),
)

# Shader

GafferUI.PlugValueWidget.registerCreator( GafferScene.Shader.staticTypeId(), "parameters", GafferUI.CompoundPlugValueWidget, collapsed=None )
GafferUI.PlugValueWidget.registerCreator( GafferScene.Shader.staticTypeId(), "out", None )

# SceneElementProcessor

GafferUI.Nodule.registerNodule( GafferScene.SceneElementProcessor.staticTypeId(), "filter", GafferUI.StandardNodule )
Expand Down
Loading