Search Unity

Cheaper optimisations for my shader?

Discussion in 'Shaders' started by LukasO, Mar 18, 2016.

  1. LukasO

    LukasO

    Joined:
    May 23, 2013
    Posts:
    115
    I've made a shader which was edited from Unity's toon shader. I wondered if there's any suggestions anybody has for optimisations as I know the shader will need to be run on Mobile. I know I'm using a pow() operation which I'd like to remove and some Matrix multiplication.

    Shader code below:

    Code (CSharp):
    1.             v2f vert (appdata v)
    2.             {
    3.                 v2f o;
    4.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    5.                 fixed3 worldPos = mul(_Object2World, v.vertex);
    6.                 o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    7.                 fixed3 dir = normalize(_PlayerPos - worldPos);
    8.                 fixed3 worldNormal = mul(_Object2World, fixed4(v.normal, 0.0)).xyz;
    9.                 o.cubeTexCoord = dot(dir, worldNormal);
    10.                 return o;
    11.             }
    Those operations are basically used so I can define a point in the scene for a "light" and have any objects using this shader considered to be "lit" if the vert being checked is facing towards the "light".