I have no particular expertise in graphics programming, so when writing shaders I apply knowledge that I’ve picked up from various books/websites, together with intuition around general coding best practice, which suggests:
- You should always use the smallest datatype capable of representing the precision and range of a given variable. Colours and unit length vectors can use fixed, for other variables prefer fixed over half, and half over float.
- You should avoid converting values between types if possible.
- Particularly on mobile, applying swizzles to fixed types is expensive.
With those rules in mind, I’m looking through the Unity example shaders (which I’m assuming represent best practice
and trying to explain the justification of why the COLOR semantic returned by the fragment shader is
- a fixed4 in the Simple Shader example (as I’d expect)
- a half4 in the UV shader example
- a float4 in the Mandelbrot shader example
Can anyone provide a justification why these examples don’t return COLOR as a fixed4? (Should all fragment shaders return a fixed4?)