Beispiel #1
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            // determine if an tessellation material have already been added in another layer
            hasAlreadyTessellationFeature = context.GetStreamFinalModifier <MaterialTessellationBaseFeature>(MaterialShaderStage.Domain) != null;

            // Notify problem on multiple tessellation techniques and return
            if (hasAlreadyTessellationFeature)
            {
                context.Log.Warning("A material cannot have more than one layer performing tessellation. The first tessellation method found, will be used.");
                return;
            }

            // reset the tessellation stream at the beginning of the stage
            context.AddStreamInitializer(MaterialShaderStage.Domain, "MaterialTessellationStream");

            // set the desired triangle size desired for this material
            context.Parameters.Set(TessellationKeys.DesiredTriangleSize, TriangleSize);

            // set the tessellation method and callback to add Displacement/Normal average shaders.
            if (AdjacentEdgeAverage && !context.Tags.Get(HasFinalCallback))
            {
                context.Tags.Set(HasFinalCallback, true);
                context.MaterialPass.TessellationMethod = XenkoTessellationMethod.AdjacentEdgeAverage;
                context.AddFinalCallback(MaterialShaderStage.Domain, AddAdjacentEdgeAverageMacros);
                context.AddFinalCallback(MaterialShaderStage.Domain, AddAdjacentEdgeAverageShaders);
            }
        }
Beispiel #2
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            var alpha = Alpha ?? new ComputeFloat(0.5f);
            var tint  = Tint ?? new ComputeColor(Color.White);

            alpha.ClampFloat(0, 1);

            // Use pre-multiplied alpha to support both additive and alpha blending
            if (context.MaterialPass.BlendState == null)
            {
                context.MaterialPass.BlendState = BlendStates.AlphaBlend;
            }
            context.MaterialPass.HasTransparency = true;
            // TODO GRAPHICS REFACTOR
            //context.Parameters.SetResourceSlow(Effect.BlendStateKey, BlendState.NewFake(blendDesc));

            var alphaColor = alpha.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseSpecularAlphaBlendMap, MaterialKeys.DiffuseSpecularAlphaBlendValue, Color.White));

            var mixin = new ShaderMixinSource();

            mixin.Mixins.Add(new ShaderClassSource("ComputeColorMaterialAlphaBlend"));
            mixin.AddComposition("color", alphaColor);

            context.SetStream(MaterialShaderStage.Pixel, AlphaBlendStream.Stream, MaterialStreamType.Float2, mixin);
            context.SetStream(AlphaBlendColorStream.Stream, tint, MaterialKeys.AlphaBlendColorMap, MaterialKeys.AlphaBlendColorValue, Color.White);

            context.MaterialPass.Parameters.Set(MaterialKeys.UsePixelShaderWithDepthPass, true);

            if (!context.Tags.Get(HasFinalCallback))
            {
                context.Tags.Set(HasFinalCallback, true);
                context.AddFinalCallback(MaterialShaderStage.Pixel, AddDiffuseSpecularAlphaBlendColor);
            }
        }
Beispiel #3
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            var alpha = Alpha ?? new ComputeFloat(1f);
            var tint  = Tint ?? new ComputeColor(Color.White);

            alpha.ClampFloat(0, 1);

            // Use pre-multiplied alpha to support both additive and alpha blending
            if (context.MaterialPass.BlendState == null)
            {
                context.MaterialPass.BlendState = BlendStates.AlphaBlend;
            }
            context.MaterialPass.HasTransparency = true;
            // TODO GRAPHICS REFACTOR
            //context.Parameters.SetResourceSlow(Effect.BlendStateKey, BlendState.NewFake(blendDesc));

            context.SetStream(AlphaBlendStream.Stream, alpha, MaterialKeys.DiffuseSpecularAlphaBlendMap, MaterialKeys.DiffuseSpecularAlphaBlendValue, Color.White);
            context.SetStream(AlphaBlendColorStream.Stream, tint, MaterialKeys.AlphaBlendColorMap, MaterialKeys.AlphaBlendColorValue, Color.White);

            context.MaterialPass.Parameters.Set(MaterialKeys.UsePixelShaderWithDepthPass, true);

            if (!context.Tags.Get(HasFinalCallback))
            {
                context.Tags.Set(HasFinalCallback, true);
                context.AddFinalCallback(MaterialShaderStage.Pixel, AddDiffuseSpecularAlphaBlendColor, ShadingColorAlphaFinalCallbackOrder);
            }
        }
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            var alpha = Alpha ?? new ComputeFloat(DefaultAlpha);

            alpha.ClampFloat(0, 1);
            context.SetStream(AlphaDiscardStream.Stream, alpha, MaterialKeys.AlphaDiscardMap, MaterialKeys.AlphaDiscardValue, new Color(DefaultAlpha));

            context.MaterialPass.Parameters.Set(MaterialKeys.UsePixelShaderWithDepthPass, true);

            if (!context.Tags.Get(HasFinalCallback))
            {
                context.Tags.Set(HasFinalCallback, true);
                context.AddFinalCallback(MaterialShaderStage.Pixel, AddDiscardFromLuminance);
            }
        }
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            base.GenerateShader(context);

            var attributes = context.CurrentMaterialDescriptor.Attributes;

            int glassPassIndex = context.PassIndex % 2;

            if (attributes.CullMode == CullMode.None)
            {
                context.MaterialPass.CullMode = context.PassIndex < 2 ? CullMode.Back : CullMode.Front;
            }
            else
            {
                context.MaterialPass.CullMode = attributes.CullMode;
            }

            // Compute transmittance
            context.GetShading(this).LightDependentExtraModels.Add(new ShaderClassSource("MaterialTransmittanceReflectanceStream"));

            context.Parameters.Set(MaterialTransmittanceReflectanceStreamKeys.RefractiveIndex, RefractiveIndex);
            context.MaterialPass.HasTransparency = true;
            if (glassPassIndex == 0)
            {
                // Transmittance pass
                context.MaterialPass.BlendState = new BlendStateDescription(Blend.Zero, Blend.SourceColor)
                {
                    RenderTarget0 = { AlphaSourceBlend = Blend.One, AlphaDestinationBlend = Blend.Zero }
                };

                // Shader output is matTransmittance
                // Note: we make sure to run after MaterialTransparencyBlendFeature so that shadingColorAlpha is fully updated
                context.AddFinalCallback(MaterialShaderStage.Pixel, AddMaterialSurfaceTransmittanceShading, MaterialTransparencyBlendFeature.ShadingColorAlphaFinalCallbackOrder + 1);
            }
            else if (glassPassIndex == 1)
            {
                // Reflectance pass
                context.MaterialPass.BlendState = BlendStates.Additive;
            }
        }