Sign in to follow this  
BrakePad

HLSL and Textured Meshes

Recommended Posts

Hey all, I'm starting working on some shaders for lighting a bunch of meshes in the scene, but can't for the life of me figure out how to even get textures appearing... When using the shader, the entire mesh is rendered with no lighting at all, and all white. At the moment the shader code literally is meant to just draw the vertices and pixels unchanged (pretty much plagurised of the net)...
float4x4 worldViewProj;

Texture xTexture;

sampler TextureSampler = sampler_state
{
	texture = <xTexture> ;
	magfilter = LINEAR;
	minfilter = LINEAR;
	mipfilter = LINEAR;
	AddressU = mirror;
	AddressV = mirror;
};

struct VertexToPixel
{
    float4 Position     : POSITION;
    float3 Tex		: TEXCOORD0;

};

struct PixelToFrame
{
    float4 Color        : COLOR0;
};


VertexToPixel SimplestVertexShader( float4 inPos : POSITION, float4 inTex : TEXCOORD0)
{
    VertexToPixel Output = (VertexToPixel)0;
    
    Output.Position = mul(inPos, worldViewProj);
    Output.Tex = inTex;


    return Output;
}


PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
{
    PixelToFrame Output = (PixelToFrame)0;    

    Output.Color = tex2D(TextureSampler, PSIn.Tex);

    return Output;
}

technique Simplest
{
    pass Pass0
    {
        VertexShader = compile vs_1_1 SimplestVertexShader();
        PixelShader = compile ps_1_1 OurFirstPixelShader();
    }
}

I think it has something to do with the FVF of the mesh being different from the vertex declaration, but I've tried retrieving the FVF from the mesh, and setting it in a vertex Declaration, but nothing changes. I'm rendering my meshes like so:
m_effPostProcessing->Begin(&numPasses,0);
for (UINT i=0;i<numPasses;i++)
{
    m_effPostProcessing->BeginPass(i); // Set the pass

    for(DWORD i = 0; i < m_numMats; i++)    // loop through each subset
    {
        D3DXMATRIX &matWorldViewProjection = matWorld * m_matView * m_matProjection;
	m_effPostProcessing->SetMatrix("worldViewProj", &matWorldViewProjection);
	m_directXDevice->SetMaterial(&m_matMesh[i]);    	// set the appropriate material for the subset
	if(m_texMesh[i] != NULL)    	// if the subset has a texture (if texture is not NULL)
	{
	    m_directXDevice->SetTexture(0, m_texMesh[i]);    // ...then set the texture
	    m_effPostProcessing->SetTexture("xTexture", m_texMesh[i]);
	    m_effPostProcessing->CommitChanges();
        }
	else
	{
	    m_directXDevice->SetTexture(0, NULL);
	    m_effPostProcessing->SetTexture("xTexture", NULL);
	    m_effPostProcessing->CommitChanges();
	}
	m_meshMesh->DrawSubset(i);    // draw the subset
    }	// END FOR
    m_effPostProcessing->EndPass();
} // END EFFECT LOOP
m_effPostProcessing->End();

Maybe I'm misunderstanding the concept behind where the shaders get their data from, but i'm fairly sure I'm presenting them the correct FVF and textures to it. The problem is I'm loading meshes dynamically, and hence cannot predict the vertec format saved in each mesh... Any help would be greatly appreciated - yet again I look to GameDev in the early hours of the morning after too many awake trying to code out of my depth! bp

Share this post


Link to post
Share on other sites

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