着色器在 Monogame 中不起作用(有着色器看起来没有)| C#
Shader doesnt work in Monogame (With shader it looks like without) | C#
所以我有以下问题:
我想在我的游戏中有一个漂亮的绽放效果。但是当我尝试使用我的着色器和 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调用方法的摘录class:
/// <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");
}
您的 sprite 批量渲染应该在 bloom.BeginDraw
和 bloom.Draw
之间。
bloom.BeginDraw
绑定 sceneRenderTarget
你应该渲染你的场景。通过这种方式,可以访问渲染数据以在 bloom.Draw
.
中进行进一步处理
所以我有以下问题:
我想在我的游戏中有一个漂亮的绽放效果。但是当我尝试使用我的着色器和 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调用方法的摘录class:
/// <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");
}
您的 sprite 批量渲染应该在 bloom.BeginDraw
和 bloom.Draw
之间。
bloom.BeginDraw
绑定 sceneRenderTarget
你应该渲染你的场景。通过这种方式,可以访问渲染数据以在 bloom.Draw
.