I want to render the weapons of an FPS game using a separate camera.
I want that because it allows me to control the FOV independently when rendering the weapon which is important to me.
I hope to get some feedback from EPIC, I suppose you guys have thought of solutions to this problem but I’m also interested to get recommendation from everyone else.
Having no accurate shadows or light conditions on the gun is not a big issue to me as long as it isn’t very noticeable so I’m really open to all propositions even if it requires creating approximations of light condition.
If you see in the blueprints game example for the FPS look under the player and you will notice how the cameras are set up. Simply notice how that worked out and you will understand how you want your camera set up to just render a weapon and not the arms, etc. Hope this helped you out. Also read under documentation on setting up cameras, cheers.
Thank you , I might not have described the problem well enough and I think you misunderstood my question.
When I meant rendering the weapon separately, I meant the arms+weapon on one camera and the world on another camera.
In the shooter game there is currently only 1 camera and the way it works is not the problem.
I’m interested to know how I can render the weapon separately in an optimised way to then layer it on top of the world view.
I’m hoping UE4 has a magic bullet for this particular problem, Unreal having a long history with FPS games.
AFAIK not currently supported or possible. A similar issue is that weapons clip into geometry when you stand close to a wall. I believe the background/foreground layers are not yet in but planned for the future (like UE3).
There is a rendering sort priority I THINK but that’s a C++ thing, the best way to avoid weapon clipping through geometry (IMO) is to use an overlap collision on the weapon and enable the player character to ‘move’ the weapon out of the geometry via animation. Gears of War did this for each game in the series I believe, though I’m yet to see an example of it set up in UE4.
In fact, this would be a great C++ Animation tutorial (hint hint epic games). I believe it’s done with blends and IK’s
This is fairly easy. Create a SceneCapture2D in front of your weapon at desired FOV, render the object to a RenderTexture2D, then render this texture with a Canvas DrawMaterial call using a material that masks the background color.
I recommend making the changes suggested above in the linked thread. If you want to be lazy though, you can move your weapon and camera to a far out location such as high in the sky where nothing else will be rendered in the view due to culling.
I have been struggling with a gamma/tonemapping issue when using DrawMaterial (emissive/unlit) instead of DrawTexture though. For some reason it renders the rendertarget much darker. I tried to do an inverse pow 2.2 thinking it just needed to be converted to linear space, but it was still slightly wrong. I toggled force linear gamma and no difference. I don’t know what is fundamentally different between DrawTexture that can’t be replicated with DrawMaterial.
So is a RenderTexture2D the recommended way to do this? Sounds like more of a hackish way imo. So many FPS games render the weapon separately that I’m surprised UE4 doesn’t have some form of support for this other than hijacking the render pipeline, which I’m guessing most people do not have the capacity to do.
Quite the bump… but there isn’t really any need to do it, and render targets are extremely expensive and have far too many artefacts to be useable. Scale the FPP meshes down until they fit inside the character capsule, that will stop any intersection with level geometry, and since the meshes are based around the camera it’s unnoticeable.
We do this in HLL (see sig), and we also “reproject” the first-person meshes with a special material function plugged into WPO. This allows us to keep the scene FOV and the first-person mesh FOV separate. I believe there’s even a marketplace asset that can do this for you now.
The gist of it is you use a material to distort the vertex based on a type of projection. You can also use this to shift the vertices back towards the camera when coming into contact with walls to prevent some clipping.
average render cost of a render target with just the hands and weapon would probably be around 2ms or so. Really depends on resolution and other render parameters. However, you will pretty much never be able to compose the 2 results at a convincing resolution and without lag/stutter because of how the render target works.
it takes time to render and, write, and even more time to read what’s been written into something.
thus, shifting the vertices of the mesh and weapon via a function is much easier on performance and on quality of the final result.