The problem is caused due to a difference in perspective in programming hlsl for dx9 vs 10+. Here's the situation:
- Code: Select all
uniform extern float4x4 g_wvp;
struct VSInput
{
float3 posL : POSITION0;
float4 color : COLOR0;
};
struct VSOutput
{
float4 posH : POSITION0;
float4 color : TEXCOORD0;
};
VSOutput VShader(VSInput input)
{
VSOutput output = (VSOutput)0;
output.posH = mul(float4(input.posL, 1.0f), g_wvp);
output.color = input.color;
return output;
}
float4 PShader(float4 color : TEXCOORD0) : COLOR
{
return color;
}
Yes, in this case, the pixel shader is pretty useless, but it's for simplicity. The vertex shader receives as input a float3 position, and float4 color. The output is a float4 transformed homogeneous position, and a float4 color.
The pixel shader receives only the float4 color as input because the extra data is not necessary.
However, this would be invalid for dx10+. Dx10+ requires that the vertex shader output match the pixel shader input. So the equivalent shaders would be:
- Code: Select all
cbuffer ConstBuffer : register(b0)
{
matrix g_wvp;
}
struct VSInput
{
float3 posL : POSITION0;
float4 color : COLOR0;
};
struct VStoPS
{
float4 posH : SV_Position;
float4 color : TEXCOORD0;
};
VStoPS VShader(VSInput input)
{
VStoPS output = (VStoPS)0;
output.posH = mul(float4(input.posL, 1.0f), g_wvp);
output.color = input.color;
return output;
}
float4 PShader(VStoPS input) : SV_Target
{
return input.color;
}
Note that even though the positional data is not used, it must be passed to the pixel shader.
This has been the hangup for me successfully rendering a simple cube on the screen with position, color, and texture coordinate data. What a pain!!

