Disable viewDistance mesh culling?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Ultraporing
Posts: 34
Joined: Tue Nov 06, 2007 7:22 pm
Location: Würzburg, Germany

Disable viewDistance mesh culling?

Post by Ultraporing »

Hello o/.
I'm currently trying to render a Solar System in which the player can walk on the planets and fly around in space.

I like to always draw the Sun in my scene regardless of its distance.
I already tried to set the Sun nodes Automatic culling to off but did not work.
here is the code:

Code: Select all

 
IMesh *mesh = smgr->addSphereMesh("Sun", 100000.0f, 64, 64);
    IMeshSceneNode *node = smgr->addMeshSceneNode(mesh);
    node->setMaterialTexture(0, driver->getTexture("sunmap2.jpg"));
    node->setMaterialFlag(EMF_LIGHTING, false);
    node->setMaterialFlag(EMF_TRILINEAR_FILTER, true);
    node->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
    node->setAutomaticCulling(EAC_OFF);
    video::SMaterial &matPlanet = node->getMaterial(0);
    matPlanet.AmbientColor = video::SColor(255, 0, 0, 0);
    matPlanet.DiffuseColor = video::SColor(0, 0, 0, 0);
    matPlanet.EmissiveColor = video::SColor(255, 255, 186, 21);
    matPlanet.MaterialTypeParam = 0.0035f;
    matPlanet.Lighting = true;
    matPlanet.NormalizeNormals = true;
 
If anyone could help it would be greatly appreciated. Thank you
CuteAlien
Admin
Posts: 10022
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Disable viewDistance mesh culling?

Post by CuteAlien »

It's probably clipped by the far-plane which you can set for the camera. But using so different scales that you can see things a few meters away as well a few million kilometers (or miles) away will need some workaround. The problem is that the z-buffer only has a certain depth and also Irrlicht only supports linear interpretation of the depth-values to my knowledge. So you could move the farplane so far out that the sun is visible... but then everything close by will have the same depth-value and so polygons inside that area will start draw on top of each other without knowing which one should be in front.

Simplest workaround - put the sun close-by and just scale it's size down :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
AReichl
Posts: 269
Joined: Wed Jul 13, 2011 2:34 pm

Re: Disable viewDistance mesh culling?

Post by AReichl »

I am thinking about the same problem (for my long awaited super-über-space-strategy-game which will never be finished).

Would this be possible? :

1: render two "scenes" with two cameras (which look the same way) with different near, far values.

2: "logarithmic depth buffer" (wouldn't know how to implement it in irrlicht; probably not only the depth buffer would have to be changed, but the whole engine).
Ultraporing
Posts: 34
Joined: Tue Nov 06, 2007 7:22 pm
Location: Würzburg, Germany

Re: Disable viewDistance mesh culling?

Post by Ultraporing »

CuteAlien wrote:It's probably clipped by the far-plane which you can set for the camera. But using so different scales that you can see things a few meters away as well a few million kilometers (or miles) away will need some workaround. The problem is that the z-buffer only has a certain depth and also Irrlicht only supports linear interpretation of the depth-values to my knowledge. So you could move the farplane so far out that the sun is visible... but then everything close by will have the same depth-value and so polygons inside that area will start draw on top of each other without knowing which one should be in front.

Simplest workaround - put the sun close-by and just scale it's size down :-)
Thanks for the tip, I already downscaled everything but the camera is way to big. How could I go about shrinking the camera so everything appears bigger? Because I like the player to be able to walk over the sphere (planet) which gets to a later date some proper terrain elevation.
I like the Planets to be like Kerbal space program or Shores of Hazeron. So I can fly with a ship from the planet surface to space and land on other planets. Thats why I initially did have giant planets.

If you guys got any ideas please let me know. Thanks
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Disable viewDistance mesh culling?

Post by hendu »

The camera has no "size". It is an illusion based on how fast you move.
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: Disable viewDistance mesh culling?

Post by Seven »

Could you use a second scene manager for just the sun?
CuteAlien
Admin
Posts: 10022
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Disable viewDistance mesh culling?

Post by CuteAlien »

@AReichl: Both solutions sound good to me. Using a second scenemanager for the sun which draws first and then resetting the z-buffer should work in theory as everything on the planet will be in front of the sun anyway. The logarithmic z-buffers would be another solution - those are also necessary when doing larger landscapes. Although not sure if that really works well with interplanetary scales (if the distances get too large you might at some point run into troubles again that the backside polygons of the sun are too close to it's front maybe, but I didn't do the math).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ultraporing
Posts: 34
Joined: Tue Nov 06, 2007 7:22 pm
Location: Würzburg, Germany

Re: Disable viewDistance mesh culling?

Post by Ultraporing »

Thank you, I like to try the solution with the second screenmanager.
Can please someone tell me how to do this? Last time I added a second screen manager and added the sun to it, it did not draw my sun (or just did not show it in my camera).
Sorry for being this annoying but the last time I used Irrlicht was 7 Years ago and I can't remember how to do it.
CuteAlien
Admin
Posts: 10022
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Disable viewDistance mesh culling?

Post by CuteAlien »

Untested, but probably like that:
1. create a new scenemanager with oldScenemanager->createNewSceneManager();
2. make certain both have a correctly placed camera and light (or no light materials)
3. You have to call beginScene and drawAll for both. First beginScene should clear both buffers (first 2 params true, true) before running drawAll and the stuff further away has to be in that scenemanager. Second beginScene does not clear the backbuffer but only the z-buffer (so first 2 params should be false,true). Call endScene just once.

I hope that works.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply