Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    37
    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:
    17
    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
     
  3. A132LW

    A132LW

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

    nikefootbag

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

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    37
    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. rz_0lento

    rz_0lento

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

    nikefootbag

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

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    1,965
    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:
    37
    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:
    37
    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.
  11. cr4y

    cr4y

    Joined:
    Jul 12, 2012
    Posts:
    41
    I had the same issue. It's clearly a bug in Unity, so I've reported it. Now you can vote for fixing it here!
     
  12. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    1,965
    No comment on Graphics.Blit but CRT definitely works on both URP and HDRP. This is relatively old thread but wanted to give some update now that the thread has been bumped. Basically URP Unlit and old style CRT shaders work as is on HDRP but it's challenging to get URP shader itself to HDRP as you need to have both URP and HDRP installed for this to work.

    You can still use old style CRT shaders as shown in official docs for CRT. If you want node graph shader for CRT you can use Amplify Shader Editor as it has special CRT support. This also works with HDRP.
     
    Ne0mega and A132LW like this.
  13. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    94
    If it helps anyone, CommandBuffer.Blit does work with shader graph shaders, at least in URP.
     
    oleg_v likes this.
  14. cr4y

    cr4y

    Joined:
    Jul 12, 2012
    Posts:
    41
    @rz_0lento What do you mean by "CRT shaders"? I don't recognize the term :(
    @Oxeren thanks for sharing this! How do you use it? Do you add the custom render pass? Maybe you would have some code to share, please?
     
  15. Oxeren

    Oxeren

    Joined:
    Aug 14, 2013
    Posts:
    94
    I've used it in scriptable renderer features/passes. Here is an example of a pass that uses it. Check out the rest of the repository to see how the pass is used in the scriptable renderer feature.
     
  16. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    1,965
    Ne0mega likes this.
unityunity