Esempio n. 1
0
        private void Generate(MaterialShaderStage stage, MaterialGeneratorContext context)
        {
            if (!context.HasSurfaceShaders(stage))
            {
                return;
            }

            // Blend setup for this layer
            context.SetStream(stage, BlendStream, BlendMap, MaterialKeys.BlendMap, MaterialKeys.BlendValue);

            // Generate a dynamic shader name
            // Create a mixin
            var shaderMixinSource = new ShaderMixinSource();

            shaderMixinSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceStreamsBlend"));

            // Add all streams
            foreach (var stream in context.Streams[stage])
            {
                shaderMixinSource.AddCompositionToArray("blends", context.GetStreamBlendShaderSource(stream));
            }

            var materialBlendLayerMixin = context.GenerateSurfaceShader(stage);

            // Add the shader to the mixin
            shaderMixinSource.AddComposition("layer", materialBlendLayerMixin);

            context.ResetSurfaceShaders(stage);
            context.AddSurfaceShader(stage, shaderMixinSource);
        }
Esempio n. 2
0
        public static MaterialShaderResult Generate(MaterialDescriptor materialDescriptor, MaterialGeneratorContext context, string rootMaterialFriendlyName)
        {
            if (materialDescriptor == null)
            {
                throw new ArgumentNullException("materialDescriptor");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var result = new MaterialShaderResult();

            context.Log = result;

            var material = context.Material;

            result.Material = context.Material;

            context.Parameters = material.Parameters;
            context.PushMaterial(materialDescriptor, rootMaterialFriendlyName);
            context.PushLayer();
            materialDescriptor.Visit(context);
            context.PopLayer();
            context.PopMaterial();

            if (!material.Parameters.ContainsKey(MaterialKeys.TessellationShader))
            {
                material.Parameters.Set(MaterialKeys.TessellationShader, null);
            }

            material.Parameters.Set(MaterialKeys.VertexStageSurfaceShaders, context.GenerateSurfaceShader(MaterialShaderStage.Vertex));
            material.Parameters.Set(MaterialKeys.DomainStageSurfaceShaders, context.GenerateSurfaceShader(MaterialShaderStage.Domain));
            material.Parameters.Set(MaterialKeys.PixelStageSurfaceShaders, context.GenerateSurfaceShader(MaterialShaderStage.Pixel));

            material.Parameters.Set(MaterialKeys.VertexStageStreamInitializer, context.GenerateStreamInitializer(MaterialShaderStage.Vertex));
            material.Parameters.Set(MaterialKeys.DomainStageStreamInitializer, context.GenerateStreamInitializer(MaterialShaderStage.Domain));
            material.Parameters.Set(MaterialKeys.PixelStageStreamInitializer, context.GenerateStreamInitializer(MaterialShaderStage.Pixel));

            return(result);
        }