Far Clipping Plane & exceptions

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Saturn7_dev
Posts: 9
Joined: Sun Sep 24, 2023 5:48 am

Far Clipping Plane & exceptions

Post by Saturn7_dev »

I want to make use of the camera far clipping plane to reduce large terrain drawing distance yet also have exemptions to override any clipping like very distant planets and sun mesh using a 3D plane - so keep them rendered always within the view frustum.

I am using the fixed function pipeline as default.

Can this be done ? and if so how ?

I tried per material to switch off culling for transparent materials (for planet and sun etc) and back on but once switched off would not come back again for solid materials (SetRenderState(D3DRS_CLIPPING,TRUE/FALSE) - even when adding as true in the unset material section.

The last post mentioned if the material was rendered through HLSL then clipping would not occur - is that right ?
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Far Clipping Plane & exceptions

Post by CuteAlien »

It sounds like a problem of render ordering. The problem with transparent materials is that they are drawn last - and you want the distant stuff to draw first.

One trick I sometimes use is having more than one scenemanager. In your case you can put large distance stuff in a second scenemanager and draw all objects in that one first. Then clear the depth buffer (but not anything else) and draw the other scene with stuff closer by.
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
Rusty Rooster
Posts: 14
Joined: Thu May 24, 2018 6:43 pm
Location: USA

Re: Far Clipping Plane & exceptions

Post by Rusty Rooster »

The last post mentioned if the material was rendered through HLSL then clipping would not occur - is that right ?
Actually, it’s just a matter of setting the clipping distance in the vertex shader. Then you can do anything you want in terms of clipping.
Saturn7_dev
Posts: 9
Joined: Sun Sep 24, 2023 5:48 am

Re: Far Clipping Plane & exceptions

Post by Saturn7_dev »

Thanks for the responses - I do prefer to keep all material as FFP however instead of creating a new transparent material in HLSL.

I noticed the skybox and skydome are not clipped as they are drawn before most other things as counted in the ESNRP_SKY_BOX render pass - I thought that this might be this issue actually and was wondering how do I add existing 3d mesh to be drawn as part of this render pass instead ?

I tried using: SceneManager->registerNodeForRendering(node, scene::ESNRP_SKY_BOX); but it seems that when rendering it is trying to run the render code that is suited to the skybox and not the code needed for the actual 3d mesh is that right ?
(I'm not fully sure how the void CFlaceMeshSceneNode::render() part works - yes, this is CopperCube)

I added a new section within the CFlaceMeshSceneNode class to segregate non clipped mesh and try and render them while its in the skybox pass
bool isSkyBoxPass = SceneManager->getSceneNodeRenderPass() == scene::ESNRP_SKY_BOX;
but this didn't work for some reason...

what code would I need to run a separate scene manager for the selected items ?
can you suggest any code snippets at all ?
CuteAlien
Admin
Posts: 9746
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Far Clipping Plane & exceptions

Post by CuteAlien »

Yeah, using ESNRP_SKY_BOX more or less also affects the order. One problem is that it doesn't work with CMeshSceneNode which uses that pass for shadow volumes. But the other is that it still writes to the z-buffer (depth buffer). And if you want to ensure stuff is in the background - you want to reset the z-buffer afterwards so all later things are drawn in the front. You could do that by using own scenenodes and then reset in between with a light-manager, but that's unnecessarily complicated.

Second scenemanger is easy: createNewSceneManager can create a new one from the first one you have (function in ISceneManager). Then just add the far away nodes into that one. And render them both with drawAll() with those with the far away nodes first. And in between the 2 drawAll calls you do a driver->clearBuffers call. Parameters depend on if you use 1.8 or trunk. With trunk it should be driver->clearBuffers(ECBF_DEPTH);
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