0

So i have following problem :

I wanna have a nice bloom effect in my game. But when i try to use my shader and the shader.draw(); method is called it looks unchanged ... It looks like i wouldnt use a shader. Also when i change shader parameters nothing changes . I can set BloomThreshold to 10000f and it looks like 0f or 1f ... Im a total noob to shaders so i would be really glad for some help !

Left with shader, right without shader:

enter image description here

This is my draw loop:

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);
}

This is an excerpt of the called methods of my 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");

    }

The full classes and shader code can be found here

LJᛃ
  • 7,655
  • 2
  • 24
  • 35
genaray
  • 1,080
  • 1
  • 9
  • 30
  • 1
    Downvoted because the question itself doesn't contain any code and answering is impossible without viewing external link that can stop working in the future. – SurvivalMachine Sep 18 '16 at 12:18
  • 1
    Well, a link is better than nothing. If posting code into the question, it doesn't have be the whole project, just relevant parts. – SurvivalMachine Sep 18 '16 at 13:05
  • Ja and thats the problem ... There are 3 Shaders, and 4 Classes ... And all those are relevant . I would be very happy when you could undo the downvote :/ – genaray Sep 18 '16 at 14:03
  • Narrow down your problem to a small part of the code. If you don't know how: figure out if you have any GLErrors in the compilation of your shader, whether your shader is actually enabled, whether your FBO's are good, etc. Any thing you can to narrow down the problem before you post here. – TWT Sep 18 '16 at 15:19
  • Im already searching two whole weeks for the problem. I searched in every programming forum, on the Monogame Main Website and there Forum and didnt found a solution. And heres my problem. I dont know wheres the problem. I Only know that the shader is the problem. And how i call it . I found many similar questions in the web but the most ones werent answered and some others got an answer but that didnt helped me ... – genaray Sep 18 '16 at 15:23
  • Contrary to the popular and incorrect advice, [mcve]. Also check out [ask] –  Sep 21 '16 at 03:21

1 Answers1

1

Your sprite batch rendering should be between bloom.BeginDraw and bloom.Draw.

bloom.BeginDraw binds the sceneRenderTarget you're supposed to render you scene to. This way the rendered data is accessible for further processing done in bloom.Draw.

LJᛃ
  • 7,655
  • 2
  • 24
  • 35