Sign in to follow this  
belfegor

VS->PS linker error

Recommended Posts

belfegor    2834

I got this error:

 

Direct3D9: VS->PS Linker: X777: (Error) The current pixel shader expects vertex declaration to provide semantic 'texcoord0' including components(s): 'xyzw',

however the current transformed vertex declaration (vertex proc. disabled) provides 'texcoord0' with component(s): 'xy'. 

The vertex declaration's component set needs to be a superset of pixel shader input component set.

 

Vertex shader

struct A2V
{
    float4 Position  : POSITION;
    float2 TexCoord0 : TEXCOORD0;
    float4 Color     : TEXCOORD1;
};

struct V2P
{
    float4 Position  : POSITION;
    float4 TexCoord0 : TEXCOORD0;
    float4 Color     : TEXCOORD1;
};

void VertexProgram(in A2V IN, out V2P OUT)
{
    OUT.Position.x  = IN.Position.x;
    OUT.Position.y  = IN.Position.y;
    OUT.Position.z  = IN.Position.z;
    OUT.Position.w  = IN.Position.w;
    OUT.TexCoord0.x = IN.TexCoord0.x;
    OUT.TexCoord0.y = IN.TexCoord0.y;
    OUT.TexCoord0.z = IN.TexCoord0.x * 0.25f;
    OUT.TexCoord0.w = IN.TexCoord0.y * 0.25f;
    OUT.Color       = IN.Color;
}

 

Pixel shader

sampler fontSamp : register(s0);

struct V2P
{
    float4 Position  : POSITION;
    float4 TexCoord0 : TEXCOORD0;
    float4 Color     : TEXCOORD1;
};

struct P2A
{
    float4 Color     : COLOR;
};

void PixelProgram(in V2P IN, out P2A OUT)
{
    float2 alphaRange = float2(0.1f, 1.0f);
    float4 base       = float4(IN.Color.rgb, tex2D(fontSamp, IN.TexCoord0.xy).a);
    float sdf         = tex2D(fontSamp, IN.TexCoord0.zw).r;
    float alpha       = smoothstep(alphaRange.x, alphaRange.y, sdf);
    OUT.Color         = lerp(base, IN.Color, alpha);
}

 

and my vertex elements

D3DVERTEXELEMENT9 vertexElements[] =
{
    {0,  0,  D3DDECLTYPE_FLOAT4,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITIONT, 0},
    {0, 16,  D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  0},
    {0, 24,  D3DDECLTYPE_FLOAT4,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,  1},
    D3DDECL_END()
};

 

I don't see whats wrong?

Share this post


Link to post
Share on other sites
MJP    19756

When you use POSITIONT, it means that the vertex positions are pre-transformed and that the vertex shader isn't run. Therefore the contents of your vertex buffer get passed directly to the pixel shader. In your vertex decaration TEXCOORD0 is a float2, but your pixel shader expects a float4. Either change your vertex buffer and declaration so that it has a float4, or change your pixel shader to take a float2.

Edited by MJP

Share this post


Link to post
Share on other sites
belfegor    2834
That's that. Thanks.

EDIT:
Now i have other issue. I want to use vertex shader so i removed 'T' from (POSITION) vertex declaration .
And now have this vertex shader
#pragma pack_matrix(row_major)

float4x4 mat2D : register(c0);

struct A2V
{
	float4 Position  : POSITION;
	float2 TexCoord0 : TEXCOORD0;
	float4 Color     : TEXCOORD1;
};

struct V2P
{
	float4 Position  : POSITION;
	float4 TexCoord0 : TEXCOORD0;
	float4 Color     : TEXCOORD1;
};

void VertexProgram(in A2V IN, out V2P OUT)
{
	OUT.Position    = mul(float4(IN.Position.xyz, 1.0f), mat2D);
	OUT.TexCoord0.x = IN.TexCoord0.x;
	OUT.TexCoord0.y = IN.TexCoord0.y;
	OUT.TexCoord0.z = IN.TexCoord0.x * 0.25f;
	OUT.TexCoord0.w = IN.TexCoord0.y * 0.25f;
	OUT.Color       = IN.Color;
}

and code
D3DXMATRIX mat2D;
D3DXMatrixTransformation2D(&mat2D, NULL, 0.0f, NULL, NULL, 0.0f, NULL);
...
d3d9device->SetVertexShaderConstantF(0, mat2D, 4);

and my quads are in "screen coordinate".

But now i cannot display anything to screen. Any help? Edited by belfegor

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this