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

**URL:** <https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [February 23, 2018, 9:31pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976 "2018-02-23T21:31:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8204e96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8204e96](https://forums.unrealengine.com/u/anonymous_user_a8204e96)\
**Post date:** [February 23, 2018, 9:31pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/1 "2018-02-23T21:31:05Z")

</div>

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

 ![Fov.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/d/9/d9745a79efb37ba3267418985178e9936e7b4acc.jpeg)

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 😕

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8204e96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8204e96](https://forums.unrealengine.com/u/anonymous_user_a8204e96)\
**Post date:** [February 24, 2018, 5:09pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/2 "2018-02-24T17:09:12Z")

</div>

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:

> **[Panini Projection script from UT posted by Bhaid | blueprintUE | PasteBin For...](https://blueprintue.com/blueprint/agmtf9vr/)**
>
> No description provided

Theres lots of math there, Im not sure what all of it does but it works 🙂  
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:

 ![Script.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/4/1/4155c1a1e6d6b4833e6963eb7dcf166c107cb503.jpeg)  
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:

 ![Script2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/1/21bc653eb8b6e8efd20ec05f752d6e1b17982eb1.jpeg)  
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

---

<div class="post-metadata">

**Author:** ![HiIAmMoot](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HiIAmMoot](https://forums.unrealengine.com/u/HiIAmMoot)\
**Post date:** [February 24, 2018, 10:21pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/3 "2018-02-24T22:21:06Z")

</div>

Sorry, where do you apply this exactly?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a8204e96](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a8204e96](https://forums.unrealengine.com/u/anonymous_user_a8204e96)\
**Post date:** [February 24, 2018, 10:32pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/4 "2018-02-24T22:32:53Z")

</div>

> [@Mootjuh](#):
>
> 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

---

<div class="post-metadata">

**Author:** ![Spoondog](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spoondog](https://forums.unrealengine.com/u/Spoondog)\
**Post date:** [July 16, 2018, 8:38pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/5 "2018-07-16T20:38:06Z")

</div>

Thanks for this 🙂

---

<div class="post-metadata">

**Author:** ![Nerdsbeware](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/nerdsbeware/32/897578_2.png) [@Nerdsbeware](https://forums.unrealengine.com/u/Nerdsbeware)\
**Post date:** [July 17, 2018, 12:02pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/6 "2018-07-17T12:02:53Z")

</div>

Thank you so much for sharing your solution!

---

<div class="post-metadata">

**Author:** ![Rezulux](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rezulux](https://forums.unrealengine.com/u/Rezulux)\
**Post date:** [July 19, 2018, 2:49am UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/7 "2018-07-19T02:49:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![WinterLanternPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WinterLanternPro](https://forums.unrealengine.com/u/WinterLanternPro)\
**Post date:** [September 5, 2018, 8:52pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/8 "2018-09-05T20:52:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ImaginaryBlend](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ImaginaryBlend](https://forums.unrealengine.com/u/ImaginaryBlend)\
**Post date:** [October 16, 2018, 11:57am UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/9 "2018-10-16T11:57:43Z")

</div>

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

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/d/9/cd9c1d72fa6ee3b7634bac2074f257b4374cf715.jpeg "FPP/FPS Weapon FOV Experiments") ](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.

---

<div class="post-metadata">

**Author:** ![Ryan1111x](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ryan1111x](https://forums.unrealengine.com/u/Ryan1111x)\
**Post date:** [October 19, 2019, 5:04pm UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/10 "2019-10-19T17:04:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cpt.Trips](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Cpt.Trips](https://forums.unrealengine.com/u/Cpt.Trips)\
**Post date:** [May 26, 2020, 1:11am UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/11 "2020-05-26T01:11:18Z")

</div>

> [@ImaginaryBlend](#):
>
> I’m going to explain step by step how it works in the article on my site very soon.

Is this still online somewhere?

---

<div class="post-metadata">

**Author:** ![ImaginaryBlend](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ImaginaryBlend](https://forums.unrealengine.com/u/ImaginaryBlend)\
**Post date:** [May 29, 2020, 11:20am UTC](https://forums.unrealengine.com/t/how-to-implement-panini-projection-for-first-person-weapon-separate-fov-for-weapon/106976/12 "2020-05-29T11:20:25Z")

</div>

> [@Cpt.Trips](#):
>
> 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](https://www.unrealengine.com/marketplace/en-US/product/weapon-fov)
