Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Full screen quad through shader problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Shanee   Members   -  Reputation: 207

Like
0Likes
Like

Posted 28 March 2011 - 08:26 AM

Hi :)

I need to render a full screen quad, until now I have been using this:

		FLOAT fWidth5 = ( FLOAT )dtdsdRT.Width - 0.5f;
		FLOAT fHeight5 = ( FLOAT )dtdsdRT.Height - 0.5f;


		// Draw the quad
		QuadVertex svQuad[4];

		svQuad[0].Position = D3DXVECTOR4( -0.5f, -0.5f, 0.5f, 1.0f );
		svQuad[0].Texture = D3DXVECTOR2( fLeftU, fTopV );

		svQuad[1].Position = D3DXVECTOR4( fWidth5, -0.5f, 0.5f, 1.0f );
		svQuad[1].Texture = D3DXVECTOR2( fRightU, fTopV );

		svQuad[2].Position = D3DXVECTOR4( -0.5f, fHeight5, 0.5f, 1.0f );
		svQuad[2].Texture = D3DXVECTOR2( fLeftU, fBottomV );

		svQuad[3].Position = D3DXVECTOR4( fWidth5, fHeight5, 0.5f, 1.0f );
		svQuad[3].Texture = D3DXVECTOR2( fRightU, fBottomV );

		DWORD oldZ;
		gEngine->GraphicsDevice()->GetDeviceCOM()->GetRenderState( D3DRS_ZENABLE, &oldZ );

		if (oldZ)
			gEngine->GraphicsDevice()->GetDeviceCOM()->SetRenderState( D3DRS_ZENABLE, FALSE );

		gEngine->GraphicsDevice()->GetDeviceCOM()->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1 );
		gEngine->GraphicsDevice()->GetDeviceCOM()->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, svQuad, sizeof( QuadVertex ) );

		if (oldZ)
			gEngine->GraphicsDevice()->GetDeviceCOM()->SetRenderState( D3DRS_ZENABLE, TRUE );


Which works just fine but does not go through the shader because of the D3DFVF_XYZRHW value.

So I tried to use XYZ and XYZW but both gave me incorrect results. I also tried rendering the quad at size of [0,1] and sizes [-1,1] as I saw online some discussions, both failed, also [0,width/height] seems to have failed, but I may have not tried XYZ or XYZW in one or the other.

What is the solution for this ? How should I make my vertices so I can have a fullscreen quad which will also go through the vertex shader (the reason for it to go through the vertex shader is because I need a corner index of the quad to pass values to the pixel shader, so my texture UV is actually D3DXVECTOR3 with z being the index).

Sponsor:

#2 programci_84   Members   -  Reputation: 335

Like
0Likes
Like

Posted 28 March 2011 - 09:00 AM

I think that passing through shader but not touching position and texcoord might not cause any problems.

For example:
void VS_FSQ (in float4 in_posH : POSITION, in float2 in_texC : TEXCOORD0, out out_posH : POSITION, out out_texC : TEXCOORD0)
{
	out_texC = in_texC;
	out_posH = in_posH;
}

float4 PS_FSQ (float2 texC : TEXCOORD0) : COLOR0
{
   return tex2D (smpSomeSampler, texC);
}

NOTE: You must create a vertex declaration:
D3DVERTEXELEMENT9 vFSQ [ ] = 
{
      { 0, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, 
      { 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
      D3DDECL_END() 
};

LPDIRECT3DVERTEXDECLARATION9 pDecl_FSQ = NULL;
yourD3DDevice->CreateVertexDeclaration (vFSQ, &pDecl_FSQ);

...and set it before rendering full screen quad with a shader like above:
LPDIRECT3DVERTEXDECLARATION9 pDecl_Curr = NULL;
yourD3DDevice->GetVertexDeclaration (&pDecl_Curr);
yourD3DDevice->SetVertexDeclaration (pDecl_FSQ);

//your FSQ rendering code goes here!

yourD3DDevice->SetVertexDeclaration (pDecl_Curr);

hth.
-R
There's no "hard", and "the impossible" takes just a little time.

#3 Shanee   Members   -  Reputation: 207

Like
0Likes
Like

Posted 29 March 2011 - 06:59 AM

I already tired that (and yes, I know how to set vertex decelerations thanks) and it didn't work, I said that in the beginning of the thread, that is why I came here.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS