How to implement panini projection for first-person weapon? (separate FOV for weapon)

Update: I figured out how to do it!
I will soon post here how to do it for those who might be interested…

Original post:
I have read that UT uses this to render FP weapon model with different fov than the world fov and I want to achieve this as well for my project. I googled about this and did not really find how to exactly do it. I know that this requires something to do with World Position Offset but I have never used this before, I did download the UT editor and browsed their material implementations but they are rather difficult to understand :confused:

Can anyone who has used this show how its done with a simple material?
I would greatly appreciate it :slight_smile:

3 Likes

Here is how to do it,
You need 2 material functions and a material, this one I copied from UT and uploaded to blueprintue for easy copy/paste:

Theres lots of math there, Im not sure what all of it does but it works :slight_smile:
Dont forget to tick Expose to Library from settings (click background and on the sidepanel) to be able to use the functions in other bps

The second is simpler:


Here mf_PaniProjecti is the first function and it gets its inputs here, for GetMaterialAttributes and SetMaterialAttributes need to add the WorldPositionOffset pin in details panel

Finally example material:


Here mf_CustomShader is the function above, to use this MakeMaterialAttributes u need to tick the Use Material Attributes from the material’s settings

U can then create material instances from this to apply it for all materials in FP models

Sorry, where do you apply this exactly?

On the materials that are used on first person weapon. For example if u have a metal, wood and skin material on first person model then u would apply the shader on all of those materials, it basically makes the textures render differently on the camera from what I understood

Thanks for this :slight_smile:

Thank you so much for sharing your solution!

This is a great implementation of the Panini Projection shader, although it seems the math might be slightly off? At the default values and around 105-115 fov, the viewmodel seems to be at its furthest out, while an fov outside of that range causes the viewmodel to be pushed closer and closer depending on how great of a difference there is. This shouldn’t be an issue with games that restrict the fov to a standard range (70 and 140 fov result in around the same appearance, and the viewmodel isn’t affected all that much), though it would be nice to have a bit more consistency no matter your fov!

Is there any word from Epic if we’re allowed to use the UT panini MF in our games?

I’ve spent some time doing 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 Panini projection node known from Unreal Tournament project.

https://www.youtube.com/watch?v=OpE0UypSzng

Problems that my node solves:

1. Lack of separate weapon Field Of View (weapon stretching)

“Panini Projection”: Bad stretching, no control over the field of view, animators can’t see the result in editors. Not clear license terms (Unreal Tournament source).
Separate render pass for weapon layer: Requires a lot of engine modifications.

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 projected into in-game camera space. It means that weapon mesh is stretched in axes X and Y to look like rendered in another FOV. 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: Clear depth and render weapon in a separate pass to prevent intersection. Requires engine modifications.

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.
  • The intersections are possible but rare

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.

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.

I added this part to it, this allows Left/Right, Up/Down to be controlled manually as well.

Is this still online somewhere?

Yes, you can buy my Weapon FOV implementation in the marketplace and it’s 30%OFF now:
https://www.unrealengine.com/marketp…uct/weapon-fov