Пример #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);
        }
 public void Visit(MaterialGeneratorContext context)
 {
     if (MetalnessMap != null)
     {
         var computeColorSource = MetalnessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.MetalnessMap, MaterialKeys.MetalnessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceMetalness"));
         mixin.AddComposition("metalnessMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, "matSpecular");
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
 public void Visit(MaterialGeneratorContext context)
 {
     if (GlossinessMap != null)
     {
         context.UseStream(MaterialShaderStage.Pixel, GlossinessStream.Stream);
         var computeColorSource = GlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMap", Invert));
         mixin.AddComposition("glossinessMap", computeColorSource);
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
Пример #4
0
 public void Visit(MaterialGeneratorContext context)
 {
     if (DiffuseMap != null)
     {
         var computeColorSource = DiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
         var mixin = new ShaderMixinSource();
         mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
         mixin.AddComposition("diffuseMap", computeColorSource);
         context.UseStream(MaterialShaderStage.Pixel, DiffuseStream.Stream);
         context.UseStream(MaterialShaderStage.Pixel, ColorBaseStream.Stream);
         context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
     }
 }
Пример #5
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, new Color(0x80, 0x80, 0xFF, 0xFF)));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
            }
        }
Пример #6
0
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            if (NormalMap != null)
            {
                // Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
                context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
                context.Parameters.Set(MaterialKeys.HasNormalMap, true);

                var normalMap = NormalMap;
                // Workaround to make sure that normal map are setup
                var computeTextureColor = normalMap as ComputeTextureColor;
                if (computeTextureColor != null)
                {
                    if (computeTextureColor.FallbackValue.Value == Color.White)
                    {
                        computeTextureColor.FallbackValue.Value = DefaultNormalColor;
                    }
                }
                else
                {
                    var computeColor = normalMap as ComputeColor;
                    if (computeColor != null)
                    {
                        if (computeColor.Value == Color.Black || computeColor.Value == Color.White)
                        {
                            computeColor.Value = DefaultNormalColor;
                        }
                    }
                }

                var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, DefaultNormalColor, false));
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
                mixin.AddComposition("normalMap", computeColorSource);
                context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
            }
        }
Пример #7
0
 private void AddDiscardFromLuminance(MaterialShaderStage stage, MaterialGeneratorContext context)
 {
     context.AddSurfaceShader(MaterialShaderStage.Pixel, new ShaderClassSource("MaterialSurfaceTransparentAlphaDiscard"));
 }
 private void AddDiffuseSpecularAlphaBlendColor(MaterialShaderStage stage, MaterialGeneratorContext context)
 {
     context.AddSurfaceShader(MaterialShaderStage.Pixel, new ShaderClassSource("MaterialSurfaceDiffuseSpecularAlphaBlendColor"));
 }