Page 1 of 1

How can I make a certain mesh not be affected by the far val

Posted: Wed Nov 29, 2017 12:48 pm
by Donald Duck
In my program, I want to set the far value for the camera at 20 (using irr::scene::ICameraSceneNode::setFarValue(20)), so that no element farther than 20 units from the camera is visible. But I don't want all elements that far from the camera to be invisible, but all except one. So I have one element approximately 3000 units from the camera that should be visible all the time, and all other elements that should only be visible when they're 20 units or closer to the camera. Is there a way I can do this?

Re: How can I make a certain mesh not be affected by the far

Posted: Wed Nov 29, 2017 4:48 pm
by CuteAlien
Not with near-far values. That's a camera-settings describing the frustum which your camera does see.
There's probably a few solution to this (like working with shaders). One idea which popped into my head and is completely untested (so might or might not work):
- Render far away mesh to a rendertarget texture.
- Put that texture on a quad with has a distance of 20 and show it there.
- Render rest (everything behind that quad will be clipped now by the quad).

Another similar solution, which probably needs Irrlicht trunk (I think 1.9 didn't have clearBuffers yet).
- Render far away mesh
- Call clearBuffers with ECBF_DEPTH and calculate the depth value which 20 would have. It's probably about the ratio which 20 units have compared to the distance of near to far plane. Value-range for depth-buffer is probably 0-1 (not sure and also don't know if 0 or 1 is the near, also not 100% certain if the buffer is really linear you might have to google a little bit for that one).
- Render the rest (clipping basically same as above except you cleared z-buffers instead of using some pseudo-object to set the z-buffer values).

So basically the idea is both times the same - you set z-buffer values to a certain distance after rendering your first mesh.

Re: How can I make a certain mesh not be affected by the far

Posted: Thu Nov 30, 2017 1:53 am
by Mel
Using a lighting manager you can change the camera settings prior to the rendering of any node and restore them later. Take a look at the lighting manager example.

Re: How can I make a certain mesh not be affected by the far

Posted: Thu Nov 30, 2017 10:33 am
by CuteAlien
@Mel: Hm, yeah, but not quite sure what happens in that case. If you have a far-value with long range first and then one with short range and they still use the same z-buffer. I guess then you can suddenly have things close by be behind objects far away?

Re: How can I make a certain mesh not be affected by the far

Posted: Fri Dec 01, 2017 9:46 am
by devsh
in OpenGL you can temporarily set glEnable(GL_DEPTH_CLAMP) but beware... the stuff beyond your camera far value will have no Z-Buffer depth testing... so your meshes better be convex or they will be 'flattened' and z-fight .

Re: How can I make a certain mesh not be affected by the far

Posted: Sat Dec 02, 2017 6:53 am
by chronologicaldot
I think you could just implement ILightManager and implement OnNodePreRender() and OnNodePostRender(). For each node, you would check its distance from the camera and turn off its visibility in OnNodePreRender() if it's too far and then back on again in OnNodePostRender(), which is called after the rendering. You don't need to mess with the camera at all - just get its position and use that for distance checks.

Re: How can I make a certain mesh not be affected by the far

Posted: Sat Dec 02, 2017 12:18 pm
by Mel
CuteAlien wrote:@Mel: Hm, yeah, but not quite sure what happens in that case. If you have a far-value with long range first and then one with short range and they still use the same z-buffer. I guess then you can suddenly have things close by be behind objects far away?
Yeah, i skipped that part, the ZBuffer resolution normally gets scaled accordingly as well, bad idea.