Cycles Volume Render: support for rendering of homogeneous volume with absorption.
[blender.git] / release / scripts / startup / nodeitems_builtins.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 import nodeitems_utils
22 from nodeitems_utils import NodeCategory, NodeItem, NodeItemCustom
23
24
25 # Subclasses for standard node types
26
27 class CompositorNodeCategory(NodeCategory):
28     @classmethod
29     def poll(cls, context):
30         return (context.space_data.tree_type == 'CompositorNodeTree')
31
32
33 class ShaderNewNodeCategory(NodeCategory):
34     @classmethod
35     def poll(cls, context):
36         return (context.space_data.tree_type == 'ShaderNodeTree' and
37                 context.scene.render.use_shading_nodes)
38
39
40 class ShaderOldNodeCategory(NodeCategory):
41     @classmethod
42     def poll(cls, context):
43         return (context.space_data.tree_type == 'ShaderNodeTree' and
44                 not context.scene.render.use_shading_nodes)
45
46
47 class TextureNodeCategory(NodeCategory):
48     @classmethod
49     def poll(cls, context):
50         return context.space_data.tree_type == 'TextureNodeTree'
51
52
53 # menu entry for making a new group from selected nodes
54 def group_make_draw(self, layout, context):
55     layout.operator("node.group_make")
56     layout.separator()
57
58 # maps node tree type to group node type
59 node_tree_group_type = {
60     'CompositorNodeTree': 'CompositorNodeGroup',
61     'ShaderNodeTree': 'ShaderNodeGroup',
62     'TextureNodeTree': 'TextureNodeGroup',
63     }
64
65
66 # generic node group items generator for shader, compositor and texture node groups
67 def node_group_items(context):
68     space = context.space_data
69     if not space:
70         return
71     ntree = space.edit_tree
72     if not ntree:
73         return
74
75     yield NodeItemCustom(draw=group_make_draw)
76
77     def contains_group(nodetree, group):
78         if nodetree == group:
79             return True
80         else:
81             for node in nodetree.nodes:
82                 if node.bl_idname in node_tree_group_type.values() and node.node_tree is not None:
83                     if contains_group(node.node_tree, group):
84                         return True
85         return False
86
87     for group in context.blend_data.node_groups:
88         if group.bl_idname != ntree.bl_idname:
89             continue
90         # filter out recursive groups
91         if contains_group(group, ntree):
92             continue
93
94         yield NodeItem(node_tree_group_type[group.bl_idname],
95                        group.name,
96                        {"node_tree": "bpy.data.node_groups[%r]" % group.name})
97
98
99 # only show input/output nodes inside node groups
100 def group_input_output_item_poll(context):
101     space = context.space_data
102     if space.edit_tree in bpy.data.node_groups.values():
103         return True
104     return False
105
106
107 # All standard node categories currently used in nodes.
108
109 shader_node_categories = [
110     # Shader Nodes
111     ShaderOldNodeCategory("SH_INPUT", "Input", items=[
112         NodeItem("ShaderNodeMaterial"),
113         NodeItem("ShaderNodeCameraData"),
114         NodeItem("ShaderNodeLampData"),
115         NodeItem("ShaderNodeValue"),
116         NodeItem("ShaderNodeRGB"),
117         NodeItem("ShaderNodeTexture"),
118         NodeItem("ShaderNodeGeometry"),
119         NodeItem("ShaderNodeExtendedMaterial"),
120         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
121         ]),
122     ShaderOldNodeCategory("SH_OUTPUT", "Output", items=[
123         NodeItem("ShaderNodeOutput"),
124         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
125         ]),
126     ShaderOldNodeCategory("SH_OP_COLOR", "Color", items=[
127         NodeItem("ShaderNodeMixRGB"),
128         NodeItem("ShaderNodeRGBCurve"),
129         NodeItem("ShaderNodeInvert"),
130         NodeItem("ShaderNodeHueSaturation"),
131         ]),
132     ShaderOldNodeCategory("SH_OP_VECTOR", "Vector", items=[
133         NodeItem("ShaderNodeNormal"),
134         NodeItem("ShaderNodeMapping"),
135         NodeItem("ShaderNodeVectorCurve"),
136         ]),
137     ShaderOldNodeCategory("SH_CONVERTOR", "Converter", items=[
138         NodeItem("ShaderNodeValToRGB"),
139         NodeItem("ShaderNodeRGBToBW"),
140         NodeItem("ShaderNodeMath"),
141         NodeItem("ShaderNodeVectorMath"),
142         NodeItem("ShaderNodeSqueeze"),
143         NodeItem("ShaderNodeSeparateRGB"),
144         NodeItem("ShaderNodeCombineRGB"),
145         NodeItem("ShaderNodeSeparateHSV"),
146         NodeItem("ShaderNodeCombineHSV"),
147         ]),
148     ShaderOldNodeCategory("SH_GROUP", "Group", items=node_group_items),
149     ShaderOldNodeCategory("SH_LAYOUT", "Layout", items=[
150         NodeItem("NodeFrame"),
151         NodeItem("NodeReroute"),
152         ]),
153
154     # New Shader Nodes (Cycles)
155     ShaderNewNodeCategory("SH_NEW_INPUT", "Input", items=[
156         NodeItem("ShaderNodeTexCoord"),
157         NodeItem("ShaderNodeAttribute"),
158         NodeItem("ShaderNodeLightPath"),
159         NodeItem("ShaderNodeFresnel"),
160         NodeItem("ShaderNodeLayerWeight"),
161         NodeItem("ShaderNodeRGB"),
162         NodeItem("ShaderNodeValue"),
163         NodeItem("ShaderNodeTangent"),
164         NodeItem("ShaderNodeNewGeometry"),
165         NodeItem("ShaderNodeWireframe"),
166         NodeItem("ShaderNodeObjectInfo"),
167         NodeItem("ShaderNodeHairInfo"),
168         NodeItem("ShaderNodeParticleInfo"),
169         NodeItem("ShaderNodeCameraData"),
170         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
171         ]),
172     ShaderNewNodeCategory("SH_NEW_OUTPUT", "Output", items=[
173         NodeItem("ShaderNodeOutputMaterial"),
174         NodeItem("ShaderNodeOutputLamp"),
175         NodeItem("ShaderNodeOutputWorld"),
176         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
177         ]),
178     ShaderNewNodeCategory("SH_NEW_SHADER", "Shader", items=[
179         NodeItem("ShaderNodeMixShader"),
180         NodeItem("ShaderNodeAddShader"),
181         NodeItem("ShaderNodeBsdfDiffuse"),
182         NodeItem("ShaderNodeBsdfGlossy"),
183         NodeItem("ShaderNodeBsdfTransparent"),
184         NodeItem("ShaderNodeBsdfRefraction"),
185         NodeItem("ShaderNodeBsdfGlass"),
186         NodeItem("ShaderNodeBsdfTranslucent"),
187         NodeItem("ShaderNodeBsdfAnisotropic"),
188         NodeItem("ShaderNodeBsdfVelvet"),
189         NodeItem("ShaderNodeBsdfToon"),
190         NodeItem("ShaderNodeSubsurfaceScattering"),
191         NodeItem("ShaderNodeEmission"),
192         NodeItem("ShaderNodeBsdfHair"),
193         NodeItem("ShaderNodeBackground"),
194         NodeItem("ShaderNodeAmbientOcclusion"),
195         NodeItem("ShaderNodeHoldout"),
196         NodeItem("ShaderNodeVolumeAbsorption"),
197         ]),
198     ShaderNewNodeCategory("SH_NEW_TEXTURE", "Texture", items=[
199         NodeItem("ShaderNodeTexImage"),
200         NodeItem("ShaderNodeTexEnvironment"),
201         NodeItem("ShaderNodeTexSky"),
202         NodeItem("ShaderNodeTexNoise"),
203         NodeItem("ShaderNodeTexWave"),
204         NodeItem("ShaderNodeTexVoronoi"),
205         NodeItem("ShaderNodeTexMusgrave"),
206         NodeItem("ShaderNodeTexGradient"),
207         NodeItem("ShaderNodeTexMagic"),
208         NodeItem("ShaderNodeTexChecker"),
209         NodeItem("ShaderNodeTexBrick"),
210         ]),
211     ShaderNewNodeCategory("SH_NEW_OP_COLOR", "Color", items=[
212         NodeItem("ShaderNodeMixRGB"),
213         NodeItem("ShaderNodeRGBCurve"),
214         NodeItem("ShaderNodeInvert"),
215         NodeItem("ShaderNodeLightFalloff"),
216         NodeItem("ShaderNodeHueSaturation"),
217         NodeItem("ShaderNodeGamma"),
218         NodeItem("ShaderNodeBrightContrast"),
219         ]),
220     ShaderNewNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[
221         NodeItem("ShaderNodeMapping"),
222         NodeItem("ShaderNodeBump"),
223         NodeItem("ShaderNodeNormalMap"),
224         NodeItem("ShaderNodeNormal"),
225         NodeItem("ShaderNodeVectorCurve"),
226         NodeItem("ShaderNodeVectorTransform"),
227         ]),
228     ShaderNewNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
229         NodeItem("ShaderNodeMath"),
230         NodeItem("ShaderNodeValToRGB"),
231         NodeItem("ShaderNodeRGBToBW"),
232         NodeItem("ShaderNodeVectorMath"),
233         NodeItem("ShaderNodeSeparateRGB"),
234         NodeItem("ShaderNodeCombineRGB"),
235         NodeItem("ShaderNodeSeparateHSV"),
236         NodeItem("ShaderNodeCombineHSV"),
237         NodeItem("ShaderNodeWavelength"),
238         NodeItem("ShaderNodeBlackbody"),
239         ]),
240     ShaderNewNodeCategory("SH_NEW_SCRIPT", "Script", items=[
241         NodeItem("ShaderNodeScript"),
242         ]),
243     ShaderNewNodeCategory("SH_NEW_GROUP", "Group", items=node_group_items),
244     ShaderNewNodeCategory("SH_NEW_LAYOUT", "Layout", items=[
245         NodeItem("NodeFrame"),
246         NodeItem("NodeReroute"),
247         ]),
248     ]
249
250 compositor_node_categories = [
251     # Compositor Nodes
252     CompositorNodeCategory("CMP_INPUT", "Input", items=[
253         NodeItem("CompositorNodeRLayers"),
254         NodeItem("CompositorNodeImage"),
255         NodeItem("CompositorNodeMovieClip"),
256         NodeItem("CompositorNodeMask"),
257         NodeItem("CompositorNodeRGB"),
258         NodeItem("CompositorNodeValue"),
259         NodeItem("CompositorNodeTexture"),
260         NodeItem("CompositorNodeBokehImage"),
261         NodeItem("CompositorNodeTime"),
262         NodeItem("CompositorNodeTrackPos"),
263         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
264         ]),
265     CompositorNodeCategory("CMP_OUTPUT", "Output", items=[
266         NodeItem("CompositorNodeComposite"),
267         NodeItem("CompositorNodeViewer"),
268         NodeItem("CompositorNodeSplitViewer"),
269         NodeItem("CompositorNodeOutputFile"),
270         NodeItem("CompositorNodeLevels"),
271         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
272         ]),
273     CompositorNodeCategory("CMP_OP_COLOR", "Color", items=[
274         NodeItem("CompositorNodeMixRGB"),
275         NodeItem("CompositorNodeAlphaOver"),
276         NodeItem("CompositorNodeInvert"),
277         NodeItem("CompositorNodeCurveRGB"),
278         NodeItem("CompositorNodeHueSat"),
279         NodeItem("CompositorNodeColorBalance"),
280         NodeItem("CompositorNodeHueCorrect"),
281         NodeItem("CompositorNodeBrightContrast"),
282         NodeItem("CompositorNodeGamma"),
283         NodeItem("CompositorNodeColorCorrection"),
284         NodeItem("CompositorNodeTonemap"),
285         NodeItem("CompositorNodeZcombine"),
286         ]),
287     CompositorNodeCategory("CMP_CONVERTOR", "Converter", items=[
288         NodeItem("CompositorNodeMath"),
289         NodeItem("CompositorNodeValToRGB"),
290         NodeItem("CompositorNodeSetAlpha"),
291         NodeItem("CompositorNodePremulKey"),
292         NodeItem("CompositorNodeIDMask"),
293         NodeItem("CompositorNodeRGBToBW"),
294         NodeItem("CompositorNodeSepRGBA"),
295         NodeItem("CompositorNodeCombRGBA"),
296         NodeItem("CompositorNodeSepHSVA"),
297         NodeItem("CompositorNodeCombHSVA"),
298         NodeItem("CompositorNodeSepYUVA"),
299         NodeItem("CompositorNodeCombYUVA"),
300         NodeItem("CompositorNodeSepYCCA"),
301         NodeItem("CompositorNodeCombYCCA"),
302         ]),
303     CompositorNodeCategory("CMP_OP_FILTER", "Filter", items=[
304         NodeItem("CompositorNodeBlur"),
305         NodeItem("CompositorNodeBilateralblur"),
306         NodeItem("CompositorNodeDilateErode"),
307         NodeItem("CompositorNodeDespeckle"),
308         NodeItem("CompositorNodeFilter"),
309         NodeItem("CompositorNodeBokehBlur"),
310         NodeItem("CompositorNodeVecBlur"),
311         NodeItem("CompositorNodeDefocus"),
312         NodeItem("CompositorNodeGlare"),
313         NodeItem("CompositorNodeInpaint"),
314         NodeItem("CompositorNodeDBlur"),
315         NodeItem("CompositorNodePixelate"),
316         ]),
317     CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
318         NodeItem("CompositorNodeNormal"),
319         NodeItem("CompositorNodeMapValue"),
320         NodeItem("CompositorNodeMapRange"),
321         NodeItem("CompositorNodeNormalize"),
322         NodeItem("CompositorNodeCurveVec"),
323         ]),
324     CompositorNodeCategory("CMP_MATTE", "Matte", items=[
325         NodeItem("CompositorNodeKeying"),
326         NodeItem("CompositorNodeKeyingScreen"),
327         NodeItem("CompositorNodeChannelMatte"),
328         NodeItem("CompositorNodeColorSpill"),
329         NodeItem("CompositorNodeBoxMask"),
330         NodeItem("CompositorNodeEllipseMask"),
331         NodeItem("CompositorNodeLumaMatte"),
332         NodeItem("CompositorNodeDiffMatte"),
333         NodeItem("CompositorNodeDistanceMatte"),
334         NodeItem("CompositorNodeChromaMatte"),
335         NodeItem("CompositorNodeColorMatte"),
336         NodeItem("CompositorNodeDoubleEdgeMask"),
337         ]),
338     CompositorNodeCategory("CMP_DISTORT", "Distort", items=[
339         NodeItem("CompositorNodeScale"),
340         NodeItem("CompositorNodeLensdist"),
341         NodeItem("CompositorNodeMovieDistortion"),
342         NodeItem("CompositorNodeTranslate"),
343         NodeItem("CompositorNodeRotate"),
344         NodeItem("CompositorNodeFlip"),
345         NodeItem("CompositorNodeCrop"),
346         NodeItem("CompositorNodeDisplace"),
347         NodeItem("CompositorNodeMapUV"),
348         NodeItem("CompositorNodeTransform"),
349         NodeItem("CompositorNodeStabilize"),
350         NodeItem("CompositorNodePlaneTrackDeform"),
351         ]),
352     CompositorNodeCategory("CMP_GROUP", "Group", items=node_group_items),
353     CompositorNodeCategory("CMP_LAYOUT", "Layout", items=[
354         NodeItem("NodeFrame"),
355         NodeItem("NodeReroute"),
356         NodeItem("CompositorNodeSwitch"),
357         ]),
358     ]
359
360 texture_node_categories = [
361     # Texture Nodes
362     TextureNodeCategory("TEX_INPUT", "Input", items=[
363         NodeItem("TextureNodeCurveTime"),
364         NodeItem("TextureNodeCoordinates"),
365         NodeItem("TextureNodeTexture"),
366         NodeItem("TextureNodeImage"),
367         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
368         ]),
369     TextureNodeCategory("TEX_OUTPUT", "Output", items=[
370         NodeItem("TextureNodeOutput"),
371         NodeItem("TextureNodeViewer"),
372         NodeItem("NodeGroupOutput", poll=group_input_output_item_poll),
373         ]),
374     TextureNodeCategory("TEX_OP_COLOR", "Color", items=[
375         NodeItem("TextureNodeMixRGB"),
376         NodeItem("TextureNodeCurveRGB"),
377         NodeItem("TextureNodeInvert"),
378         NodeItem("TextureNodeHueSaturation"),
379         NodeItem("TextureNodeCompose"),
380         NodeItem("TextureNodeDecompose"),
381         ]),
382     TextureNodeCategory("TEX_PATTERN", "Pattern", items=[
383         NodeItem("TextureNodeChecker"),
384         NodeItem("TextureNodeBricks"),
385         ]),
386     TextureNodeCategory("TEX_TEXTURE", "Textures", items=[
387         NodeItem("TextureNodeTexNoise"),
388         NodeItem("TextureNodeTexDistNoise"),
389         NodeItem("TextureNodeTexClouds"),
390         NodeItem("TextureNodeTexBlend"),
391         NodeItem("TextureNodeTexVoronoi"),
392         NodeItem("TextureNodeTexMagic"),
393         NodeItem("TextureNodeTexMarble"),
394         NodeItem("TextureNodeTexWood"),
395         NodeItem("TextureNodeTexMusgrave"),
396         NodeItem("TextureNodeTexStucci"),
397         ]),
398     TextureNodeCategory("TEX_CONVERTOR", "Converter", items=[
399         NodeItem("TextureNodeMath"),
400         NodeItem("TextureNodeValToRGB"),
401         NodeItem("TextureNodeRGBToBW"),
402         NodeItem("TextureNodeValToNor"),
403         NodeItem("TextureNodeDistance"),
404         ]),
405     TextureNodeCategory("TEX_DISTORT", "Distort", items=[
406         NodeItem("TextureNodeScale"),
407         NodeItem("TextureNodeTranslate"),
408         NodeItem("TextureNodeRotate"),
409         ]),
410     TextureNodeCategory("TEX_GROUP", "Group", items=node_group_items),
411     TextureNodeCategory("TEX_LAYOUT", "Layout", items=[
412         NodeItem("NodeFrame"),
413         NodeItem("NodeReroute"),
414         ]),
415     ]
416
417
418 def register():
419     nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
420     nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
421     nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
422
423
424 def unregister():
425     nodeitems_utils.unregister_node_categories('SHADER')
426     nodeitems_utils.unregister_node_categories('COMPOSITING')
427     nodeitems_utils.unregister_node_categories('TEXTURE')
428
429
430 if __name__ == "__main__":
431     register()