import os
+def compute_render_method_hash(material):
+ descr = ""
+ for m in material.render_methods:
+ if descr:
+ descr += ","
+ descr += "{}={}".format(m.tag, m.shader)
+ return hash(descr)
+
def check_group(node_tree, group, func):
from .util import get_linked_node_and_socket
self.render_mode = material.render_mode
self.technique = material.technique
- self.shader = material.shader
+ self.render_methods = material.render_methods[:]
self.receive_shadows = material.receive_shadows
self.cast_shadows = (material.shadow_method!='NONE')
self.image_based_lighting = material.image_based_lighting
if self.render_mode=='EXTERNAL' and not self.technique:
raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name))
- elif self.render_mode=='CUSTOM' and not self.shader:
- raise Exception("Invalid configuration on material {}: No shader for custom rendering".format(self.name))
+ elif self.render_mode=='CUSTOM' and not self.render_methods:
+ raise Exception("Invalid configuration on material {}: No render methods for custom rendering".format(self.name))
out_node = next((n for n in material.node_tree.nodes if n.type=='OUTPUT_MATERIAL'), None)
if not out_node:
if self.render_mode=='EXTERNAL':
raise Exception("Material atlas with external render mode does not make sense")
- self.shader = materials[0].shader
- if self.shader:
- self.name = "material_atlas_"+os.path.splitext(self.shader)[0]
+ if self.render_mode=='CUSTOM':
+ self.render_methods = materials[0].render_methods
+ else:
+ self.render_methods = None
+ if self.render_methods:
+ self.name = "material_atlas_"+os.path.splitext(self.render_methods[0].shader)[0]
else:
self.name = "material_atlas"
self.receive_shadows = materials[0].receive_shadows
self.cast_shadows = (materials[0].shadow_method!='NONE')
self.materials = materials
self.material_names = [m.name for m in self.materials]
+ self.uniforms = None
+ method_hash = compute_render_method_hash(self)
for m in self.materials:
if m.render_mode!=self.render_mode:
raise Exception("Conflicting render modes in MaterialAtlas constructor")
- if self.render_mode=='CUSTOM' and m.shader!=self.shader:
+ if self.render_mode=='CUSTOM' and compute_render_method_hash(m)!=method_hash:
raise Exception("Conflicting shaders in MaterialAtlas constructor")
if m.receive_shadows!=self.receive_shadows or m.shadow_method!=materials[0].shadow_method:
raise Exception("Conflicting shadow settings in MaterialAtlas constructor")
if not material.material_atlas:
raise Exception("Material is not part of a material atlas")
- shader = material.shader
+ method_hash = compute_render_method_hash(material)
materials = []
for m in context.blend_data.materials:
- if m.material_atlas and m.shader==shader:
+ if m.material_atlas and compute_render_method_hash(m)==method_hash:
materials.append(m)
return MaterialAtlas(materials)