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

Get scale in fragment shader

Discussion in 'Shaders' started by grahnzz, Aug 25, 2015.

  1. grahnzz

    grahnzz

    Joined:
    May 7, 2013
    Posts:
    46
    Right now I'm using a property that i set via Material.SetFloat(), but this is not optimal as it breaks batching so... how would i get the scale?
     
  2. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    You can pack it in the vertex properties (one would typically pack it into vertex colour), or derive it from one of the vertex properties (i.e. some calculation based on the position).

    But don't worry about over-optimizing draw calls too much unless you know it's actually a bottle neck. Extra draw calls aren't the end of the world especially on PC or with the newer mobile APIs. The GPU still has to run all the shader code even if you pack it into a single draw call. If you're already GPU bound, packing more work into the vertex shader to make all your geometry batch won't improve performance.