public MaterialBatch(Shader shader, MaterialPermutation permutation, MaterialProperties properties) { Properties = properties; Permutation = permutation; _decals = new List <DecalRenderInstance>(); BoundingSpheres = new BoundingSphere[16]; Decals = new ReadOnlyCollection <DecalRenderInstance>(_decals); var material = new Material(shader) { hideFlags = HideFlags.DontSave }; if (permutation.LayerMode == LayerMode.Single) { material.EnableKeyword("LAYERS_SINGLE"); } else if (permutation.LayerMode == LayerMode.Triplanar) { material.EnableKeyword("LAYERS_TRIPLANAR"); } if (permutation.LayerProjectionMode == ProjectionMode.Local) { material.EnableKeyword("LAYER_PROJECTION_LOCAL"); } else { material.EnableKeyword("LAYER_PROJECTION_WORLD"); } if (permutation.EnableJitter) { material.EnableKeyword("JITTER_LAYERS"); } if (permutation.Shape == DecalShape.Sphere) { material.EnableKeyword("SHAPE_CIRCLE"); } else if (permutation.Shape == DecalShape.Cube) { material.EnableKeyword("SHAPE_SQUARE"); } else if (permutation.Shape == DecalShape.Mesh) { material.EnableKeyword("SHAPE_MESH"); } else { throw new InvalidOperationException("Unknown decal shape `" + permutation.Shape + "`"); } properties.LoadInto(material); _material = material; }