I'm trying to draw 2d planes with textures. Previously, I was doing this with fixed functions which was fine, but now I'm moving into shaders and I'm stuck.
I have written below shader:
/**
* Parameters
*/
const float4x4 WorldViewProjMatrix;
const int MaxAnisotropy;
const texture MainTexture;
const float4 MainColor;
const bool IsMainTextureSet = true;
/**
* Samplers
*/
sampler2D MainSampler = sampler_state
{
Texture = <MainTexture>;
AddressU = Clamp;
AddressV = Clamp;
MipFilter = Point;
MinFilter = Point;
MagFilter = Point;
MaxAnisotropy = <MaxAnisotropy>;
MipMapLodBias = 0;
};
/**
* Structs
*/
struct VertexShaderInput
{
float4 Position : POSITION0;
float2 TextureUV : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TextureUV : TEXCOORD0;
};
struct PixelShaderOutput
{
float4 Color : COLOR0;
};
/**
* Functions
*/
VertexShaderOutput VertexShaderMain(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = mul(input.Position, WorldViewProjMatrix);
output.TextureUV = input.TextureUV;
return output;
}
PixelShaderOutput PixelShaderMain(VertexShaderOutput input)
{
PixelShaderOutput output;
float4 textureColor = (IsMainTextureSet) ? tex2D(MainSampler, input.TextureUV) : float4(1.0f, 1.0f, 1.0f, 1.0f);
output.Color = saturate(textureColor * MainColor);
return output;
}
/**
* Techniques
*/
technique Diffuse
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShaderMain();
PixelShader = compile ps_2_0 PixelShaderMain();
}
}
The problem is, only first row and column of the texture is drawn. This seems to be a uv coordination problem, but if it was the problem it shouldn't have worked with fixed functions too.
I have attached two files. One is the shot from my application and second is my 128x128 test texture. If you look at the first picture you can see there is a red 2d plane with only the first row and column part of the second picture applied to it. In second picture first row and column is a red line.
I'm sure there is something I'm missing.