Sign in to follow this  

Problem with HLSL and textures

This topic is 4138 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

To make some cool effects I am starting to learn HLSL but there is a big problem I do not know how to solve: I have a very simple shader which only should show my textured mesh but instead of a textured mesh there is only a grey one. My fx-file looks like this:
float4x4 matViewProjection; 

struct a2v
{ 
    float4 Position : POSITION;
    float2 Texcoord0 : TEXCOORD0;
};
 
struct v2p
{
    float4 Position  : POSITION;
    float2 Texcoord0  : TEXCOORD0;
};
 
//VERTEX SHADER
void vs(in a2v IN, out v2p OUT) 
{
    OUT.Position = mul(IN.Position, matViewProjection);
    OUT.Texcoord0 = IN.Texcoord0;
}

technique test
{
    pass p0
    {
        vertexshader = compile vs_1_1 vs();
    }
}
I do not know what the problem could be because the mesh is rendered correctly (so the shader should be applied to the model correctly I think) but there is no texture visible (I tried out a color instead if a texture but this also did not work)!

Share this post


Link to post
Share on other sites
you dont have a pixel shader. The actual colouring and texturing is done in the pixel shader.

your effect file should be this:

float4x4 matViewProjection;

sampler2D tex = "texture.gif" // or whatever
struct a2v
{
float4 Position : POSITION;
float2 Texcoord0 : TEXCOORD0;
};

struct v2p
{
float4 Position : POSITION;
float2 Texcoord0 : TEXCOORD0;
};

//VERTEX SHADER
v2p vs(in a2v IN)
{
v2p OUT;
OUT.Position = mul(IN.Position, matViewProjection);
OUT.Texcoord0 = IN.Texcoord0;
return OUT;
}

//VERTEX SHADER
float4 ps(v2p Input)
{
return tex2d(tex, Input.Texcoord0);
}


technique test
{
pass p0
{
vertexshader = compile vs_1_1 vs();
pixelshader = compile vs_1_1 ps();

}
}


i did that from memory so it might not be perfect but give it a go in rendermonkey or somehting

Share this post


Link to post
Share on other sites
I think there must be another problem because not even simple coloring works...

In some tutorials I found that this should work:


float4x4 matViewProjection;

struct a2v
{
float4 Position : POSITION;
float4 Color : COLOR0;
};

struct v2p
{
float4 Position : POSITION;
float4 Color : COLOR0;
};

v2p vs(in a2v IN)
{
v2p OUT;

OUT.Position = mul(IN.Position, matViewProjection);
OUT.Color = IN.Color;

return OUT;
}

technique test
{
pass p0
{
vertexshader = compile vs_1_1 vs();
}
}


but there also just a grey mesh is rendered....

Share this post


Link to post
Share on other sites

Well since you don't use pixel shader, you should define some texture operations such as modulate diffuse and texture or just use diffuse.

You can use VS without pixel shaders too.

Cheers

Share this post


Link to post
Share on other sites
but now I don't know why the last code snippet doesn't work....It should render a simple mesh with the color I specified in my application.... but no matter what color I use in my app the mesh is always grey :(

maybe it is not the shader that isn't correct maybe it is something in my application...are there any things I have to take care of when loading a fx-file?

atm I am doing this:


D3DXCreateEffectFromFile(pDevice, strShader, 0, 0, 0, NULL, &this->m_pShader, 0);


and later this


UINT cPasses;

m_pShader->SetMatrix("matViewProjection", &m_matViewProjection);
m_pShader->SetTechnique("test");
m_pShader->Begin(&cPasses, 0);
m_pShader->BeginPass(0);
--- Render something ---
m_pShader->EndPass();
m_pShader->End();

Share this post


Link to post
Share on other sites
After m_pShader->BeginPass(0);, try setting the FVF for the mesh structure and check your v2p structure too, that it matches the vertex format.

Share this post


Link to post
Share on other sites

This topic is 4138 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.

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