Shader performance in custom vertex function

What are you guys experience with performance of doing calculation in here?

example:

  half3 distance = _WorldSpaceCameraPos - mul((half4x4)_Object2World, v.vertex);

// or

fixed2 offset = TransformViewToProjection(norm.xy);

The implementation of TransformViewToProjection can be found in UnityCG.cginc and looks like this:

inline float2 TransformViewToProjection (float2 v) {
    return mul((float2x2)UNITY_MATRIX_P, v);
}

inline float3 TransformViewToProjection (float3 v) {
    return mul((float3x3)UNITY_MATRIX_P, v);
}

So Iā€™d guess TransformViewToProjection(float2 v) should be the fastest variant, but without proper profiling, you never know.

Do you think precision really matter?

This most likely depends on the target platform.

2 Likes