Categories

RealKo Engine (Journal diary of working in progress)

Everyone, I want to tell you that I have solved the problem now.

For what I have done is simple, draw particle scene on top of the deferred scene as Shawn said.
Also the external scene like particle scene in this case involves with the depth buffer, thus like MJP said, we must be aware when using all of these stuffs with XNA as the framework might tries to reset everything (I guess as I have worked on it, as if our rendering system is complex enough that requires many render targets, and we must switch between them, this might be the case that the framework tries to reset the buffer automatically. We will not face this behavior if our rendering system is just one draw call that everything is contained in it.). So we should do at most everything we can control like clearing the buffer, etc.

This is the step-pass I used
1. Prepare all the render tagets, ready for Deferred shading process.
2. Set our custom depth buffer (just to be matched in format with the depth render target used in deferred shading process) to graphics device.
3. *Clear the depth buffer to 1.0f.
4. Draw the deferred scene.
5. Unset all the render targets used in deferred shading scene.
6. Set our original depth buffer to graphics device.
7. Draw the particle scene. But remember to set our custom depth buffer to graphics device again.
8. Set back the original depth buffer to grpahics device.

*If we miss the step 6 and 7, the framework will suggest use the depth buffer which is not for us, so everything will not be as our expect.

See the following code, cut from my DeferredShadingRenderer class,

///
        /// Prepare the deferred rendering process.
        ///
        /// Draw part will be handled by the outside.
        ///
 
        public void BeginDraw(GameTime gameTime)
        {
            //set the proper depth-test function
            graphicsDevice.RenderState.DepthBufferFunction = CompareFunction.LessEqual; 
 
            //set render targets
            SetGBuffer(); 
 
            //cache the current depth buffer
            old = graphicsDevice.DepthStencilBuffer;
            //set our custom depth buffer
            graphicsDevice.DepthStencilBuffer = depthBuffer; 
 
            //clear render targets
            ClearGBuffer(); 
 
            //clear out our depth buffer
            graphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Black, 1.0f, 1);
        }

And another one.

        ///
        /// End the deferred rendering process.
        /// In fact, end draw will finish the deferred rendering pass by drawing the lights, and draw scene with or without bloom post-processing.
        ///
        /// Draw part will be handled by the outside.
        ///
 
        public void EndDraw(GameTime gameTime)
        { 
 
            //resolve all render targets
            ResolveGBufer(); 
 
            //set the depth buffer back to old one
            graphicsDevice.DepthStencilBuffer = old; 
 
            //draw all lights
            DrawLights(gameTime); 
 
            //draw on top of the result from lighting target
            graphicsDevice.SetRenderTarget(0, combinedLightRt); 
 
            //set to use our custome depth buffer
            graphicsDevice.DepthStencilBuffer = depthBuffer; 
 
            //Note: All the particle systems should be drawed after all the solid objects are drawed. This is quite important as the particle itself
            //can be able to pass the depth-test.
            //draw the particle system
            //TODO: Add any related functionality into this drawing section of particle systems.
            if (ParticleSystemsManager.NumberOfParticleSystem > 0)
            {
                //traverse all the particle system
                foreach (ParticleSystem p in ParticleSystemsManager.ParticleSystems)
                {
                    //draw
                    p.Draw(gameTime);
                }
            }
            //ENDTODO 
 
            graphicsDevice.SetRenderTarget(0, null); 
 
            //set the depth buffer back to old one
            graphicsDevice.DepthStencilBuffer = old; 
 
            //draw the bloom applied, or just normal scene
            if(isBloomApplied)
                DrawPostProcessing(gameTime);
            else
                DrawNormalScene(gameTime);
        }

As you see above, I have 2 methods to be used in drawing process. Other scenes will be drawed in between those 2 methods.
Hope this will clear out some points.

The last word as I learned from this exprerience => DO NOT INVOLVE ALPHA BLENDING STUFF DURING DEFERRED SHADING PROCESS.

Thanks Shawn, and MJP for your great help that can point me to this final clue.

And this is the result.

Alpha in deferred fixed

Alpha in deferred fixed

Note: You can see similar post, that I have posted out in creator clubs here.

2 comments to RealKo Engine (Journal diary of working in progress)

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">