Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Canvas issues with materials

Discussion in 'Getting Started' started by epistax, May 27, 2024.

  1. epistax

    epistax

    Joined:
    May 23, 2024
    Posts:
    11
    Hello! I'm quite new but I've done a lot of looking around for documentation / other people reaching out for a similar issue but I have come up empty.

    I'm using URP, editor is 2022.3. If I create a canvas and apply it to a particular camera (any camera, really), and then set a RawImage with a material, I get an visual effect where the screen becomes two colors. There is a diagonal line from the lower left corner to the upper right corner. Above the line the camera is bright, and below the line the camera is darker. For the material, I started by creating a full screen shader. I create a color node, give it a color and connect it to the fragment. I set the alpha of the fragment down to 0.5. I then create a material from this shader.

    Oddly enough I had to follow those instructions above twice to reproduce the issue. There is some non-determinism in the shader creation that I can't wrap my head around. For example if I diff the generated code from a couple of shaders (which to me should be identical) I see one has "Blend Off" set, and another has "Blend SrcAlpha One, One One" set in the "Render State" section. I cannot relate this to anything I can find in the inspector. Another oddity is that I can't add anything to the "Fragment" without it being disabled, even if I connect something to it. If I remove the default "Base Color(3)" I cannot add it back. I can find it in the list but the UI won't let me actually add it. Also no matter the alpha I set right now, the canvas is completely opaque. Working on that.

    What I am actually trying to do is intentionally induce noise in a camera. I was able to do this successfully by using noise generation (and even got it to animate) but I then I noticed the diagonal line and it really started to bug me. It's present on all cameras, and disabling any/all of the various lighting and other things doesn't seem to make a difference.

    Since I'm so new, I'm guessing that I am going about things the wrong way. I could find nothing on learn.unity about canvases. Even the UI Components lesson which explicitly mentions in the summary does not cover it. I have been able to create a canvas group and canvas to place text over the cameras on demand from C# so I don't think I'm completely lost :)

    Thanks for any pointers.
     
  2. influjensbahr

    influjensbahr

    Joined:
    Aug 31, 2015
    Posts:
    47
    Hi! Could you maybe post screenshots or a video of your problem? It's quite hard to imagine what's going on with just a text description :)
     
  3. epistax

    epistax

    Joined:
    May 23, 2024
    Posts:
    11
    This is a RawImage with a RenderCamera set to a particular camera. One thing that is odd is that the closer I set the plane distance, the more other things in the scene will cover the canvas. Seems opposite to me. I have this in the UI layer.
    upload_2024-5-28_7-0-35.png
    I am using a flat material as a test case until I can figure out the issue. The material was created off of a simple full screen shader. (Shader Graph -> URP -> Fullsreen shader graph). What I am expecting to see is a consistent hue applied across the screen. not with a different apparent alpha in the top left versus the bottom right.

    So one more time I have
    Full screen shader graph to create material
    Material applied to a canvas
    Canvas Renderer is set with a particular Render camera
    When the canvas is enabled and I use that camera, I see this diagonal line. i.e. disabling the canvas shows:
    upload_2024-5-28_7-12-41.png

    I removed any post processing to make sure I was just seeing the effect of this one canvas. I can remove directional lighting and still see the same effect.

    Thanks for any tips!