Search Unity

Standard shader - Unused property performance?

Discussion in 'Shaders' started by castor76, Aug 22, 2017.

  1. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I was wondering about the performance of Unity Standard shader if some of their properties are not used.

    So for example if I don't use an occlusion map or a height map, would standard shader uses variation of itself to be cheaper in terms of performance? Or does it just use a blank texture and their performance is the same no matter if I use them or not?

    Also, I was wondering if it would be worth while if I manually pack say an occlusion map into alpha channel of the emission map and then write a custom surface shader to read only emission map and then use alpha channel of it to assign to the occlusion? ( thus save performance on reading another texture map )
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    You should pack your texture data to the most efficient paradigm to fit your content. This is just standard operating procedure.

    The Standard shader does compile a lot of variants, but I am not sure how aggressive it is because I always do the above and avoid using the Standard stuff. Honestly, Unity naming the "Standard" shader "Standard" and not "PBR" has caused untold suffering because people think they should use the "Standard" thing...
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The Standard shader is quite aggressive in its variants. Nearly every single texture slot enables a different variant. The albedo and occlusion textures are the two that are always sampled no matter what.
     
  4. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It is aggressive in compiling variants which don't sample the textures which aren't used, but aggressively packing textures can also be a big performance win. Unity's packing favors pixel quality over speed- this is a reasonable choice to make. For instance, 2 channel maps (normal, smoothness/metallic) are packed into R/A textures to help with texture compression quality. These could all be packed into a single texture instead, which would save memory bandwidth and sample counts, but reduce the quality of the texture data substantially.

    This is because most texture compression formats consider the RGB channels to be a "perceptual color". When only one channel is used in the RGB data, there are only 256 possible color values, so the compression looks reasonably decent. But when you pack data into all 3 channels, the compressor now has 16 million colors to deal with, and treats the importance of those colors based on how our eyes see color (for instance, many formats give preference to green, since we see it better than other colors).

    So assuming we are using low-def compressed texture formats like DXT5, you can basically choose to pack more data into a single texture (faster) or pack only 2 channels into each non-color texture (slower, but better quality). If you are going to put data into the RGB channels and compress them, the green channel will have a slightly better quality than R and B (A is also high quality). And remember to keep your data linear.
     
    tomraegan likes this.