The color values ​​of the shader does not work.

*I’m sorry in dub English. (I’m Japanese)

I am using for the first time the Monogame. (Ver 3.5)
I was using in the XNA (SM3.0), but was ported to MonoGame (SM4.0).
In XNA it was displayed properly.
Cause I do not know, but it disables the color values ​​in the shader.

sample code

struct sVS_INPUT_PN
{
    float4 f4Pos0: POSITION0;
    float3 f3Normal0: NORMAL;
};

struct sVS_OUTPUT_PC
{
    float4 f4Pos0: POSITION0;
    float4 f4Color0: COLOR0;
};

struct sPS_INPUT_C
{
    float4 f4Color0: COLOR0;
};

sVS_OUTPUT_PC vs_PN (sVS_INPUT_PN In)
{
    sVS_OUTPUT_PC Out;
//
// Vertex calc(omit)
//

Out.f4Color0.rgba = max(0,dot(vNormalWorldSpace, gLightDir3));


   // Test code A
// Out.f4Color0 = 1;

    return Out;
}

float4 ps_C (sPS_INPUT_C In): COLOR
{
    // Test code B
// In.f4Color0 = 1;
    return In.f4Color0;
}

technique technique_PC
{
    pass Pass1
    {
        VertexShader = compile vs_4_0_level_9_1 vs_PN ();
        PixelShader = compile ps_4_0_level_9_1 ps_C ();
    }
}
  1. test code A Comment out (test code B is Comment)
    The output color of VertexShader, even if forced assignment, color is still black.

  2. test code B Comment out (test code A is Comment)
    The output color of PixelShader, if you force assignment, the color is white.

Why?
Vertex Shader of color, it seems not to have been passed to the Pixel Shader.
It is pitch black, but since the vertices are depicted, vertex data is no problem.
Both, to become white is the correct answer.

Not using SV_POSITION on the inputs is quite a common problem http://www.monogame.net/documentation/?page=Custom_Effects

In the vertex shader you register the output variable, but you do not define it / fill it with values.

It’s just an empty struck of sVS_OUTPUT_PC.

You need to do something like

sVS_OUTPUT_PC vs_PN (sVS_INPUT_PN In)
{
sVS_OUTPUT_PC Out;
Out.f4Pos0 = In.f4Pos0.
return Out;
}

to pass the position to the pixel shader.
Now obviously you won’t get a color, since in your input you only ask for Normal and Position. Your input must also define a Color which you then pass to the output like this

Out.Color = In.Color
[…]
return Out;

All that is said before is true.

SV_POSITION is required.
I usually use texture coordinates in my VertexShaderOutput like this
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float2 TextureCoordinates : TEXCOORD0;
};

Don’t forget to set the values to the members of the struct at the end of the VertexShader as kosmonautgames said.

You can test your texture coordinates contained in the output by returning something like
return float4(TextureCoordinates, 0,0);
If the result is uniformely filled with the same color (all red or all green for ex), your coordinates are wrong !

Dear procd.
thank you, replay!

I’ve already tried, but the results did not change. (SV_POSITION)
There is the color is wrong, the vertex is no problem.

Dear kosmonautgames
Thank you!

Delivery of color, has written of course.
Because the problem is not there, in the sample code, it has been omitted.
Rather than in the calculation of the color is a problem, but has put the color just prior to return,
Not be reflected in the pixel shader is is the problem.

  • Just to be sure, it has been modified the sample code

Dear Alkher.

thank you.
Because I English is not good, I’m sorry when I wrong.

This Shader, the texture does not use.
Input of VS is position + normal.
The output of the VS is positon + color.
Input of the PS is color.
Only.

Do you mean you use some sort of vertex color instead of reading colors from the model’s texture ?

yes yes. This shader use Vertex color.

This is a bug?

Way to avoid it was found, why I do not know.
In VS, without touching the COLOR0, and use the Vertex Color in COLOR1, there is no problem!
Then, when the output of the PS even COLOR1, will be displayed properly.
To try, to remove the COLOR0, also try only to COLOR1, will cause problems.
To imagine, register contents of COLOR0 it is, seem to have been destroyed.

fixed.

Without using COLOR1 was good.
Vertex Shader of Output Structure of the order seems to be a problem in.

struct sVS_OUTPUT_PC
{
   float4 f4Pos0: VS_POSITION;
   float4 f4Color0: COLOR0;
};

↓

struct sVS_OUTPUT_PC
{
    float4 f4Color0: COLOR0;
    float4 f4Pos0: VS_POSITION;
};

data that follows the position data is, seems to be destroyed.
When i move the position data to the end of the structure, it has moved in the same way as the XNA.
Was good.
Although not a real solution, not perhaps of the Shader Compiler bug.
(So no other person becomes, only such to be my project …)


To I think that’ll keep posting.