Problem with HLSL and textures

Started by
5 comments, last by madRenEGadE 17 years, 8 months ago
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)!
Advertisement
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
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....

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
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();

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.
found the problem....all were grey because of fog being enabled. After I disabled fog all worksed fine

This topic is closed to new replies.

Advertisement