This project is read-only.

Rendering outside of sunburn

Jul 11, 2012 at 9:53 PM

I want to render a skybox model outside of sunburn and before any other rendering is done. I cant figure out how to do this with an IGF project. Could anybody advise me where to but the render call?

I have tried it in my Game.Draw function before the base.Draw but it doesnt show and after the base.Draw renders it above everything else.

Ideally I would like to be able to do this from within my GameState. Is that possible?



Jul 12, 2012 at 1:10 AM
Edited Jul 12, 2012 at 1:18 AM

I do this myself. The way i have it implemented, is I have a Skybox class derived from IGF's Layer class. I then override the Draw() function to do my custom rendering, and add it with GameState.AddLayer(). Works like a charm.

For a skybox, there are a couple of very key elements to rememmber: First, make sure it's the FIRST layer you add, so it draws first. Second, if you don't want to have to worry about sizing the box appropriately, DISABLE the depthbuffer. This means other scene objects and such will draw on top of it regardless of how big the box is, and the box will draw over anything that might be left hanging around from last frame (except there shouldn't be anything).

Speaking for myself, I construct a box where the corners are 1,1,1 and -1,-1,-1. I pass the Projection matrix from my active camera, BUT I construct a new view matrix from the rotation of the camera's view *only* and use Matrix.Identity for the world. This yields an infinitely distant skybox that responds to camera rotation, without having to worry about annoying scale issues.

NOTE: if you do rendering outside of SunBurn(skybox or otherwise), make sure to include a using statement for Indiefreaks.Xna.Extensions and call Application.Graphics.GraphicsDevice.SamplerStates.Reset() after you're done with your drawing, or Bad Things Might Happen (especially in deferred mode).

Jul 12, 2012 at 10:24 AM

Fantastic thanks!

How do I disable the depth buffer and will I need to re-enable it in my main gamestate?

Do I do it like this:

depthState = new DepthStencilState();
depthState.DepthBufferEnable = false
Application.GraphicsDevice.DepthStencilState = depthState;

Do I need to disable the depth buffer before I render the sky box and enable it again after?



Jul 18, 2012 at 10:26 AM

That's how I do it, yes. Though I initialize my depthState object in the constructor so I only have to do it once. I haven't had any problems with not restoring the original depthstate, but I can't guarantee this is a good idea, so it's really up to you. I'm pretty sure that stuff gets reset fine, though.

Jul 19, 2012 at 11:10 PM

Awesome thanks!