Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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...
    Click image for larger version  Name:	Fov.jpg Views:	1 Size:	289.6 KB ID:	1434150

    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

    Last edited by Ruhton; 02-24-2018, 03:55 PM. Reason: Update

    #2
    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:
    https://blueprintue.com/blueprint/agmtf9vr/
    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:
    Click image for larger version  Name:	Script.jpg Views:	1 Size:	196.1 KB ID:	1434191
    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:
    Click image for larger version  Name:	Script2.jpg Views:	1 Size:	180.9 KB ID:	1434192
    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
    Last edited by Ruhton; 02-24-2018, 03:47 PM.

    Comment


      #3
      Sorry, where do you apply this exactly?

      Comment


        #4
        Originally posted by Mootjuh View Post
        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

        Comment


          #5
          Thanks for this
          Dev Blog
          Twitter: @TheRealSpoonDog
          150 FREE Blueprint functions for your project

          Comment


            #6
            Thank you so much for sharing your solution!

            Comment


              #7
              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!

              Comment


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

                Comment


                  #9
                  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.




                  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.
                  Last edited by ImaginaryBlend; 10-16-2018, 08:04 AM.
                  Fast Stylized Procedural Sky
                  Anime Toon Shading
                  SDF Robo Progress Bars
                  Aquatic Surface

                  Comment


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

                    Comment


                      #11
                      Originally posted by ImaginaryBlend View Post
                      I’m going to explain step by step how it works in the article on my site very soon.
                      Is this still online somewhere?

                      [Marketplace] Loading Screen System (ᴘʀᴏᴘᴇʀ ʟᴏᴀᴅɪɴɢ sᴄʀᴇᴇɴs, ɴᴏᴡ ᴡɪᴛʜ ᴘʀᴏɢʀᴇss ʙᴀʀs)
                      [Free][Script] Automate Download of Mixamo Animations
                      [VłĐɆØ] Performance: BP vs C++ vs Blueprint Nativization

                      Comment


                        #12
                        Originally posted by Cpt.Trips View Post
                        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
                        Fast Stylized Procedural Sky
                        Anime Toon Shading
                        SDF Robo Progress Bars
                        Aquatic Surface

                        Comment

                        Working...
                        X