Color rendering via pixel shader in HLSL

I have a pixel shader that should just skip the input color, but instead I get a consistent result. I think my syntax could be a problem. Here is the shader:

struct PixelShaderInput
{
    float3 color : COLOR;
};

struct PixelShaderOutput
{
    float4 color : SV_TARGET0;
};

PixelShaderOutput main(PixelShaderInput input)
{
    PixelShaderOutput output; 
    output.color.rgba = float4(input.color, 1.0f); // input.color is 0.5, 0.5, 0.5; output is black
    // output.color.rgba = float4(0.5f, 0.5f, 0.5f, 1); // output is gray
    return output;
}

For testing, I have a vertex shader that precedes this in pipleline, passing the COLOR parameter of 0.5, 0.5, 0.5. Coming through a pixel shader in VisualStudio, input.color has the correct values, and they are correctly processed by output.color. However, when rendering the vertices that use this shader are all black.

Here is a description of the vertex shader element:

const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
{
    { "POSITION",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR",      0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD",   0, DXGI_FORMAT_R32G32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

I'm not sure if it matters that the vertex shader accepts colors, since RGB produces the same thing, but the pixel shader outputs RGBA. The alpha layer works as a minimum.

, input.color , , ( ).

, ?

4 9_1, .

+5
3
output.color.rgba = float4(input.color, 1.0f);

input.color - float4, float4, ,

output.color.rgba = float4(input.color.rgb, 1.0f);

,

 return input.color;

, -

input.color = float4(1.0f, 0.0f, 0.0f, 1.0f);
return input.color;
+2

* , , ? D3D.: , , , . PixelShaderInput :   struct PixelShaderInput   {        float4: SV_POSITION;       float3 color: COLOR;   }; *

?:

float4 main(float3 color : COLOR) : SV_TARGET
{
    return float4(color, 1.0f);
}
+1

float4(input.color, 1.0f);

, . :

float4(input.color[0], input.color[1], input.color[2], 1.0f);

Edit:

, , float4 COLOR (http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx)

0
source

All Articles