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

Question Optimization question(s) : Alpha clipping and Texture atlases

Discussion in 'General Graphics' started by rob11, Aug 5, 2022.

  1. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    59
    Hey ! I have two questions regarding Texture atlases :

    1- When making my texture atlases to optimize my game scenes, my intuition always made me group Cutout foliage (Alpha clip) with opaque (Without alpha clip). My thought process was that having 1 texture atlases instead of 2 would be better for performance, but I wonder what are the performance cost of toggling alpha clipping for objects that don't need it.

    Is it (most of the time), better to separate cutout shaders from diffuse shaders ? Is there any clues as to when they should be separate and when they should be batched together?

    2- According to my current understanding, empty spaces in texture atlases are wasted space and other textures can be scaled up basically for free if it doesn't change the total size of the atlas. I know it would increase the compressed size of the atlas, but is there any other performance cost in having a single texture take up more space in an atlas ? Image below to illustrate :

    upload_2022-8-5_12-16-3.png
    If I were to add a texture to this atlas, is there any extra performance cost to have it take 1024x1024 (green square) compared to the 512x512 size (red square)

    Thank you for your time and answers !
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    651
    1 - GPUs can't use the early-z optimization when alpha testing is used. You can combine them in the same atlas, but you shouldn't use the same draw call for both alpha tested and opaque geometry.

    2 - Theoretically, the GPU has to read more texels which increases the required VRAM bandwidth but that's most likely negligible.

    As always with performance - measure, measure, measure ;)
     
    rob11 and DevDunk like this.
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    What code monkey said

    I also want to add that some tiles GPUs (mobile) perform better with a transparent material instead of one with opaque with alpha clipping. Might be interesting to know
     
    rob11 and c0d3_m0nk3y like this.
  4. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    59
    Thank you both for your input, very appreciated and enlightening.
    Very ! I am actually targeting mobile so I'll be looking into this, I always assumed alpha clipping was always cheaper.
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    It's because with alpha clipping a pixel can't always be certain to be rendered by the material or something. Google could explain better. Alpha cutout is the only way to use cutout shadow casting tho
     
    rob11 likes this.
  6. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    59
    I've been thinking about this sentence you said. You say that I can, but should I or does it matter ? I believe the main gain of atlas is reducing draw calls, so if I were to put everything in a single atlas but use 2 different shaders, wouldn't I have absolutely no gain?
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    Basically if you use the same material across different meshes they can be batched together with dynamic batching.
    Texture atlassing helps with this, since you can use 1 texture for the 1 material.

    Atlassing also saves GPU bandwidth, since it has to load 1 texture and keep that in memory instead of loading in and out textures constantly
     
  8. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    59
    Alright, so even if I use multiple materials, I save GPU bandwidth if I use a single atlas for my whole scene, for example. I only ever made atlas for dynamic batching (so 1 batch 1 texture), as you mentionned in the first part of your reply. I did not know I would be saving GPU bandwidth by grouping textures outsides of batches. (Example : 2 batches 1 texture).