对精灵的多重效果

发布于 2024-12-01 09:08:29 字数 495 浏览 3 评论 0原文

我已经使用像素着色器文件实现了效果和过渡。当我分别应用效果和过渡时,它工作正常,但如果我同时应用两者,它就不起作用。如何将多个着色器应用于精灵。下面是我正在做的代码。

_effect = Effect.FromFile(_parentRVRenderer.Device, path, null, ShaderFlags.None, null);
_effect1 = Effect.FromFile(_parentRVRenderer.Device, path1, 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();
....

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, path1, 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();
....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-12-08 09:08:29

将两个像素着色器函数放在同一个着色器中,并使用双通道技术,在每个通道中应用不同的像素着色器。

您仍然必须使用两个渲染目标将输出从第一个通道弹回到另一个通道,如上所述,但使用两通道方法比将渲染目标发送到另一种着色器技术更好。

伪代码:

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)

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)
唠甜嗑 2024-12-08 09:08:29

我不确定是否可以同时应用 2 个着色器。但我要做的是使用第一个着色器将精灵绘制到渲染目标,然后使用第二个着色器将生成的图像绘制到屏幕上。

显然,如果您可以将这些效果组合到单个着色器中,那将是理想的选择,但这并不总是可能的。这可能不是最好的解决方案,但它应该可以解决问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文