Question

I make a test with Effect class in XNA and I want to set multiple times the same parameters (MyParameter in below code).

My code is :

[...]
//In Engine class
Effect ShaderEffect = GameEngine.Instance.Content.Load<Effect>(@"shaders\test");

spriteBatch.Begin(
    SpriteSortMode.Deferred,
    BlendState.AlphaBlend,
    SamplerState.PointWrap,
    DepthStencilState.Default,
    RasterizerState.CullNone,
    ShaderEffect);

[...]

//in drawable class
foreach(//big loop) {
     ShaderEffect.Parameters["MyParameter"].SetValue(//random vector4);
     spriteBatch.Draw(
            SpriteSheet,
            ScreenRect,
            sprite_to_draw.Rectangle,
            color,
            rotation,
            Scene.getInstance().Camera.Position,
            sprite_to_draw.SpriteEffect,
            layer
     );
}

[...]

//In Engine class
spriteBatch.End();
[...]

But on my screen it look like the Parameter "MyParameter" is not overwrite.

So can I overwrite it and If yes do you know how ?

Thanks

Was it helpful?

Solution

I resolv my problem by hijacking the color param as follow :

/*
* hijack color desciption :
* r : offset color of refill magenta
* g : offset color of refill cyan
* b : offset color of local light
* a : 0 - 255 intensity of light color, usefull for smoothy light
*/

After that I only need to specify color member (r/g/b/a) in spritebatch for a object given which match the color_list shader array below :

color_list[0] = float4(0.969, 0.627, 0.145,1) ;     //red hair
color_list[1] = float4(1, 0.894, 0.173,1) ;         //golden red
color_list[2] = float4(0.953, 0.953, 0.953,1) ;     //white hair
color_list[3] = float4(0.1, 0.1, 0.1,1) ;           //black hair
color_list[4] = float4(0.424, 0.314, 0.082,1) ;     //brown
color_list[5] = float4(0.5,0.5,0.5,1) ;             //grey
color_list[6] = float4(1,0.906,0.098,1) ;           //gold
color_list[7] = float4(0.651, 0.643, 0.584,1) ;     //pure iron
color_list[8] = float4(0.294, 0.459, 0.6,1) ;       //bluejeans
color_list[9] = float4(0.714, 0.439, 0.114,1) ;     //leather1
color_list[10] = float4(0.714, 0.243, 0.114,1) ;    //leather2
color_list[11] = float4(1, 1, 1,1) ;    //white
color_list[12] = float4(0.027, 0.49, 0.102,1) ;     //greenpants
color_list[13] = float4(1,0,0,1) ;                  //red
color_list[14] = float4(1,1,1,0.3) ;                //ghost

Then in shader I match/change color with an offset given.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top