Passing TexCoords to the shader, always get grey textures - Solved

Started by
2 comments, last by Muzzy A 11 years, 6 months ago
EDIT:
I erased everything because i realized my texcoords are just fine, but my texture is always rendering grey.

I started passing in texcoords manually to the sampler, and it was giving me parts of the texture like it should... I think.


/*HLSL*/
// My list of texcoords, they're getting passed correctly i've debugged this
float2 gTexCoord[4];

struct InVertex
{
float3 position : POSITION0;
int nIndex : TEXCOORD0;
};

struct OutVertex
{
float4 position : POSITION0;
float2 texCoord : TEXCOORD0;
};

OutVertex VertexShader(InVertex input)
{
OutVertex output;

output.position = float4(input.position,1);

// Setting the texcoord for this vert.
output.texCoord = gTexCoord[input.nIndex];

return output;
}
float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
{
return tex2D(gSampler,texCoord);
}



// The vertex declaration
D3DVERTEXELEMENT9 decl[] =
{
{ 0,0,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_POSITION,0 },
{ 0,12,D3DDECLTYPE_FLOAT1,D3DDECLMETHOD_DEFAULT,D3DDECLUSAGE_TEXCOORD,0 },
D3DDECL_END()
};


I'm going to try to test the index, to see if it's getting correct values

EDIT: SOLVED

It was indeed the vertex declaration, i was sending it a D3DDECLTYPE_FLOAT1, i changed it to a D3DDECLTYPE_SHORT2 and it worked just fine. I can see why it works, but i feel like it still should work with FLOAT1
Advertisement

Once again, maybe something to do with D3D9 on VS 2012?

It would not be a problem in my opinion.

Could you show the vertex declaration, please?

It was indeed the vertex declaration, i was sending it a D3DDECLTYPE_FLOAT1, i changed it to a D3DDECLTYPE_SHORT2 and it worked just fine. I can see why it works, but i feel like it still should work with FLOAT1


Why? You have it defined as an integer in your vertex shader input.
I assumed it copied by value, so i'm guessing it doesnt?

This topic is closed to new replies.

Advertisement