Jump to content
  • Advertisement
Sign in to follow this  
S-Rave

pixel shader without sampler

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

Hey, I'm trying to use a pixel shader on a quad and change the color based on the uv coordinates (without a sample texture). On all the examples I've seen this should work but all it returns is the color blue:
float4 GradPS(float2 tex : TEXCOORD0) : COLOR
{
	float4 c = float4(1,1,1,1);
	c.r = tex[0];
	c.g = 0;
	return c;
}
I'm guessing that I'm not sending any TEXCOORD0, only I've set it in my vertex declaration:
// This looks okay to me.
D3DVERTEXELEMENT9 VertexPNTElements[] = 
{
  {0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
  {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
  {0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
  D3DDECL_END()
};	
HR(gd3dDevice->CreateVertexDeclaration(VertexPNTElements, &VertexPNT::Decl));
It might be the declaration of the plane vertex buffer and index buffer, only it shows the quad. In the VertexPNT, first 3 are position, next 3 are normal (aren't really used in the shader), last 2 are uv.
HR(gd3dDevice->CreateVertexBuffer(4 * sizeof(VertexPNT), D3DUSAGE_WRITEONLY,
		0, D3DPOOL_MANAGED,	&mPlaneVB, 0));

	VertexPNT* v = 0;
	HR(mPlaneVB->Lock(0,0,(void**)&v, 0));

	v[0] = VertexPNT(-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
	v[1] = VertexPNT(-1.0f,  1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
	v[2] = VertexPNT( 1.0f,  1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
	v[3] = VertexPNT( 1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);

	HR(mPlaneVB->Unlock());
	
	// Create the vertex buffer.
	HR(gd3dDevice->CreateIndexBuffer(6 * sizeof(WORD),	D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,	D3DPOOL_MANAGED, &mPlaneIB, 0));

	// Write box indices to the index buffer.
	WORD* i = 0;
	HR(mPlaneIB->Lock(0, 0, (void**)&i, 0));

	// Fill in the front face index data
	i[0] = 0; i[1] = 1; i[2] = 2;
	i[3] = 0; i[4] = 2; i[5] = 3;
	
	HR(mPlaneIB->Unlock());
Here is my rendering:
HR(mPlaneFX->SetTechnique(mhPlaneTech));
HR(mPlaneFX->SetMatrix(mhPlaneWVP, &(mView*mProj*mWorld)))
HR(mPlaneFX->SetFloat(mhPlaneTime, fTime));
	
HR(gd3dDevice->SetVertexDeclaration(VertexPNT::Decl));
HR(gd3dDevice->SetStreamSource(0, mPlaneVB, 0, sizeof(VertexPNT)));
HR(gd3dDevice->SetIndices(mPlaneIB));

UINT numPasses = 0;
HR(mPlaneFX->Begin(&numPasses, 0));
for(UINT i = 0; i < numPasses; ++i)
{
  HR(mPlaneFX->BeginPass(i));
  HR(gd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2));
  HR(mPlaneFX->EndPass());
}
HR(mPlaneFX->End());
I've googled for 5 hours and checked my directx book but I just can't figure it out. Anyone got any clue to why it doesn't work? Or maybe it's not supposed to work like this.

Share this post


Link to post
Share on other sites
Advertisement
Does your vertex shader actually pass the UV coordinates to PS? Also, what Buckeye said.

Share this post


Link to post
Share on other sites
Buckeye:
I've already tried with tex.x (had it that way before), didn't work. Tried again now, same results. :

Nik02:
How do I pass the uv from the vertex shader?


Edit: Aah... send the texcood to the vertex shader output structure. Thanks, it've got it now. :)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!