Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CustomRenderTextureVertexShader behaves strangely... looks broken

Discussion in 'Universal Render Pipeline' started by JonPQ, Jan 23, 2020.

  1. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    I am trying to checkout the custom render texture feature.
    in unity 2019.1.14f1
    basic unmodified LRWP
    simple, empty new project.
    No scripts except, rotate object.

    I have a rotating camera... with a second camera (cam2) facing backwards, it renders to a custom render texture.. which I put onto material 1
    then I put that material onto ui Image in top left of screen, rendered by main camera 1
    so far so good... main camera rotates... I have an image in top left that looks like a big mirror or creen showing me a rear view.

    now the trouble begins...
    I make a second material... with shader from unity manual... "CustomRenderTexture/Simple" . that should tint my render texture when applied to the custom render texture....

    instead... what I see is...
    for the material... an exploded, broken polygon preview in Inspector view... (it is tinted though)
    and if I try to apply that material to my Ui Image... it makes my image disappear in game view... and instead it replaces the entire background of the screen view window, with the broken, exploded(and tinted) polygon look. (see below)

    I've tried with and without double buffer checked on the render texture.
    Seems broken.

    any thoughts or ideas appreciated, thanks.

    expected.... but with purple tint in top left image...
    upload_2020-1-23_12-2-16.png

    Apply the CustomRender Material to the Ui Image at top left... this is the output...
    screen view's backdrop gets replaced... and the Ui image disappears

    upload_2020-1-23_12-4-59.png

    more info.... its replacing the skybox in the scene view.... if the (invisible) Ui image is off screen, the skybox is drawn normally. if the (invisible) ui image is on screen... the skybox turns into the tinted material.

    more info... it also looks like its rendering the terrain inside out on that second camera.
     
    Last edited: Jan 24, 2020
  2. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    If it helps others... found a couple of things wrong in the docs....
    I'm looking at 2019.1 and 2019.2 docs... here... https://docs.unity3d.com/2019.1/Documentation/Manual/class-CustomRenderTexture.html

    The unity docs provide 2 example shaders... both are borked ! ( maybe never tested ? )

    the first shader...
    has this line "#pragma vertex CustomRenderTextureVertexShader"
    which seems like it should maybe be "#pragma vertex InitCustomRenderTextureVertexShader"

    The second shader...
    has this line... " _Color * tex2D(_Tex, IN.texcoord.xy);"
    which should be "return _Color * tex2D(_Tex, IN.texcoord.xy);"

    Now the shader works and outputs expected tinted texture...
    renders ok in 3d and 2d ui
     
    Last edited: Jan 24, 2020
  3. JonPQ

    JonPQ

    Joined:
    Aug 10, 2016
    Posts:
    120
    working :)