【发布时间】:2016-09-18 10:40:50
【问题描述】:
所以我有以下问题:
我想在我的游戏中有一个漂亮的绽放效果。但是当我尝试使用我的着色器和 shader.draw();方法被称为它看起来没有变化......看起来它不会使用着色器。此外,当我更改着色器参数时,没有任何变化。我可以将 BloomThreshold 设置为 10000f,它看起来像 0f 或 1f ...我对着色器完全陌生,所以我很高兴能得到一些帮助!
左边有着色器,右边没有着色器:
这是我的绘制循环:
protected override void Draw (GameTime gameTime) {
bloom.BeginDraw();
bloom.Draw(gameTime);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
spriteBatch.Draw(texture, new Rectangle(300, 300, 50, 50), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
这是我的bloom类的调用方法的摘录:
/// <summary>
/// This should be called at the very start of the scene rendering. The bloom
/// component uses it to redirect drawing into its custom rendertarget, so it
/// can capture the scene image in preparation for applying the bloom filter.
/// </summary>
public void BeginDraw()
{
if (Visible)
{
GraphicsDevice.SetRenderTarget(sceneRenderTarget);
}
}
/// <summary>
/// This is where it all happens. Grabs a scene that has already been rendered,
/// and uses postprocess magic to add a glowing bloom effect over the top of it.
/// </summary>
public override void Draw(GameTime gameTime)
{
GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp;
// Pass 1: draw the scene into rendertarget 1, using a
// shader that extracts only the brightest parts of the image.
bloomExtractEffect.Parameters["BloomThreshold"].SetValue(
Settings.BloomThreshold);
DrawFullscreenQuad(sceneRenderTarget, renderTarget1,
bloomExtractEffect,
IntermediateBuffer.PreBloom);
// Pass 2: draw from rendertarget 1 into rendertarget 2,
// using a shader to apply a horizontal gaussian blur filter.
SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0);
DrawFullscreenQuad(renderTarget1, renderTarget2,
gaussianBlurEffect,
IntermediateBuffer.BlurredHorizontally);
// Pass 3: draw from rendertarget 2 back into rendertarget 1,
// using a shader to apply a vertical gaussian blur filter.
SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height);
DrawFullscreenQuad(renderTarget2, renderTarget1,
gaussianBlurEffect,
IntermediateBuffer.BlurredBothWays);
// Pass 4: draw both rendertarget 1 and the original scene
// image back into the main backbuffer, using a shader that
// combines them to produce the final bloomed result.
GraphicsDevice.SetRenderTarget(null);
EffectParameterCollection parameters = bloomCombineEffect.Parameters;
parameters["BloomIntensity"].SetValue(Settings.BloomIntensity);
parameters["BaseIntensity"].SetValue(Settings.BaseIntensity);
parameters["BloomSaturation"].SetValue(Settings.BloomSaturation);
parameters["BaseSaturation"].SetValue(Settings.BaseSaturation);
//GraphicsDevice.Textures[1] = sceneRenderTarget;
bloomCombineEffect.Parameters["BaseTexture"].SetValue(sceneRenderTarget);
Viewport viewport = GraphicsDevice.Viewport;
DrawFullscreenQuad(renderTarget1,
viewport.Width, viewport.Height,
bloomCombineEffect,
IntermediateBuffer.FinalResult);
System.Console.WriteLine("Draw Called");
}
【问题讨论】:
-
投了反对票,因为问题本身不包含任何代码,如果不查看将来可能会停止工作的外部链接,就无法回答。
-
嗯,一个链接总比没有好。如果将代码发布到问题中,则不是整个项目,只是相关部分。
-
Ja 这就是问题所在......有 3 个着色器和 4 个类......所有这些都是相关的。当您可以撤消否决票时,我会很高兴:/
-
将您的问题缩小到代码的一小部分。如果您不知道如何:弄清楚您的着色器编译中是否有任何 GLErrors,您的着色器是否实际启用,您的 FBO 是否良好等等。在您发布之前,您可以做任何事情来缩小问题范围.
-
我已经为这个问题搜索了整整两个星期。我在每个编程论坛、Monogame 主网站和论坛上都进行了搜索,但没有找到解决方案。这是我的问题。我不知道问题出在哪里。我只知道着色器是问题所在。以及我如何称呼它。我在网上发现了许多类似的问题,但大多数问题没有得到解答,其他一些问题得到了答案,但这对我没有帮助......