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

Shader variable types do's and don'ts

Discussion in 'PSM' started by NFeelone, Jan 21, 2015.

  1. NFeelone

    NFeelone

    Joined:
    Oct 25, 2014
    Posts:
    3
    The official PowerVR documentation says that you have to use float, everywhere, where it's possible to make operation without convertion.
    But i found a post , where you can see a clear example the clear example, that sometimes it's better to use another type, then float

    So I ask to share some expirience about using variable types in shaders, who already do dosens of "what if"
     
  2. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Hi,

    First of all - the post you refer to doesn't seem to account for the TBDR architecture of PowerVR.
    Drawing overlapping opaque quads will result in the GPU discarding non-visible quads, and that will skew the numbers.

    More over - using fixed4 can sometimes be a bad idea performance-wise (especially with regards to swizzling).
    In fact - HLSLSupport.cginc (part of the global includes shipped with Unity) will redefine fixed to half for non-GLSL/non-PSSL (i.e. also for PSM).

    And finally - converting between precision formats can be costly (i.e. mixing half and float).

    Some additional tips can be found here : http://docs.unity3d.com/Manual/SL-ShaderPerformance.html