I started teaching myself some DirectX a short time ago and found something I'm confused about. For some reason, I can only get the color of the model I'm drawing to vary between black and white, depending on the alpha that I set inside the shader.

This is my PixelShader (which compiles successfully during runtime):

float4 PS( VS_OUTPUT psInput ) : SV_Target
    return (1.0f, 0.0f, 0.0f, 1.0f);

Given the components are r,g,b,a and I'm giving them 1,0,0,1, this should return bright red! Instead, it produces this white area:

mysteriously white area, instead of red

I haven't set a blending state.

What am I missing?


1 Answer 1


You need to write:

return float4(1.0f, 0.0f, 0.0f, 1.0f);

The float4 is necessary to construct a vector. The way you've written it currently, the compiler is interpreting it as the comma operator. The result is that you only return the last element (the alpha component), which then gets replicated to all four components of the result.


You must log in to answer this question.

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