I’ve spent some time on R&D focused on resolving a few important problems with FPP weapon/hands in UE4. A material node that I’ve implemented is an (I believe better) alternative to commonly used “Panini projection” node known from Unreal Tournament project.
Problems that my node solves:
1. Lack of separate weapon Field Of View (weapon stretching)
Standard solution “Panini projection”: Bad stretching, no control over the field of view, animators can’t see the result. Not clear license terms (Unreal Tournament source).
Standard solution Separate render pass for weapon layer: Requires engine modifications and can be slow/problematic with AA.
My reprojection: Node calculates the vertex offset as a difference between the mesh projected on the screen with in-game camera FOV and the weapon FOV. The result is unprojected into in-game camera space. It means that weapon mesh is stretched in axes X and Y to look like rendered in another FOV. In comparison to “Panini projection” mesh stays in the same shape independently of camera FOV.
Tradeoff:
Shadow mapping can be little inaccurate on the weapon.
2. Weapon render depth priority (environment clipping)
Standard solution: render weapon to additional stencil buffer/separate pass and render during post-process to prevent intersection. Slow and requires stencil buffer that should be used for a higher purpose.
My solution: scale the depth of mesh vertexes in the camera space – you decide how flat your weapon will be to not intersects with the environment. Mesh looks the same on the screen.
Tradeoff:
DOF will probably not work properly on the weapon.
3. Near plane clipping
Standard solutions: change the near plane value (UE4 don’t give this functionality), it can cause another problem with calculation precision and z-fighting
My solution: just move vehicles in front/back of the camera
4. The transition between the weapon FOV and the world FOV
My solution: Additional blend parameter that can be changed dependently on distance from the camera.
Right now I have a proof of concept and my method works correctly in UE4 so I’ve decided to show the results applied onto First Person Template.
The material is very fast and works on mobile without any additional changes. I’m going to explain step by step how it works in the article on my site very soon. Full implementation with examples will be available as a material package in the marketplace too 🙂
Documentation :
http://imaginaryblend.com/2018/10/16/weapon-fov/
Unreal Marketplace :
https://www.unrealengine.com/marketplace/weapon-fov
Features:
- Separate weapon FOV – You can set a custom field of view per weapon. Fixes the weapon stretching when changing the game FOV. Useful for calibrating weapon size on the screen independently to the camera.
- Weapon depth priority – Weapon scale in camera Z axis (depth). This feature fixes the intersection of weapons with walls. Player capsule radius can be smaller and the weapons can be rendered over the environment.
- Near plane clipping – Modify the near clip plane to see more/less of mesh in the camera.
- Weapon transform – Applies a custom position of the weapon in camera space.
- Effect blending – Implements transition between FOV space and world space. Useful for projectiles and character body that is standing on the ground.
- Material node – Can be customized per weapon or controlled in global material parameter collection.
- Clean implementation – Calculated per-vertex, very fast no need to use separate pass to fix problems with a weapon.
- Zooming effect – Change the camera fov when weapon stays the same. That makes scope zoom effect really easy to implement.
- NEW! Realistic sniper scope – Multiple parameters: lens refraction, aberration, overlays ect.