Package slum :: Module shaderClasses
[hide private]
[frames] | no frames]

Source Code for Module slum.shaderClasses

1 # 2 # shaderClasses.py - shader base classes for slumTemplates 3 # 4 # Copyright (C) 2008-2009 - Roberto Hradec 5 # 6 # --------------------------------------------------------------------------- 7 # This file is part of SLUM. 8 # 9 # SLUM is free software: you can redistribute it and/or modify 10 # it under the terms of the GNU General Public License as published by 11 # the Free Software Foundation, either version 3 of the License, or 12 # (at your option) any later version. 13 # 14 # SLUM is distributed in the hope that it will be useful, 15 # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 # GNU General Public License for more details. 18 # 19 # You should have received a copy of the GNU General Public License 20 # along with SLUM. If not, see <http://www.gnu.org/licenses/>. 21 # --------------------------------------------------------------------------- 22 23 24 25 -class slum:
26 '''This is the base shader class. (not used directly to develop shaders) 27 This class have all the support methods that that a template needs. 28 Also have all the client support methods. 29 30 renderer code is define as a method, as in the following example: 31 32 def delight(self, parameters): 33 return ('','') 34 35 The method must have the name of one of the renderers defined in 36 the _renderers method. 37 38 The method will be called by the clients, which will pass 39 the "parameters" attribute to it. 40 41 The parameters attribute is a dictionary that contains all the 42 parameters returned by the parameters method, but already evaluated 43 by the client. This way the method can evaluate the parameters input 44 from the user to build up the shader parameters and code. 45 46 The method should return a tupple, where [0] is the shader 47 parameters and [1] is the shader code. 48 ''' 49 50 @staticmethod
51 - def ID(self):
52 ''' slum shader template ID. This method MUST be overriden when developing a shader template. Every shader must have an unique ID. ''' 53 return None
54 - def parameters(self):
55 ''' return parameters to be exposed in the client. This method MUST be overriden when developing a shader template. ''' 56 pass
57 - def icon(self):
58 ''' return string with MPX icon. This can be overriden in the template to define a custom icon. ''' 59 return ''
60 - def type():
61 ''' slum shader type. This method is overriden by other classes to define the slum class type ''' 62 return None
63 - def __init__(self):
64 ''' placeholder. No use for this method yet ''' 65 pass
66 - def clientRefresh(self):
67 ''' placeholder. Clients will override this at runtime to allow template to refresh client UI ''' 68 pass
69 - def upload(self):
70 ''' upload template to online repository. It will be called by the client when the user wants to submit a template to the online repository.''' 71 pass
72 73 74 # support methods - theses methods are basically to support clients. 75 # they are not suposed to be replaced in a .slum file (not virtual)
76 - def _renderers(self):
77 ''' Returns supported renderers. This is used by clients so they can add support on UI for then. 78 Basically, the names here reflect the same names of the methods for each renderer. 79 so, if you add a new renderer, you must make sure to add the method with the same name for it. 80 also, the support for this new renderer need to be added in the clients.''' 81 return [ 82 'delight', 83 'renderman', 84 'air', 85 'cgfx', 86 'glsl', 87 ]
88 - def _dictParameters(self, value=False):
89 def recursivePopulateDict( parameter ): 90 temp = {} 91 if parameter.__class__.__name__ == 'group': 92 for each in parameter.value: 93 temp.update( recursivePopulateDict( each ) ) 94 elif parameter.__class__.__name__ == 'parameter': 95 if value: 96 temp[parameter.name] = parameter.value 97 else: 98 temp[parameter.name] = parameter 99 return temp
100 101 return recursivePopulateDict( self.parameters() )
102
103 104 105 -class slumSurface(slum):
106 ''' this class is used in a slum template when defining surface shaders. 107 this class is basically a normal slum class, with the override of the type method. 108 This classes are being defined here to make a slum template easier to read, with just the 109 methods that are really needed on it.''' 110 @staticmethod
111 - def type():
112 return 'surface'
113
114 -class slumVolume(slum):
115 ''' this class is used in a slum template when defining volume shaders ''' 116 @staticmethod
117 - def type():
118 return 'volume'
119
120 -class slumDisplacement(slum):
121 ''' this class is used in a slum template when defining displacement shaders ''' 122 @staticmethod
123 - def type():
124 return 'displacement'
125
126 -class slumLight(slum):
127 ''' this class is used in a slum template when defining light shaders ''' 128 @staticmethod
129 - def type():
130 return 'light'
131
132 -class slumColor(slum):
133 ''' this class is used in a slum template when defining color utility shaders ''' 134 @staticmethod
135 - def type():
136 return 'color'
137
138 -class slumFloat(slum):
139 ''' this class is used in a slum template when defining float utility shaders ''' 140 @staticmethod
141 - def type():
142 return 'float'
143