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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Weird custom Shader behaviour with Entities Graphics + URP

Discussion in 'Graphics for ECS' started by madks13, Jun 28, 2023.

  1. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    Hello, i am using Unity 2022.3.2f1 with ECS and URP. I created a new project with the 3D URP template, then adding Entities Graphics package.

    I have a scene with a Main camera, a virtual camera (cinemachine) following my player character entity object. The player character is a quad in the subscene with a plane used as background.

    The player character uses a custom graph made with Shader Graph and has GPU instancing enabled.
    The same goes for the background entity.
    I did set Forward+ in the URP settings as the Editor warned me about.

    The weird behaviour is that While the background is enabled, i can see the player character in the editor, even when i am in play mode.

    However when i tried it in build and run, i only saw the background. I then tried to find out why this was happening and when i tried disabling the background, so i can only see the player character, the player character became invisible too.

    If i change the player character material to a simple Unlit/Lit shader it shows fine. Even in build and run mode.
    I don't know what would be needed for the analysis, so i uploaded the shaders that seem to be the problem in a zip file.

    I have no idea why this is happening. Can anyone help please?
     

    Attached Files:

  2. mingwai

    mingwai

    Small Graphics Potato Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    52
    Hi, which platform did you build on?
     
  3. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    Hello, i am working with windows 10 pro. I do update windows and drivers when available.
     
  4. mingwai

    mingwai

    Small Graphics Potato Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    52
    I don't spot anything weird from your shader graphs. Also GPU instancing checkbox doesn't matter as SRP shader uses SRP batcher (if you didn't turn off SRP batcher) and if the object is in subscene, they will always use DOTS instancing.

    Does the issue happen if you move the objects out of subscene? Just wanna check if GameObjects are behaving the same.
     
  5. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    So, if i simply move the Entity with the MainChar shader outside the subscene, it disappears when i disable the background that is still inside the subscene. The same happens if i move the background outside the subscene.
    Weirder still, i simply created a quad in the scene (not the subscene) and changed the material to my material with the shader and nothing shows up on the game camera although i see the object in the scene view...

    Edit : should i just zip the whole project and upload it here?
    Edit 2 : I checked in the settings and the batcher is enabled on all 3 modes? (high fidelity, performance and balanced)
     
    Last edited: Jun 28, 2023
  6. mingwai

    mingwai

    Small Graphics Potato Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    52
    Yes that would be great if you don't mind.
     
  7. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    Ok, so the whole project folder was huge, so i excluded Visual Studio stuff, Library and obj folders that iirc are generated by Unity. If i missed something please tell me.
     

    Attached Files:

    mingwai likes this.
  8. mingwai

    mingwai

    Small Graphics Potato Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    52
    Ok, so the player is not visible when the background is disabled is because the player material is doing AlphaClipping.
    On the MainChar material, Surface Type is set to Transparent, therefore in render queue it should set to Transparent (3000), so that it doesn't need to care if background has a depth value.
    Or you can set Surface Type to Opaque and render queue AlphaTest (2450).

    upload_2023-6-29_14-24-30.png
     
  9. madks13

    madks13

    Joined:
    May 8, 2016
    Posts:
    173
    OMG, that worked. I am sorry, i am a beginner at graphics and wasn't aware that for transparency i had to change the render queue accordingly.

    That is the solution to my problem. Thank you.
     
    mingwai likes this.