How can I make a certain mesh not be affected by the far val
-
- Posts: 34
- Joined: Sat Jan 21, 2017 6:51 pm
- Location: Duckburg
- Contact:
How can I make a certain mesh not be affected by the far val
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
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.
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.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How can I make a certain mesh not be affected by the far
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.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How can I make a certain mesh not be affected by the far
@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?
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: How can I make a certain mesh not be affected by the far
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 .
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: How can I make a certain mesh not be affected by the far
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
Yeah, i skipped that part, the ZBuffer resolution normally gets scaled accordingly as well, bad idea.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?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt