Search Unity

FPS Sample Shader graph for weapon FOV not working?

Discussion in 'FPS.Sample Game' started by hippocoder, Oct 31, 2018.

  1. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    Hi,

    As we can't use the version of HDRP in the FPS sample it would be great to have the FOV adjustment as a shader graph. I tried and failed horribly and got into a strop big time. I even refused to give my cat a treat.

    Please could you demonstrate how we can do this effect in a graph? It seems wild that I'd have to replace the SRP to do it.......
     
    Mbot and Raive like this.
  2. Raive

    Raive

    Joined:
    Jan 6, 2013
    Posts:
    8
    I second this! I am developing an FPS and was very excited to see the FPS Sample handling the FOV, yet I can't (or don't know how to do it).

    I tried replacing the SRP as a test and it all went horribly wrong - a shader graph example or a LitFPS shader would be awesome.
     
    Mbot and hippocoder like this.
  3. Vestergaard

    Vestergaard

    Unity Technologies

    Joined:
    Oct 20, 2016
    Posts:
    25
    Mister-D, Raive and hippocoder like this.
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    Oh brilliant! thank you so much :)
     
  5. Raive

    Raive

    Joined:
    Jan 6, 2013
    Posts:
    8
    That is awesome and very much appreciated, thank you!
     
  6. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
  7. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    nevermind i updated shadergraph editor and the field of view works,
    is there a way to prevent the fps view models from clipping thru walls?
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    The FPS sample shrinks the gun.
     
  9. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    not in the shader right? what script should i look for in the sample? couldnt find it
     
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    I don't recall, I believe it's just scaled though.
     
  11. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    ok, will try different scales then. tnx

    edit

    scaling doesnt work , still clips thru walls. there should be a way in the shader graph to render the fps view shader on top of everything else.
     
    Last edited: Nov 3, 2018
  12. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,372
    @Vestergaard Just curious, why not also change the z value of the viewPos?
     
  13. Vestergaard

    Vestergaard

    Unity Technologies

    Joined:
    Oct 20, 2016
    Posts:
    25
    kind of funky with regards to screenspace effects based on depth, like our ssao, contact shadows etc. Try it out maybe it works for your use cases, but i didn't want to depend on it as i don't know what kind of depth traced / ray marched effects we might end up implementing down the line.
     
    hippocoder likes this.
  14. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    could u post a copy of just the shader that has the fps view toggle and explain were to paste it? couldnt find it anywhere. ended up copying the entire hdrpipeline package folder from the fpssample project.
     
  15. Vestergaard

    Vestergaard

    Unity Technologies

    Joined:
    Oct 20, 2016
    Posts:
    25
    The implementation is injected into 7 files, you can search our hdrp package for "_FPS_MODE"

    Search "_FPS_MODE" (7 hits in 7 files)
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Editor\Material\Lit\BaseLitUI.cs (1 hit)
    Line 523: CoreUtils.SetKeyword(material, "_FPS_MODE", fpsModeEnabled);
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\Material\LayeredLit\LayeredLit.shader (1 hit)
    Line 420: #pragma shader_feature _FPS_MODE
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\Material\LayeredLit\LayeredLitTessellation.shader (1 hit)
    Line 431: #pragma shader_feature _FPS_MODE
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\Material\Lit\Lit.shader (1 hit)
    Line 251: #pragma shader_feature _FPS_MODE
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\Material\Lit\LitTessellation.shader (1 hit)
    Line 260: #pragma shader_feature _FPS_MODE
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\RenderPipeline\ShaderPass\ShaderPassVelocity.hlsl (1 hit)
    Line 153: #if _FPS_MODE
    E:\P4\prototype01\main\ProjectFolder\Packages\com.unity.render-pipelines.high-definition\Runtime\RenderPipeline\ShaderPass\VertMesh.hlsl (1 hit)
     
  16. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    tnx man!
    is your team planning on making the shader not clip thru walls. there should be a way to render it after everything else.
    scaling the weapons works but not in every case. really liking your sample btw ;)
     
  17. Vestergaard

    Vestergaard

    Unity Technologies

    Joined:
    Oct 20, 2016
    Posts:
    25
    Even the new doom has some clipping, and uses this approach so for the near future do no expect us to do anything beyond this, as we concider it the best compromise for this title.

    As mentioned to completely avoid sorting issues you have to render it in a separate pass, which requires much more invasive changes to the hdrp to be performant and as we would like to be on stock hdrp next release this is not something that we can commit to maintaining, and not a solution I would recommend to any team that doesn't have the rendering prowess to implement and maintain themselves.
     
  18. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,515
    ok tnx for explaining,
    would be nice to have that fps view checkbox in the standard hdrp shader, just a thought
     
  19. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    5
    I must be an idiot because with the ShaderGraph shader, the FOV does NOT get changed and my weapon is now fully PINK. I am up to date with the latest ShaderGraph version but there's no way for me to select what base material (either color or texture) I want to use the ShaderGraph shader on...

    Can anyone explain? Shaders are not my forte and I'm really tired of having to search through HUNDREDS of posts about this dumb issue that should've been a feature within Unity for years now. If it's possible for people to "hack" their way through this in either materials or editing the way the ProjectionMatrix works, I don't see why this is not a standard feature to begin with. "Add this script or material to your weapon to have it be rendered in a different FOV so you don't have to use two camera's yaay"
     
  20. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    Any progress on this? TAA has artefacts with the weapon and hands model.
     
  21. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,159
    Pink means the shader isn't compiled properly. Open the Shader Graph for it and hit "Save Asset", it should recompile it for the version you have now. Also, you are using it on HDRP, right?