HomeAbout inludoServicesGamesClientsDevelopmentsForumContact usHomeMail inludo


Unfogged objects behind fogging:


Download the source here.

Intro:
Fogging is great. It's a cheap effect that can hide a multitude of sins. It can give some kind of atmosphere (fog to black for night, fog to grey for mist, fog to red for fire etc. etc.) and it's a great friend of world culling - you simply don't draw anything further away than the far fog plane.
Problem is, quite often you want some kind of background, something behind the far fog plane. If you've tried this with D8.5 - you'll know there's no way of disabling fogging on a per model basis. You either have fogging in your scene or you don't. That's it. No refunds available.
Ah! Backdrops to the rescue! Except not, they are rubbish. Only a plane, minimal control. Just a bit crap really.
Before you lose all hope, read on.

Method:

This solution uses the #_nodepth flag. Basically you create your background model first, and make sure it is smaller than the near plane of the fog (IE so when drawn it won't get affected by fogging), and set it to use the #_nodepth flag. By being created first this model is processed first according to the order in the scenegraph.
Then you draw the rest of your scene as normal.
Making the object smaller than the near plane means it doesn't get fogged.
Creating the object first means it's guaranteed to be the first model rendered by the scene graph.
Using the #_nodepth flag means that after it's drawn the Z buffer doesn't know of it's existance, so all models rendered afterwards will render correctly.

Note that, using this method, you must be careful using functions that relate to distance and position of models. EG if using modelsUnderLoc() or modelsUnderRay() make sure you check results for this skybox, and ignore if found.

Note also that because drawing the background model does not use the Z buffer, only convex shapes are guaranteed to draw properly, because only convex shapes are guaranteed to have non-intersecting faces (from a visual point of view). Therefore, it helps to keep your background model something simple like a sphre, dome, box or cylinder etc.

In Practice:
To achieve this effect you must set up things in a certain order::

  • Create your background model first.
    For my demo, I'm using my skysphere model. Initialise as normal, just make sure it's the first model added to your world.
  • Set the model to not read or write into the Z buffer.
    Set your model's visibility to use #_nodepth.
    This is not a ne property, but a set of undocumented additions to a model's visibility property. You set this by adding _nodepth to whatever the model's current visibility setting is now. IE:

    #front becomes #front_nodepth
    #back becomes #back_nodepth
    #both becomes #both_nodepth

    So you'd set it by doing:

    tModel.visibility = tNoDepthVisibility

    where tNoDepthVisibility is one of the #_nodepth variations on the standard visibility as detailed above.

 

Development
Screenshots
Demos
Tutorials