开发者

Multiple Effect on the sprite

开发者 https://www.devze.com 2023-03-30 11:52 出处:网络
I have implement the effect and Transition using pixel shader files. When i apply effect and transition separately it working fine, but if i am applying both simultaneously it is not working. How can

I have implement the effect and Transition using pixel shader files. When i apply effect and transition separately it working fine, but if i am applying both simultaneously it is not working. How can apply multiple shader to a sprite. Below is code what i am doing.

_effect = Effect.FromFile(_parentRVRenderer.Device, path, null, ShaderFlags.None, null);
_effect1 = Effect.FromFile(_parentRVRenderer.Device, pat开发者_StackOverflow社区h1, null, ShaderFlags.None, null);
_effect.Technique = "TransformTexture";
_effect1.Technique = "TransformTexture";

_effect1.Begin(0);
_effect1.BeginPass(0);
_effect.Begin(0);
_effect.BeginPass(0);
sprint.Begin()
Sprite.Draw();
....


Put your two pixel shader functions in the same shader, and use a two-pass technique that applies a different pixel shader in each pass.

You still have to use two render targets to bounce the output from the first pass to the other as stated above, but it's better to use the two-pass approach than sending the render target to another shader technique.

Pseudocode:

RenderTarget2D[2] targets;

// (Draw all your sprites to target 0)

// target 1 will be empty, will be used in pass 0 (even pass)

effect.Technique = "TwoPassTechnique";

for (int i = 0; i < effect.Passes.Count; i++) 
{
    // Even pass sets target 1, odd pass sets target 0
    GraphicsDevice.setRenderTarget(targets[1 - i % 2]);
    effect(i).BeginPass;

    // Even pass samples texture from target 0, odd pass uses target 1
    effect(i).Parameters["texture"].SetValue(targets[i % 2]);

    // Draw a 2D quad with extents (-1, -1), (1, 1) in screen space 
}
// Final contents are now stored in target 0

// (Draw target 0's texture to the screen, using a sprite or another 2D quad)


I'm unsure as to if you can apply 2 shaders simultaneously. But what i would do, is draw the sprite to a render target using the first shader, and then draw the resulting image to the screen using the second shader.

Obviously it would be ideal if you could combine the effects into a single shader but thats not always possible. This might not be the best solution, but it should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号