I am trying to convert a half3 as a simple half but I am facing an issue. As for an example half3(1, 0, 0) give me white but half3(0, 1, 0) gives me black.

How can I convert properly a half3 to a simple black and white half value

Thank you.


There are a variety of formulae for converting colour to black and white. Furthermore, the programmer might mean something else when converting a vector into a scalar (length would be a common example). The shader compiler keeps things as simple as possible, just taking the first value in the vector, in your example.

Experiment with different ways to get a black and white that looks good in your situation. Some examples might be:

scalar = max(vector.r, max(vector.g, vector.b));


scalar = (vector.r + vector.g + vector.b) * 0.333;


scalar = length(vector) / 1.73205080757; // sqrt(3), which is the length of vector(1,1,1)

OR go for one of the formulae in that Wikipedia article I linked that emulates black and white film.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .