My camera has a far clip of 300. I want certain entities to be always drawn no matter of the camera far clip. So i tried:
disabling the cull on the render.meshinstances but it seems to not have any effect. The entity still gets culled from the far clip distance.
setting things in the materials like disabling depth test or depth write. But that did not lead to any positive outcome.
What helped me so far is:
Having two cameras with different far clip distances and two different drawing layers. Drawing the object in both layers. Setting the render order so that the camera that has the higher far clip is rendered first (+clear color & depth buffer) and then the maincamera is rendered where color & depth buffer is not cleared. The main camera has all other layers like world, UI etc.
The downside here is that i have two times the amount of draw calls for the same entity. because i need to have it in both layers to be rendered somewhat correctly.
The only other option i assume is one camera with a high render distance, but enable/disable the entities based on the distance to the player/camera. Something similar to LODs.
Does anyone have any advice, similar problems or possible solutions for me?
The only other option i assume is one camera with a high render distance, but enable/disable the entities based on the distance to the player/camera. Something similar to LODs.
This seems like the easiest option.
As you realised, the two camera set up has different depth between them, and so don’t compose well together. You could fix this by a more hacky solution. Specify the same culling far distance for both cameras, but override the frustum for one camera, so that it removes object after your other distance.
The first one does change the projMat permanently, which leads to different depth values and not a correct image.
The second one did unfortunately nothing. (the idea was to update the proj matrix, then calc/update the frustum and then go back to the original proj matrix).
At the end i figured out that i always want to have the distant objects rendered by the distant camera with the higher far plane in the background (always behind main camera). So i just have to clear the depth buffer also in the main camera, so everything gets rendered above the distant camera. Also the priority of main camera must be lower than distant camera. Then i only needed to switch the skybox to the distant camera instead of the main camera and it looks kind of good for my purpose in combination with the fog. This also opens up having two entities of the same object, and putting one with lower lod into the distant camera layer.
In your code, you overwrite data in projMat. Do not do that, but allocate a temporary matrix and use that, so that’s only used for frustum, but nothing else.