Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

HDRP and Custom Render Textures

Discussion in 'High Definition Render Pipeline' started by CitronMaane, Apr 19, 2021.

  1. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    Hi!
    I was inspired by an old tweet by Klement Lozar where he were experimenting with quasi 3D Screen space smoke shaders. The method could be really powerful.

    I used the custom Render texture feature but i couldn't get it to work while using Shader graph.
    Then I found an older 2019 project, example of custom render textures made by Tim Neville. This project was made in LWRP. They used Shader Graph to make the shaders and i used this as a reference to create a shader that uses a Camera target Render Texture as a source and everything worked.

    Basically the setup is two shaders, one that adds the current RenderTexture to an aggregate of previous renders and one shader that reads the texture.

    You can modify first shader to get so many interesting results.

    I then tried to make a Shader Graph in my own project that is made in HDRP.
    But ran into problems - apparently Custom Render Textures don't work with Shader graph Shaders according to the documentation.

    Then later I found a forum post describing a workaround that didn't really make sense in turns of what Unity says; URP and HDRP does not work together but the workaround was to make the shader that generates the Texture based on URP. This surprisingly worked!
    Example01.gif
    Example02.gif
    Blue.png



    The reasoning seems to be the URP shader has a pass "Unnamed pass 0" that works with Custom Render Texture.

    Unfortunately this workaround breaks basic functionality such as the time node so I had to update a property with the total play time. This is of course not a proper method in terms of using the features in the proper way.
    upload_2021-4-19_10-47-12.png
    How would I go about implementing this method using HDRP in a proper way that does not include URP?
    It seems to be such a wild workaround.
     
    Last edited: Apr 19, 2021
  2. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Based on the testing and info I've gotten in past, I'm assuming CRTs just use built-in renderer to render the RT regardless if you use SRP for rest of the rendering.

    Since CRT's rendering doesn't require SRP related shaders, you can basically write CRT shaders just like before SRPs and they work. For example snippet from https://docs.unity3d.com/Manual/class-CustomRenderTexture.html should work just fine even if you use HDRP materials for displaying the generated CRT, you just can't use HDRP shaders to render to CRT itself.

    So basically you have two options here: either write the old style shaderlab code yourself that it compatible with CRT (refer to that doc page I just linked here) or use Amplify Shader Editor as it has separate CRT template that can be used to author CRT shaders.

    If you want to stick with Shader Graph, then there's no built-in option to author CRT compatible shaders while only using HDRP as like you've found out, none of the HDRP passes are compatible. This could potentially change in the future once Unity gets built-in target for shader graph as chances are that these passes could be CRT compatible (haven't tested myself).
     
    Last edited: Apr 19, 2021
    DylanF likes this.
  3. CitronMaane

    CitronMaane

    Joined:
    Nov 16, 2016
    Posts:
    15
    Thanks for the clarification.
    In the case of Klements implementation do you think it would be possible to use HDPR custom render passes to get similar results as using CRTs and if so would it there be any benefits to go in that route?

    Again thank you so much for the help!

    Edit: In any case i would still need to save the previous frames and modify them, but Custom passes can use HDRP shader graphs as well.
     
    Last edited: Apr 19, 2021
  4. TheGhost0

    TheGhost0

    Joined:
    Sep 11, 2017
    Posts:
    29
    ok how to fix it guys to make it work with camera and TV ?? i use HDRP last version from unity
     

    Attached Files:

  5. DylanF

    DylanF

    Joined:
    Jun 25, 2013
    Posts:
    55
    Thanks for the tips here. A shader made with amplify is working with custom render texture and hdrp for me. The wrinkle was that globals like time, and my own shader globals, didn't work (usually). Setting properties directly on the material worked though.
     
  6. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I'm pretty sure recent SG versions should have CRT graph already. So you don't need to use 3rd party solutions anymore.