1

In a Metal surface shader (for a custom material), the color = params.geometry().color() call returns a float4 type. I guess that color is the interpolated color for the fragment in the triangle.

I'd like to set that color to params.surface().set_base_color(color), however set_base_color expects a half3 parameter.

How to convert from float4 to half3, and how to combine the values ? (well, I only 1.0 alfa but still...).

1 Answer 1

1

See Metal Shader Language Specification, section 2.2.1 Accessing Vector Components.

You can use .xyz (or .zyw or any other combination) on a float4 to turn it into float3

Then, when you have the right number of components in a floatN vector, you must explicitly convert it to halfN.

So what you want to do is half3(float4value.xyz)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.