我在XNA中使用Effect类进行测试,我想设置多次相同的参数(下面代码中的MyParameter)。
我的代码是:
[...]
//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();
[...]
但是在我的屏幕上,它看起来像参数“MyParameter”没有被覆盖。
我可以覆盖它,如果是,你知道怎么做吗?
由于
答案 0 :(得分:0)
我通过劫持颜色参数来解决我的问题如下:
/*
* 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
*/
之后我只需要在spritebatch中为给定的对象指定颜色成员(r / g / b / a),该对象与下面的color_list着色器数组匹配:
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
然后在着色器中我匹配/更改颜色并给出偏移量。