Reputation: 12965
in metal shader implementation, it is recommended to use half4 instead of float4. but how to know if we can use half4 instead of float4? how to know the amount of precision we need ?
Upvotes: 3
Views: 1023
Reputation: 1
From : enter link description here A general rule of thumb is to start with half precision for everything except positions and texture coordinates. Only increase precision if half precision is not enough for some parts of the computation.
Upvotes: 0
Reputation: 122458
You know you can use half4
, instead of float4
, depending on how the colour is encoded as it's passed into the fragment shader.
Half-precision floats can represent the values 0 to 2048 exactly so if it's used to represent an 8-bit channel (i.e. pretty much all commonly-used texture formats) then there is no loss of fidelity.
It will also save memory transfer bandwidth, which is important on mobile platforms.
Upvotes: 4
Reputation: 10137
Based on this Metal Shading Language Specification
float:
A 32-bit floating-point. The float data type must conform to the IEEE 754 single precision storage format.
Full float precision is generally used for world space positions, texture coordinates, or scalar computations involving complex functions such as trigonometry or power/exponentiation.
half:
A 16-bit floating-point. The half data type must conform to the IEEE 754 binary16 storage format.
Half precision is useful for short vectors, directions, object space positions, high dynamic range colors.
Upvotes: 3