Esempio n. 1
0
        /// <summary>
        /// The constructor to create a shader effect.
        /// </summary>
        /// <param name="effectPasses">The ordered array of <see cref="EffectPassDeclaration"/> items. The first item
        /// in the array is the first pass applied to rendered geometry, and so on.</param>
        /// <param name="effectParameters">A list of (uniform) parameters possibly occurring in one of the shaders in the various passes.
        /// Each array entry consists of the parameter's name and its initial value. The concrete type of the object also indicates the
        /// parameter's type.
        /// </param>
        /// <remarks>Make sure to list any parameter in any of the different passes' shaders you want to change later on in the effectParameters
        /// list. Shaders must not contain parameters with names listed in the effectParameters but declared with different types than those of
        /// the respective default values given here.</remarks>
        public ShaderEffect(EffectPassDeclaration[] effectPasses, IEnumerable <EffectParameterDeclaration> effectParameters)
        {
            if (effectPasses == null || effectPasses.Length == 0)
            {
                throw new ArgumentNullException(nameof(effectPasses), "must not be null and must contain at least one pass");
            }

            var nPasses = effectPasses.Length;

            States = new RenderStateSet[nPasses];

            VertexShaderSrc   = new string[nPasses];
            PixelShaderSrc    = new string[nPasses];
            GeometryShaderSrc = new string[nPasses];

            ParamDecl = new Dictionary <string, object>();

            for (int i = 0; i < effectPasses.Length; i++)
            {
                States[i]            = effectPasses[i].StateSet;
                VertexShaderSrc[i]   = effectPasses[i].VS;
                PixelShaderSrc[i]    = effectPasses[i].PS;
                GeometryShaderSrc[i] = effectPasses[i].GS;
            }

            if (effectParameters != null)
            {
                foreach (var param in effectParameters)
                {
                    ParamDecl.Add(param.Name, param.Value);
                }
            }

            EffectEventArgs = new ShaderEffectEventArgs(this, ShaderEffectChangedEnum.Unchanged);
        }
Esempio n. 2
0
        private void SetShaderValues(ShaderProgram sp)
        {
            RC.SetShader(sp);
            var myset = new RenderStateSet
            {
                AlphaBlendEnable = false,
                ZEnable          = true
            };

            RC.SetRenderState(myset);
            switch (_textShaderName)
            {
            case "Diffuse Color":
                RC.SetShaderParam(_paramColor, new float4(1, 0, 0, 1));
                RC.Render(_currentMesh);
                break;

            case "Texture Only":
                RC.SetShaderParamTexture(_paramTexture, _currentTexture);
                RC.Render(_currentMesh);
                break;

            case "Diffuse Texture":
                RC.SetShaderParamTexture(_paramTexture, _currentTexture);
                RC.Render(_currentMesh);
                break;

            case "Diffuse Bump Texture":
                RC.SetShaderParamTexture(_paramTexture, _currentTexture);
                RC.SetShaderParamTexture(_paramBumpTexture, _currentBumpTexture);
                RC.SetShaderParam(_paramSpecular, 64.0f);
                RC.SetShaderParam(_paramShininess, 0.5f);
                RC.Render(_currentMesh);
                break;

            case "Specular Texture":
                RC.SetShaderParamTexture(_paramTexture, _currentTexture);
                RC.SetShaderParam(_paramSpecular, 64.0f);
                RC.SetShaderParam(_paramShininess, 0.5f);
                RC.Render(_currentMesh);
                break;

            case "Toon":
                RC.SetRenderState(new RenderStateSet
                {
                    AlphaBlendEnable = true,
                    BlendFactor      = new float4(0.5f, 0.5f, 0.5f, 0.5f),
                    BlendOperation   = BlendOperation.Add,
                    SourceBlend      = Blend.BlendFactor,
                    DestinationBlend = Blend.InverseBlendFactor
                });

                _shaderEffect.RenderMesh(_currentMesh);
                break;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new instance of type ShaderEffectProtoPixel.
        /// </summary>
        /// <param name="effectPasses"></param>
        /// <param name="effectParameters"></param>
        public ShaderEffectProtoPixel(EffectPassDeclarationProto[] effectPasses, IEnumerable <EffectParameterDeclaration> effectParameters)
        {
            if (effectPasses == null || effectPasses.Length == 0)
            {
                throw new ArgumentNullException(nameof(effectPasses), "must not be null and must contain at least one pass");
            }

            var nPasses = effectPasses.Length;

            States = new RenderStateSet[nPasses];

            VertexShaderSrc   = new string[nPasses];
            PixelShaderSrc    = new string[nPasses];
            GeometryShaderSrc = new string[nPasses];

            ParamDecl = new Dictionary <string, object>();

            if (effectParameters != null)
            {
                foreach (var param in effectParameters)
                {
                    ParamDecl.Add(param.Name, param.Value);
                }
            }

            _effectPasses = effectPasses;

            for (int i = 0; i < nPasses; i++)
            {
                States[i]            = effectPasses[i].StateSet;
                VertexShaderSrc[i]   = effectPasses[i].VS;
                GeometryShaderSrc[i] = effectPasses[i].GS;
                //PixelShaderSrc is not set here because it gets built in a pre-pass, depending on whether we render deferred or forward.
            }

            EffectEventArgs = new ShaderEffectEventArgs(this, ShaderEffectChangedEnum.Unchanged);
        }