]> git.tdb.fi Git - libs/gl.git/commitdiff
Export shadow settings from Blender
authorMikko Rasa <tdb@tdb.fi>
Mon, 19 Apr 2021 08:29:03 +0000 (11:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 19 Apr 2021 15:02:21 +0000 (18:02 +0300)
blender/io_mspgl/export_material.py
blender/io_mspgl/material.py
blender/io_mspgl/properties.py

index bf7e2b3f5b8d4824dc3a132b75ff93a93b0cdce8..97bb8e9e66dc06f76fdbbd38571b236253226fe2 100644 (file)
@@ -21,9 +21,16 @@ def create_technique_resource(material, resources):
                        for u in material.uniforms:
                                ss.sub.append(Statement("uniform", u.name, *u.values[:u.size]))
                        st.sub.append(ss)
+       elif material.receive_shadows:
+               st.sub.append(Statement("receive_shadows", True))
 
        tech_res.statements.append(st)
 
+       if material.shadow_method!='NONE':
+               st = Statement("pass", "shadow")
+               st.sub.append(Statement("shader", "_occluder.glsl.shader"))
+               tech_res.statements.append(st)
+
        return tech_res
 
 class MaterialExporter:
index ba5fc3e2c6cb7567b0563b391cf8d4a3c0c21cf2..2613edac67478dae4d4ef57a1c537bc6af487bd8 100644 (file)
@@ -96,6 +96,8 @@ class Material:
                self.render_mode = material.render_mode
                self.technique = material.technique
                self.shader = material.shader
+               self.receive_shadows = material.receive_shadows
+               self.cast_shadows = (material.shadow_method!='NONE')
 
                if self.render_mode=='EXTERNAL' and not self.technique:
                        raise Exception("Invalid configuration on material {}: No technique for external rendering".format(self.name))
@@ -171,6 +173,8 @@ class MaterialAtlas:
                        self.name = "material_atlas_"+os.path.splitext(self.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]
                for m in self.materials:
@@ -178,6 +182,8 @@ class MaterialAtlas:
                                raise Exception("Conflicting render modes in MaterialAtlas constructor")
                        if self.render_mode=='CUSTOM' and m.shader!=self.shader:
                                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")
 
                count = len(self.materials)
                size = 1
index 7fad772bb4fc96669dbba5facef15df16037b1c5..0648946e749a7ccd2f15e9d4ca189c6fd6d142ad 100644 (file)
@@ -88,6 +88,8 @@ class MspGLMaterialProperties(bpy.types.Panel):
                elif mat.render_mode=='EXTERNAL':
                        self.layout.prop(mat, "technique")
                self.layout.prop(mat, "array_atlas")
+               if mat.render_mode=='BUILTIN':
+                       self.layout.prop(mat, "receive_shadows")
                if mat.array_atlas:
                        self.layout.prop(mat, "array_layer")
                if mat.render_mode!='EXTERNAL':
@@ -223,6 +225,7 @@ def register_properties():
                        ("EXTERNAL", "External technique", "Use an externally defined technique")))
        bpy.types.Material.technique = bpy.props.StringProperty(name="Custom technique", description="Name of an external technique to use for rendering")
        bpy.types.Material.shader = bpy.props.StringProperty(name="Custom shader", description="Name of an external technique to use for rendering")
+       bpy.types.Material.receive_shadows = bpy.props.BoolProperty(name="Receive shadows", description="Receive shadows from a shadow map", default=True)
        bpy.types.Material.array_atlas = bpy.props.BoolProperty(name="Texture array atlas", description="The material is stored in a texture array")
        bpy.types.Material.array_layer = bpy.props.IntProperty("Texture array layer", description="Layer of the texture array atlas to use")
        bpy.types.Material.material_atlas = bpy.props.BoolProperty(name="Material atlas", description="Make this material part of a material atlas")