• Advertisement
Sign in to follow this  

Problem with texture coordination in shader

This topic is 1053 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by MahanGM

Share this post


Link to post
Share on other sites
Advertisement

Shader looks fine. Could be lots. Mismatching VertexDeclaration, wrong texture bound, wrong texture coordinates.

 

You get anything from debug layer (enable D3D9 debugging in the DirectX Control Panel) ?

 

Also, best get familiar with a graphics debugger (renderdoc, or vendor specific). For D3D9 PIX should be fine (if it works on your system). 

 

PS: Please show the calling code:  setting effect constants, applying the pass, binding mesh, drawing. Also show or tell, what renderstates you have set. Maybe we see something.

Edited by unbird

Share this post


Link to post
Share on other sites

I figured I had a problem with vertex declaration. It's fixed now. Thanks for your time smile.png

Edited by MahanGM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement