Beispiel #1
0
        public virtual void Visit(MaterialGeneratorContext context)
        {
            // If not enabled, or Material or BlendMap are null, skip this layer
            if (!Enabled || Material == null || BlendMap == null || context.FindAsset == null)
            {
                return;
            }

            // Find the material from the reference
            var material = context.FindAsset(Material) as IMaterialDescriptor;

            if (material == null)
            {
                context.Log.Error($"Unable to find material [{Material}]");
                return;
            }

            // Check that material is valid
            var materialName = context.GetAssetFriendlyName(Material);

            if (!context.PushMaterial(material, materialName))
            {
                return;
            }

            try
            {
                // TODO: Because we are not fully supporting Streams declaration in shaders, we have to workaround this limitation by using a dynamic shader (inline)
                // Push a layer for the sub-material
                context.PushOverrides(Overrides);
                context.PushLayer(BlendMap);

                // Generate the material shaders into the current context
                material.Visit(context);
            }
            finally
            {
                // Pop the stack
                context.PopLayer();
                context.PopOverrides();
                context.PopMaterial();
            }
        }