Search Unity

Failing to write the most basic shader. Any help appriciated.

Discussion in 'Graphics for ECS' started by Knedlo, Jun 2, 2021.

  1. Knedlo

    Knedlo

    Joined:
    Oct 15, 2012
    Posts:
    54
    Hello,
    I am trying to write a simple shader for Hybrid v2, but I can't get batching to work properly. All my instances are rendered with the same properties including position (entity debugger shows they differ as intended).

    I am using:
    Unity 2020.3.5f1
    Universal RP 10.5.0
    Hybrid Renderer 0.11.0-preview.44

    I an writing a shader by hand instead of using ShaderGraph because I want to use geometry shader and in general put a lot of logic into the shader itself which should be easier in coder rather than with graph editing. Also the whole thing will be unlit, so very simple from that point of view.

    As a base for my shader I took this: https://docs.unity3d.com/Packages/c...0/manual/writing-shaders-urp-unlit-color.html however this already doesn't work.

    Now I can get hybrid to work fine and use properties passed through components using ShaderGraph authored Lit shader (it doesn't work with Unlit, but that's a known bug that is scheduled to be fixed in 10.6.0.). In this working version I see multiple entities rendered at their positions with their other passed properties as expected. However using a shader written by hand, all entities (using that shader) are rendered on top of each other. I am pretty sure I am missing some instancing related code to make it work properly. Does anyone know how a super simple hand written shader that batches well should look like?

    I was trying to decode that from the working generated ShaderGraph shader, but it's quite a mess and I wasn't able to get anything usefull out of it yet.

    Cheers
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    Knedlo likes this.
  3. Knedlo

    Knedlo

    Joined:
    Oct 15, 2012
    Posts:
    54
    Thanks a lot @JussiKnuuttila ,

    I was even looking through that repo, but found only the folder with shader graphs. Should've looked better.

    Anyway it works like a charm!
     
    JussiKnuuttila likes this.