Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. 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

Bug Bug in secondary texture sampling in srp batch using sprite atlas and tilemaps

Discussion in '2023.2 Beta' started by xtytyx, Sep 20, 2023.

  1. xtytyx

    xtytyx

    Joined:
    Dec 29, 2017
    Posts:
    24
    I have a project which i have reported a bug on in unity 2023.1 but it exists in all versions of unity 2023, still present in this beta
    Basically I have submitted a bug with a project with a shader, 2 tilemaps set to individual and a sprite atlas containing secondary textures and regular textures.
    Here is the id: IN-53330

    In the case where the tilemaps are set to individual OR srp batch, it is unable to sample the secondary texture any srp batch seemingly on a different rendering layer or within a different z level or as the child of a separate tilemap after the first.
    Here is a demonstration of how the secondary texture is sampled correctly in scene mode and sampled correctly in chunk mode while both other modes in play mode cause it to lose the secondary texture.

    I believe this has to do with srp batching not working correctly with secondary textures across multiple batches within a draw call.


    The frame debugger sees both the main texture and the mask texture, it is just the sample that fails to hit the mask texture in the second batch

    batch 1 of frame 1 where there IS the secondary sampled properly texture (you can tell by the yellow color)
    upload_2023-9-19_19-26-10.png
    batch 2 of frame 2 with the missing secondary texture (you can tell because its white)
    upload_2023-9-19_19-27-6.png

    and finally here is the fragment shader (its built off the urp 2d sprites default, i removed all extra custom logic)
    Code (CSharp):
    1. half4 CombinedShapeLightFragment(Varyings i) : SV_Target
    2.                 {
    3.                     half4 main = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv );
    4.                     half4 secondary = SAMPLE_TEXTURE2D(_MaskTex, sampler_MaskTex, i.uv);
    5.                     //im doing this to visualize the secondary texture not sampling properly
    6.                     main = ((secondary + main) /2);
    7.                     SurfaceData2D surfaceData;
    8.                     InputData2D inputData;
    9.                     InitializeSurfaceData(main.rgb, main.a, secondary, surfaceData);
    10.                     InitializeInputData(i.uv, i.lightingUV, inputData);
    11.                     return CombinedShapeLightShared(surfaceData, inputData);
    12.                 }
     
    Last edited: Sep 23, 2023