Search Unity

Resolved Graphics.Blit with Shadergraph

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

  1. A132LW

    A132LW

    Joined:
    Jun 21, 2017
    Posts:
    17
    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:
    7
    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:
    17
    Thank you so much! This is exactly what I was looking for.
     
    nikefootbag likes this.
  4. nikefootbag

    nikefootbag

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

    A132LW

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