Camera frustum, what does changing this affect?


I have a nice gun, which is only 1 meter long in real life, in my game it was 20 WU (and I use 1WU=1meter), so I scaled it, but because the camera near frustum it cut off 3/4 of the gun. So I changed the camera frustum (devided all by 10). Now it seems like it works.
Is this a good way? Does this affect anything else?(I also changed ALL the frustums, near, far, top,left…) . Is my render distance still the same? Does this change the LOD or something?
I tried to search on the internet, but by my English isnt that good…
Any nice math links or something?

Thank you in advance :smile:

I have thought about how to do this for a while and it turns out it is quite complicated to get a fully working solution that is also efficient and correct.

Here’s the solution I came up with:

  1. Create a pre viewport containing the weapon. The weapon should write to the stencil buffer and set the value to 1. So anywhere the weapon is, it is set to 1, the rest is set to 0. Since you’re writing to the stencil buffer now, you have to enable clearing it for the pre viewport and disable clearing it for the main viewport.
  2. For the main viewport, you now have a stencil buffer with values that indicates where the weapon is. You will need to render the rest of the scene with stencil test turned on and test that it does not equal 1. This will only render the scene into pixels where the weapon is not, thus saving precious GPU cycles.
  3. Now you can render the actual weapon, you will need to create a post view containing it and render it normally. You will need to clear the depth buffer here (but nothing else) and use a camera with different near / far values.

You may want to share the same lighting setup as from the main scene. There’s a weird trick of doing this is by sharing a root node but only have specific subnodes of it render in the viewports.

Then you attach your lights to the root node and they would be properly propagated to both the weapon and scene subnodes.

For starters, you can skip the stencil buffer parts and just do step #3, then if that part is working you can add the optimizations in step #1 and #2.


  1. create a second viewport with weapon, I have that, enable clearing stencil, view.setClearFlags(false, true, TRUE); for the second
    viewPort.setClearStencil(FALSE); for the main
    How to write to the stencil buffer.

2)how to enable stencil test? and how to test it?
3) if Im right i cleared the depth with above setclearflags. making a second camera, following exatly the normal camera movement, and move the gun. But with different frustum

Or am i doing something totally wrong…

For starters do #3, but yeah, thats correct.