Ejemplo n.º 1
0
        private void BlendShadingModel(MaterialBlendLayerContext parent, MaterialBlendLayerPerStageContext pendingPixelLayerContext, MaterialBlendLayerPerStageContext parentPixelLayerContext)
        {
            var shaderBlendingSource = new ShaderMixinSource();

            shaderBlendingSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceShadingBlend"));

            parent.SetStreamBlend(MaterialShaderStage.Pixel, parent.BlendMapForShadingModel);

            // Add shader source already setup for the parent
            foreach (var shaderSource in pendingPixelLayerContext.ShaderSources)
            {
                shaderBlendingSource.AddCompositionToArray("layers", shaderSource);
            }

            // Add shader source generated for blending this layer
            foreach (var shaderSource in parent.ShadingModels.Generate(this))
            {
                shaderBlendingSource.AddCompositionToArray("layers", shaderSource);
            }
            parent.ShadingModels.Clear();

            parentPixelLayerContext.ShaderSources.Add(shaderBlendingSource);

            pendingPixelLayerContext.Reset();
            parent.BlendMapForShadingModel = null;
        }
        /// <summary>
        /// Initializes a new instance of <see cref="MaterialBlendLayerContext"/>.
        /// </summary>
        /// <param name="context">The material generator context</param>
        /// <param name="parentLayerContext">The parent layer context</param>
        /// <param name="blendMap">The blend map used for this layer</param>
        public MaterialBlendLayerContext(MaterialGeneratorContext context, MaterialBlendLayerContext parentLayerContext, IComputeScalar blendMap)
        {
            if (context == null) throw new ArgumentNullException(nameof(context));
            Context = context;
            Parent = parentLayerContext;
            BlendMap = blendMap;

            Children = new List<MaterialBlendLayerContext>();
            ShadingModels = new MaterialShadingModelCollection();

            ContextPerStage = new Dictionary<MaterialShaderStage, MaterialBlendLayerPerStageContext>();
            foreach (MaterialShaderStage stage in Enum.GetValues(typeof(MaterialShaderStage)))
            {
                ContextPerStage[stage] = new MaterialBlendLayerPerStageContext();
            }

            PendingPixelLayerContext = new MaterialBlendLayerPerStageContext();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="MaterialBlendLayerContext"/>.
        /// </summary>
        /// <param name="context">The material generator context</param>
        /// <param name="parentLayerContext">The parent layer context</param>
        /// <param name="blendMap">The blend map used for this layer</param>
        public MaterialBlendLayerContext(MaterialGeneratorContext context, MaterialBlendLayerContext parentLayerContext, IComputeScalar blendMap)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            Context  = context;
            Parent   = parentLayerContext;
            BlendMap = blendMap;

            Children      = new List <MaterialBlendLayerContext>();
            ShadingModels = new MaterialShadingModelCollection();

            ContextPerStage = new Dictionary <MaterialShaderStage, MaterialBlendLayerPerStageContext>();
            foreach (MaterialShaderStage stage in Enum.GetValues(typeof(MaterialShaderStage)))
            {
                ContextPerStage[stage] = new MaterialBlendLayerPerStageContext();
            }

            PendingPixelLayerContext = new MaterialBlendLayerPerStageContext();
        }