Search Unity

Help Wanted Graphics.Blit with HDRP Shadergraph

Discussion in 'Shader Graph' started by A132LW, Aug 8, 2019.

  1. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    34
    As MR-Heavy originally asked on the shadergraph thread - with no answer as far as I know:

    "Is it any good way to force "Graphics.Blit(Texture2D, RenderTexture, Material); " work with shader graph's unlit shader?"


    @MR-Heavy, have you found a solution yet? I tried wyatttt 's method and got your results.

    @wyatttt, do you have any more ideas?


    All suggestions are appreciated.
    HDRP and Shadergraph on 6.9.1 in 2019.2.0b9. Can upgrade if necessary.
     
  2. nikefootbag

    nikefootbag

    Joined:
    Jun 13, 2017
    Posts:
    14
    I'm not sure if this is related to the issue I had with Graphics.Blit not working, but in the end I used Unity's CustomRenderTexture to get shadergraph to write to a texture.

    To elaborate, I was making a Snow Track shader for car wheels, and was using one shader graph to paint to a texture(aka splatmap) based on wheel positions, then another shader graph to read from that texture and displace the snow.

    The Custom Render Texture takes in a material that uses the ShaderGraph you're wanting to blit with. You can then use that Custom Render Texture as an input to another ShaderGraph (in my case, a Snow Displacement Shadergraph).

    On the Custom Render Texture, you can set it's updateMode to "OnDemand", and tell it to Update whenever you would call Graphics.Blit.

    In my case of SnowTracks, this would be each fixed update frame, raycasting wheel positions then sending those positions to the CustomRenderTexture DrawTracks shadergraph, which updates the RenderTexture and is then used to the SnowTracks Displacement shadergraph.

    I uploaded the project to github also: https://github.com/tim-neville/Snow-Tracks-ShaderGraph-Unity-2019.1

    Snap.png

    Snap2.png
     
    iSinner and A132LW like this.
  3. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    34
    Thank you so much! This is exactly what I was looking for.
     
    nikefootbag likes this.
  4. nikefootbag

    nikefootbag

    Joined:
    Jun 13, 2017
    Posts:
    14
    No problem, glad I could help!
     
  5. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    34
    So, for some reason, the HDRP unlit shadergraph, as well as any other material created by the default HDRP shaders, fails to update a custom render texture.
    This is probably due to these specifications:

    The only mandatory steps when writing a shader for a custom texture are:

    * #include “UnityCustomRenderTexture.cginc”

    • Use the provided Vertex Shader
      CustomRenderTextureVertexShader

    • Use the provided input structure v2f_customrendertexture for the pixel shader

    When I use the example custom render texture shader; however, the render texture works perfectly.

    Thank you for the help. I will ask around to see if someone has a workaround.
     
  6. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,282
  7. nikefootbag

    nikefootbag

    Joined:
    Jun 13, 2017
    Posts:
    14
    @rizu Yes they're free to use, I just added the MIT licence to the repo aswell for clarity. Thanks for asking!
     
    rizu likes this.
  8. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    1,282
    You can use regular (nonHDRP) unlit shadergraph with HDRP. I quickly ported nikefootbag's sample to HDRP by just changing the SRP asset to HDRP asset from graphics settings, swapping the regular shaders to HDRP/Lit and recompiled/resaved the unlit shadergraphs used for drawing the tracks (didn't port them to HDRP unlit at all).

    Just to clarify this: those regular shadergraphs are all compatible with HDRP, you can think them as generic/universal graphs that work on both SRP pipelines, only HDRP shadergraphs are specific to one SRP.
     
    A132LW likes this.
  9. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    34
    Thank you rizu. Since nikefootbag's solution did not work in my HDRP-based project, I had incorrectly assumed that HDRP did not yet work with custom render textures. I have tried with the unlit (non-HDRP specific) shadergraph as well - so it must be an issue with my project.
     
  10. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    34
    Update: Custom render textures only work with LWRP, not HDRP, unless both packages are installed in the same project and the unlit master node is used.
     
    zyzyx likes this.
unityunity