public ShaderGeneratorContext(GraphicsDevice graphicsDevice = null)
 {
     this.graphicsDevice   = graphicsDevice;
     Parameters            = new ParameterCollection();
     parameterKeyIndices   = new Dictionary <ParameterKey, int>();
     declaredSamplerStates = new Dictionary <SamplerStateDescription, ObjectParameterKey <SamplerState> >();
     currentOverrides      = new MaterialOverrides();
 }
 public ShaderGeneratorContext(GraphicsDevice graphicsDevice = null)
 {
     this.graphicsDevice = graphicsDevice;
     Parameters = new ParameterCollection();
     parameterKeyIndices = new Dictionary<ParameterKey, int>();
     declaredSamplerStates = new Dictionary<SamplerStateDescription, ObjectParameterKey<SamplerState>>();
     currentOverrides = new MaterialOverrides();
 }
Ejemplo n.º 3
0
        ///// <summary>
        ///// Gets or sets the scale v.
        ///// </summary>
        ///// <value>The scale v.</value>
        //[DefaultValue(1.0f)]
        //[DataMember(90)]
        //public float ScaleV { get; set; }

        /// <summary>
        /// Implements the multiply operator in order to support correct calculation of overrides for a particular layer.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static MaterialOverrides operator *(MaterialOverrides left, MaterialOverrides right)
        {
            var overrides = new MaterialOverrides {
                UVScale = left.UVScale * right.UVScale
            };

            return(overrides);
        }
 private void UpdateOverrides()
 {
     // Update overrides by squashing them using multiplication
     currentOverrides = new MaterialOverrides();
     foreach (var current in overridesStack)
     {
         currentOverrides *= current;
     }
 }
 public void PushOverrides(MaterialOverrides overrides)
 {
     if (overrides == null)
     {
         throw new ArgumentNullException("overrides");
     }
     overridesStack.Push(overrides);
     UpdateOverrides();
 }
Ejemplo n.º 6
0
        public MaterialGeneratorContext(Material material = null)
        {
            this.material = material ?? new Material();
            Parameters    = this.material.Parameters;

            currentOverrides = new MaterialOverrides();

            foreach (MaterialShaderStage stage in Enum.GetValues(typeof(MaterialShaderStage)))
            {
                finalCallbacks[stage] = new List <MaterialGeneratorCallback>();
            }

            // By default return the asset
            FindAsset            = asset => ((Material)asset).Descriptor;
            GetAssetFriendlyName = asset => ((Material)asset).Descriptor != null ? ((Material)asset).Descriptor.MaterialId.ToString() : string.Empty;
        }
Ejemplo n.º 7
0
        public override void GenerateShader(MaterialGeneratorContext context)
        {
            // Exclude ambient occlusion from uv-scale overrides
            var revertOverrides = new MaterialOverrides();

            revertOverrides.UVScale = 1.0f / context.CurrentOverrides.UVScale;

            context.PushOverrides(revertOverrides);
            context.SetStream(OcclusionStream.Stream, AmbientOcclusionMap, MaterialKeys.AmbientOcclusionMap, MaterialKeys.AmbientOcclusionValue, Color.White);
            context.PopOverrides();

            context.SetStream("matAmbientOcclusionDirectLightingFactor", DirectLightingFactor, null, MaterialKeys.AmbientOcclusionDirectLightingFactorValue);

            if (CavityMap != null)
            {
                context.SetStream(CavityStream.Stream, CavityMap, MaterialKeys.CavityMap, MaterialKeys.CavityValue, Color.White);
                context.SetStream("matCavityDiffuse", DiffuseCavity, null, MaterialKeys.CavityDiffuseValue);
                context.SetStream("matCavitySpecular", SpecularCavity, null, MaterialKeys.CavitySpecularValue);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialBlendLayer"/> class.
 /// </summary>
 public MaterialBlendLayer()
 {
     Enabled   = true;
     BlendMap  = new ComputeTextureScalar();
     Overrides = new MaterialOverrides();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialAttributes"/> class.
 /// </summary>
 public MaterialAttributes()
 {
     CullMode  = CullMode.Back;
     Overrides = new MaterialOverrides();
 }
Ejemplo n.º 10
0
        ///// <summary>
        ///// Gets or sets the scale v.
        ///// </summary>
        ///// <value>The scale v.</value>
        //[DefaultValue(1.0f)]
        //[DataMember(90)]
        //public float ScaleV { get; set; }

        /// <summary>
        /// Implements the multiply operator in order to support correct calculation of overrides for a particular layer.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static MaterialOverrides operator *(MaterialOverrides left, MaterialOverrides right)
        {
            var overrides = new MaterialOverrides { UVScale = left.UVScale * right.UVScale };
            return overrides;
        }
        public override void VisitFeature(MaterialGeneratorContext context)
        {
            // Exclude ambient occlusion from uv-scale overrides
            var revertOverrides = new MaterialOverrides();
            revertOverrides.UVScale = 1.0f / context.CurrentOverrides.UVScale;

            context.PushOverrides(revertOverrides);
            context.SetStream(OcclusionStream.Stream, AmbientOcclusionMap, MaterialKeys.AmbientOcclusionMap, MaterialKeys.AmbientOcclusionValue, Color.White);
            context.PopOverrides();

            context.SetStream("matAmbientOcclusionDirectLightingFactor", DirectLightingFactor, null, MaterialKeys.AmbientOcclusionDirectLightingFactorValue);

            if (CavityMap != null)
            {
                context.SetStream(CavityStream.Stream, CavityMap, MaterialKeys.CavityMap, MaterialKeys.CavityValue, Color.White);
                context.SetStream("matCavityDiffuse", DiffuseCavity, null, MaterialKeys.CavityDiffuseValue);
                context.SetStream("matCavitySpecular", SpecularCavity, null, MaterialKeys.CavitySpecularValue);
            }
        }
 private void UpdateOverrides()
 {
     // Update overrides by squashing them using multiplication
     currentOverrides = new MaterialOverrides();
     foreach (var current in overridesStack)
     {
         currentOverrides *= current;
     }
 }
 public void PushOverrides(MaterialOverrides overrides)
 {
     if (overrides == null) throw new ArgumentNullException("overrides");
     overridesStack.Push(overrides);
     UpdateOverrides();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialAttributes"/> class.
 /// </summary>
 public MaterialAttributes()
 {
     CullMode = CullMode.Back;
     Overrides = new MaterialOverrides();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialBlendLayer"/> class.
 /// </summary>
 public MaterialBlendLayer()
 {
     Enabled = true;
     BlendMap = new ComputeTextureScalar();
     Overrides = new MaterialOverrides();
 }