Im trying to render my fps gun on another layer using separate camera to prevent obstacles clipping. But i cant combine both cameras layers together. Only the last rendered camera’s layers are visible. Is it possible to achieve a desired result without post processing shader?
I know about option 1. Option 2 is what i have been using before . I’ve just seen some info that many fps games use separate camera for a gun to add more natural bobbing and sway effects. So i’ve thought that there’s any common solution for it.
Good, but will slightly reduce FPS due to calculations. While preserving the influence of light, shadows from walls, smoke.
Check the intersection of the ray from the weapon to objects. If there is an intersection, then turn the weapon to the left and down or pull it back. When firing, a turned weapon shoots to the side.
A pulled back weapon shoots straight and looks normal if it is a short weapon, but if it is a sniper rifle, it may look strange.
To reduce the amount of calculations, it is necessary to simplify and divide the surrounding geometry into sectors and check the calculations only in sectors close to the player.
Or create a copy of the scene in the webworker and check intersections there without breaking the geometry, but then the weapon may sometimes not have time to turn.
Good. While preserving the influence of light, shadows from walls, smoke. Make the weapon small and place it close to the camera so that it seems normal in size.
But when approaching, for example, a book, you can notice a discrepancy in the size of the weapon.
Good. With the preservation of the influence of light, shadows from the walls, but the weapon will always be on top of the smoke and the rest. Set gun.renderOrder=1; gun.material.depthTest=false;.
Bad, a second scene and copies of light are required. With the preservation of the influence of light, shadows from the walls, but the weapon will always be on top of the smoke and the rest.
The first layer is used to draw a scene without weapons, the second layer is used to draw the second scene with weapons, copies of light, but without smoke.
Since there are no walls in the second scene, the smoke would always be visible, even if in the first scene it was behind the wall.
To preserve the correct influence of light and shadows, you need to disable automatic shadow update before drawing the second layer, and then enable it again after drawing.
At the very beginning, we copy the light from the first scene to the second scene like this: scene_2.children.push(ambientLight,directionalLight,pointLight);
Add a gun to the second scene: scene_2.add(gun);
Layer rendering code:
renderer.autoClear=false;
renderer.clear();
renderer.render(scene,camera);
renderer.clearDepth()
renderer.render(scene_2,camera);