コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MaterialStreamDescriptor"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="stream">The stream.</param>
 /// <param name="filter">The filter.</param>
 /// <exception cref="System.ArgumentNullException">
 /// name
 /// or
 /// stream
 /// </exception>
 public MaterialStreamDescriptor(string name, string stream, ShaderSource filter = null)
 {
     if (name == null) throw new ArgumentNullException("name");
     if (stream == null) throw new ArgumentNullException("stream");
     Name = name;
     Stream = stream;
     Filter = filter ?? GetDefaultFilter(stream, typeof(Color3));
 }
コード例 #2
0
ファイル: IEffectMixinProvider.cs プロジェクト: cg123/xenko
 public DefaultEffectMixinProvider(string name)
 {
     shaderSource = new ShaderClassSource(name);
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShaderMixinDiscardException"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 public ShaderMixinDiscardException(ShaderSource source)
 {
     DiscardSource = source;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShaderMixinDiscardException"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 public ShaderMixinDiscardException(ShaderSource source)
 {
     DiscardSource = source;
 }
コード例 #5
0
 /// <summary>
 /// Adds a composition to this mixin.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="shaderSource">The shader source.</param>
 public void AddComposition(string name, ShaderSource shaderSource)
 {
     Compositions[name] = shaderSource;
 }
コード例 #6
0
        public void SetStream(MaterialShaderStage stage, string stream, MaterialStreamType streamType, ShaderSource classSource)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            // Blend stream is not part of the stream used
            if (stream != MaterialBlendLayer.BlendStream)
            {
                GetContextPerStage(stage).Streams.Add(stream);
            }

            string channel;
            switch (streamType)
            {
                case MaterialStreamType.Float:
                    channel = "r";
                    break;
                case MaterialStreamType.Float2:
                    channel = "rg";
                    break;
                case MaterialStreamType.Float3:
                    channel = "rgb";
                    break;
                case MaterialStreamType.Float4:
                    channel = "rgba";
                    break;
                default:
                    throw new NotSupportedException("StreamType [{0}] is not supported".ToFormat(streamType));
            }

            var mixin = new ShaderMixinSource();
            mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceSetStreamFromComputeColor", stream, channel));
            mixin.AddComposition("computeColorSource", classSource);

            GetContextPerStage(stage).ShaderSources.Add(mixin);
        }
コード例 #7
0
        /// <summary>
        /// Build a encapsulating ShaderMixinSource if necessary.
        /// </summary>
        /// <param name="shaderSource">The input ShaderSource.</param>
        /// <returns>A ShaderMixinSource</returns>
        public static ShaderMixinSource GetShaderMixinSource(ShaderSource shaderSource)
        {
            if (shaderSource is ShaderClassSource)
            {
                var mixin = new ShaderMixinSource();
                mixin.Mixins.Add((ShaderClassSource)shaderSource);
                return mixin;
            }
            if (shaderSource is ShaderMixinSource)
                return (ShaderMixinSource)shaderSource;

            return null;
        }
コード例 #8
0
        private void UpdateShaders(GraphicsDevice graphicsDevice)
        {
            if (ComputeColor != null && ComputeScalar != null)
            {
                var shaderGeneratorContext = new ShaderGeneratorContext(graphicsDevice)
                {
                    Parameters = Parameters,
                    ColorSpace = graphicsDevice.ColorSpace
                };

                // Don't forget to set the proper color space!
                shaderGeneratorContext.ColorSpace = graphicsDevice.ColorSpace;

                var newShaderBaseColor = ComputeColor.GenerateShaderSource(shaderGeneratorContext, new MaterialComputeColorKeys(ParticleCustomShaderKeys.EmissiveMap, ParticleCustomShaderKeys.EmissiveValue, Color.White));
                var newShaderBaseScalar = ComputeScalar.GenerateShaderSource(shaderGeneratorContext, new MaterialComputeColorKeys(ParticleCustomShaderKeys.IntensityMap, ParticleCustomShaderKeys.IntensityValue, Color.White));

                // Check if shader code has changed
                if (!newShaderBaseColor.Equals(shaderBaseColor) || !newShaderBaseScalar.Equals(shaderBaseScalar))
                {
                    shaderBaseColor = newShaderBaseColor;
                    shaderBaseScalar = newShaderBaseScalar;
                    Parameters.Set(ParticleCustomShaderKeys.BaseColor, shaderBaseColor);
                    Parameters.Set(ParticleCustomShaderKeys.BaseIntensity, shaderBaseScalar);

                    // TODO: Is this necessary?
                    HasVertexLayoutChanged = true;
                }
            }
        }
コード例 #9
0
ファイル: SkyBoxPlugin.cs プロジェクト: h78hy78yhoi8j/xenko
 public SkyBoxPlugin(string name, ShaderSource skyBoxComposition)
     : base(name)
 {
     Texture = null;
     SkyBoxColor = skyBoxComposition;
 }
コード例 #10
0
 protected LightShaderGroup(ShaderSource mixin)
 {
     ShaderSource = mixin;
 }
コード例 #11
0
 public LightSkyBoxShaderGroup(ShaderSource mixin) : base(mixin)
 {
     HasEffectPermutations = true;
 }
コード例 #12
0
        /// <summary>
        /// Polls the shader generator if the shader code has changed and has to be reloaded
        /// </summary>
        /// <param name="graphicsDevice">The current <see cref="GraphicsDevice"/></param>
        private void UpdateShaders(GraphicsDevice graphicsDevice)
        {
            // TODO Part of the graphics improvement XK-3052
            // Don't do this every frame, we have to propagate changes better
            if (--shadersUpdateCounter > 0)
                return;
            shadersUpdateCounter = 10;

            if (ComputeColor != null)
            {
                if (ComputeColor.HasChanged)
                {
                    var shaderGeneratorContext = new ShaderGeneratorContext(graphicsDevice)
                    {
                        Parameters = Parameters,
                        ColorSpace = graphicsDevice.ColorSpace
                    };

                    shaderSource = ComputeColor.GenerateShaderSource(shaderGeneratorContext, new MaterialComputeColorKeys(ParticleBaseKeys.EmissiveMap, ParticleBaseKeys.EmissiveValue, Color.White));

                    if (Parameters.Get(ParticleBaseKeys.BaseColor)?.Equals(shaderSource) ?? false)
                    {
                        shaderSource = Parameters.Get(ParticleBaseKeys.BaseColor);
                    }
                    else
                    {
                        Parameters.Set(ParticleBaseKeys.BaseColor, shaderSource);
                    }

                    HasVertexLayoutChanged = true;
                }
            }
        }