Search Unity

Optimising using normalisation Cubemaps

Discussion in 'Shaders' started by brianasu, Aug 20, 2013.

  1. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Is doing a cubemap lookup to normalise vectors much cheaper than doing a texcube sample on iOS? I haven't seen anyone really implement that type of shader.

    I know doing a specular lookup doing a ramp texture is quite a bit cheaper.
     
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    I'd say you should always prefer ALU ops over texture lookups, but then I'm not so sure about mobiles. I guess the best way is to try it out.
     
  3. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Yeah just being a bit lazy:) I always thought normalise() was pretty expensive to use in the fragment shader.
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    I suspect it will be cheaper to use normalize(). Otherwise you're doing an indirect texture fetch on the cubemap and I don't think mobile hardware copes fantastically well with those.

    Only way to find out is to try ;)
     
  5. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    normalize() seems to be implemented as rsqrt(dot(v,v)) * v. rsqrt() is quite fast since it's just an approximation. So I wouldn't worry about it.
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I don't understand what the difference is between these two concepts.
     
  7. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Sorry I meant normalising a vector using a cubemap lookup:) or using the normalise cg function.
     
  8. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Would it still be an indirect texture fetch? I'm just re-normalising vectors that aren't normalised anymore because of the texture interpolators from vertex -> fragment?

    It just basically

    fixed4 frag(v2f i) : COLOR
    {

    fixed3 normalisedVector = texCUBE(_NormalisationCubeMap, i.normal); // i.normal is not normalised anymore

    ....do some other pizzaz

    }
     
  9. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Ah, I don't think it's indirect if it's the value straight from v2f that you use as the UV coords.

    I still don't think it'd be faster than
    i.normal = normalize(i.normal);

    But why not try it?