Search Unity

  1. How has 2019.2 and the beta been for you so far? Give us feedback in this thread.
    Dismiss Notice

HDRP Weapon shader?

Discussion in 'Graphics Experimental Previews' started by id0, Jun 14, 2018.

  1. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    270
    Is it possible to make a shader in HDRP that will be drawn on top of everything without second cameras and all that S*** (for weapon)? Because in legacy render it was impossible.
     
    hippocoder likes this.
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    I would like this but I do not know how to achieve it with current HDRP. I don't want to use multiple cameras for performance reasons.
     
    id0 likes this.
  3. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    499
    With the default pipeline you can do this with stencil buffer, we will have to wait for Shader Graph to support that or if you can add it to a version of the Lit shader yourself. I actually don't know if HDRP will have Stencil Buffer or if it's something else that's basically the same, we will have to wait and see.
     
  4. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,329
    Last edited: Jun 14, 2018
    id0 likes this.
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    I think that weapon rendering is such an integral and common feature that it MUST have native support. It's something Unity's competition has perfectly solved.

    We waited a decade for decals, lets not wait another decade for decent first person support in rendering :)
     
    Desoxi, thelebaron, id0 and 1 other person like this.
  6. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    I would like to know about this too, maybe we should summon Sebastien here so we can get a focused discussion about FPS rendering with SRP?
    ummm @SebLagarde mind to chime in?
     
    Last edited: Jul 6, 2018
  7. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,042
    Not sure what was meant by Unity's competition. UE4 doesn't support this but CryEngine does when using their legacy GameSDK (they haven't ported this over to new systems afaik). I'm sure many proprietary engines can do this but they really aren't Unity's competition as we can't access those. I'd like to add tho that this hack has really bothered me on many games, I'd always prefer if guns just moved away from walls instead of hacking the rendering to show impossible to have visuals, it just breaks the immersion and depth perception. To me, it's just feels like cheap hack to fix something that would take more effort to fix properly. I'm pretty sure this is also why engines like UE4 don't even try to solve this on rendering.

    There is one case where this makes more sense and it's when you are in a dense foliage, you can render the weapon on top of grass / bushes which isn't as disturbing than rendering the whole gun even when it's clipped into a brick wall.. But the foliage case can be solved otherwise too (bend the foliage out of the way).
     
    Flurgle and hippocoder like this.
  8. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    270
    The question was simple - it is possible or not. God, I just hate when someone pushes their opinion into the technical discussion.
     
    hippocoder likes this.
  9. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,042
    I gave people doing this alternative solutions (make guns dodge the wall, bend the foliage), I also mentioned that biggest Unity competitor doesn't do this either as it was presented here as (somewhat false) argument. In addition, I explained why this hack is technically bad (not just an opinion): it really messed up with depth perception with objects drawn in places where they can't be. But I can tell my input isn't appreciated here so I'll just unsubscribe from this thread. Don't expect any further help on your issues with that attitude :)

    PS. This is a discussion forum - opinions and discussion around the topic are both allowed as long as they don't offend others or derail it.
     
    Last edited: Jul 7, 2018
  10. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Yeah I already do that. I need to nudge it a bit further because when you move or rotate away as I do you're just displacing the problem, plus when enemies attack (game is mostly weapon based melee) they penetrate shields, so it's not just a gun vs wall problem.

    So I need a way to prioritise the drawing of objects in front of the camera a little, in addition to the measures I already take - doesn't need much but would make a nice difference.

    Seb Lagarde mentioned that I could reserve a range of depth but I'm not sure how to achieve that process.
     
  11. jjejj87

    jjejj87

    Joined:
    Feb 2, 2013
    Posts:
    261
    There was nothing technical about it. Also, I think he was just trying to help. If you are asking questions on the forum, perhaps you should appreciate the help first. If you hate that too, then don't ask for people's opinions. Go find out on your own.
     
    hippocoder likes this.
  12. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Yeah although I'm not hating anyone and would appreciate pointers eventually (whenever) :)
     
  13. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    478
    Could you just mess with the render order enough to force it into position? If you look at the gun/hands/etc material the order option should be in the material or mesh renderer section. Press yourself firmly up against the wall first to activate unwanted (wanted here?) clipping then go ham on the render order value/s.
     
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Unfortunately in my case, these are melee weapons that I've de-penetrated and rotated as far as I can already. It's just a polish pass though, to remove the final visual bugs really.

    All games experience some clipping but they're able to mask the final but with some nice tweaks to depth range or whatever, I do not currently know how that would be achieved in HDRP.
     
  15. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Any noise on this guys? Hate to bump but it's still an issue, thanks!
     
  16. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    i guess we wont' get an FPS renderer for now :(
     
  17. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,803
    Theres multilples ways to achieve this. Change the render queue value in your weapon material. Or add an additional pass to the render loop that will render weapons after everything else. Or as Sebastien suggested, reserve some depth range value for your weapon (make sure it has the higest values close to 1.0).
     
    Ryiah and hippocoder like this.
  18. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    How do I achieve the mentioned things? I do not know where to begin. My expertise with shaders very much ends around mobile vert/frag shaders. SRP is a lot of stuff I don't know how to alter yet :)
     
  19. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,803
    You are on HDRP right? I'll try to put out something today, just need to finish a hurry up commit and then I'll give it a go. :D
    PS: HDRP is really not meant to be altered, at least till it's finalized, lot of things changing within almost every day. Unless you wanna grow white hair quickly. ^^
     
    Ryiah and hippocoder like this.
  20. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    The white hair is coming, believe me. :D but yes - I can wait and you are right - I just wanted to make sure this sort of common thing is designed-for built in feature to avoid the decade or so of problems people had with it in older versions of Unity.
     
  21. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    sorry for being bit out of topic, i'm suddenly wondering long time ago unity have fps shooter demo with lerpz as main character, how do they handle the fps rendering back then, two camera?
     
  22. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Yeah ye old 2-cam trick... Thing is this is a problem for VR as well. In my game I have everything pretty physical in 3D space. So I can't do other subtle tricks like scaling the weapon smaller but bringing it closer to the camera to compensate. This would ruin the interaction with other characters.

    It's a trick that works well for overwatch I think, maybe (brigitte's melee).
     
  23. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    Lol i did use that scalling trick on mine, and yeah handling the interaction are the tricky part.
     
  24. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,042
    Thing is, the fake render will be really messed up in VR as you literally see the guns dimensions where your brain says it can't be.
     
  25. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    @tatoforever you mention "sebastien suggestion to reserve depth range" where did he explain about this one
    Edit : nvm i found the thread
     
  26. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    ...and how does one even do that? with graph or?
     
  27. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    Not sure yet, i'm still hasn't cracked this problem yet. All that cracked is my head :confused:
     
  28. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,803
    Hey Man,
    I totally forgot about you. Right now I'm like super loaded working on multiple stuff at the same time. :)
    As you probably find out, this problem is a tricky one, specially in VR. What I'm going to do is add an additional opaque pass to the HDRP loop.
     
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,803
    Follow up on the Weapon pass.
    I added a new custom Forward (only opaque) pass after default one to the HD render loop and it didn't do anything.
    I also added a custom depth pass after default one and again nothing changed.
    It's probably me being silly, i did that super quick. I'll give it an other go today and let you know how it goes. :D
     
    hippocoder likes this.
  30. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    How do you do that, if you don't mind i'm asking? it's just hdrp are bit confusing for me
     
  31. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,329
    Get ready to pull your hair out :D I certainly did while trying to figure out how to do what i did with the normal render (even with the limitations).
    Very interested to see if you can get something like this to work with HDRP. I've been wanting to try again, but i still haven't spent any time with HDRP.
     
  32. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    especially when hdrp are keep changing
     
  33. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    3,803
    @Reanimate_L
    Easycheesy, add the render passes to your custom rendering shaders, then add the rendering passes to the rendering loop. :)

    @eskovas
    I've been working intermittently with HDRP for a while now. It's not only hairy it's also quite advanced because it's state of the art rendering stuff. But if you understand how renderers in general works you can follow. The code is clean and well commented. :)

    Still I don't think HDRP is ready yet. The render loop creates huge garbages spikes, the API still evolving and new features are coming/improving. But it's getting there. ;)
     
    Last edited: Sep 24, 2018
    hippocoder, Reanimate_L and eskovas like this.
  34. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    @tatoforever isn't HDRP using built in render queue, which mean it is already predefined from 0-5000?
     
  35. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    I just found a DepthBiasZ setting in decal shader that make the decal rendered on top of everything. Might help
    @hippocoder @tatoforever
     
    Lahcene, eizenhorn and hippocoder like this.
  36. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Oh! hmmm....
     
  37. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    well i'll be damned, don't mind the shirt, it's still using built in HDRP material :p.
    But hand and the gun are rendered on top of everything now
    DepthBias.png
     
    hippocoder likes this.
  38. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,318
    But as you can see, lighting little incorrect :) upload_2018-10-19_14-48-24.png
     
  39. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    Yep, the depth buffer are broken, so the SSAO are broken in these shader. still doing some more tweak now
     
    hippocoder likes this.
  40. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    @hippocoder well i guess now you can just disect the FPS Sample demo then. Since there's an FPS Mode and FOV option on the HDRP Lit in it
     
    hippocoder likes this.
  41. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    I will simply thieve with wanton abandon.
     
  42. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,355
    and at this point i'm confused though, where the hell is this function running at
     
  43. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,329
    Ooooooo niiiiice!:) Finally an official solution for HDRP and seems to be working quite well.
    This will be game changer for FPSs with the new renderer.
    Will need to try this out more!
     
    hippocoder likes this.
  44. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,279
    Time to find a new line of business... :D
     
    eskovas likes this.
  45. eskovas

    eskovas

    Joined:
    Dec 2, 2009
    Posts:
    1,329
    Mine still works with default renderer, so its ok :) i have a new asset coming soon anyway ;)

    This new official solution is great for everyone, including me!
     
    Last edited: Oct 24, 2018
    hippocoder likes this.
  46. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    179
    Is there a reason the normal 2 camera setup is not good to use?
     
  47. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,042
    For one really good reason: it's removed in 4.2.0-preview SRPs and forwards. From 4.2.0-preview's changelog:
     
  48. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,380
    I had a quick test of this (by accident) and at the moment at least, you can still render a second camera to a rendertexture. I'm using it to do a replacement material rendering to a render texture for pixel perfect selection.

    Not that this will probably help much for this problem as only 1 camera will render to screen at a time now. Though maybe you could layer the render texture on top?
     
    Last edited: Nov 21, 2018
  49. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,042
    RT's are still supported as they should be, no modern game engine could do without.
     
  50. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    1,380
    I don't understand the graphics pipeline well, but what's the difference between rendering 2 cameras to the screen vs rendering 1 camera to the screen and 1 to a rendertexture and just rendering the render texture on top of the camera view?