Jump to content
  • Advertisement
Sign in to follow this  
robison

problems trying to do billboarding in a vertex shader

This topic is 5056 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 all, i've been trying to get hardware billboarding working for a particle system with little luck...i can verify the data is correctly being sent to the vertex shader via debugging, however control never seems to reach my pixel shader (doesn't ever stop at the breakpoint there), which i think is why i'm not seeing anything displayed. I'm filling a dynamic vertex buffer with triangle list information like so:
D3DVERTEXELEMENT9 dwDecl[] =
		{
			{0,  0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
			{0, 12, D3DDECLTYPE_D3DCOLOR,  D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
			{0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
			{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},
			D3DDECL_END()
		};

		m_pd3dDevice->CreateVertexDeclaration( dwDecl, &m_pDecl );

        VOID Draw()
	{
		if(ParticleCount() == 0)
			return;

		// Lock the vertex buffer
		SFireVertex* pVerticies;
		HRESULT hr = m_VB->Lock(0, 0, (VOID**)&pVerticies, D3DLOCK_DISCARD);
		if( SUCCEEDED(hr) )
		{
			DWORD j = 0;
			for( DWORD i = 0; i < ParticleCount() * 6; j++)
			{
				// Triangle 1
				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 0.0f, 0.0f );
				i++;

				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 1.0f, 1.0f );
				i++;

				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 0.0f, 1.0f );
				i++;

				// Triangle 2
				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 0.0f, 0.0f );
				i++;

				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 1.0f, 0.0f );
				i++;

				pVerticies.vecPos		= m_arrParticles[j].m_vecPos;
				pVerticies.diffuse		= m_arrParticles[j].m_Color;
				pVerticies.vecTexCoord1	= D3DXVECTOR2( m_arrParticles[j].m_fSize, m_arrParticles[j].m_fSize );
				pVerticies.vecTexCoord2	= D3DXVECTOR2( 1.0f, 1.0f );
				i++;
			}

			m_VB->Unlock();

			// set up the effect
			m_pd3dDevice->SetStreamSource(0, m_VB, 0, sizeof(SFireVertex));
			m_pd3dDevice->SetVertexDeclaration( m_pDecl );

			m_Effect->SetTexture("g_texture", m_arrParticles[0].m_pTex);
			m_Effect->SetTechnique("RenderBillboard");
			m_Effect->SetVector("g_vecCamUp", &D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f));
			m_Effect->SetVector("g_vecCamRight", &D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f));
			
			
			m_Effect->SetMatrix("g_mWorldViewProjection", &CRenderEngine::GetSingleton().m_matProj);

			// apply the technique
			UINT cPasses;
			m_Effect->Begin(&cPasses, 0);

			for( UINT iPass = 0; iPass < cPasses; iPass++ )
			{
				m_Effect->BeginPass(iPass);

				m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, ParticleCount());

				m_Effect->EndPass();
			}

			m_Effect->End();

		}
		
	}


and my HLSL .fx file looks like this:
float4 g_vecCamRight;
float4 g_vecCamUp;
texture g_texture : DIFFUSE;
float4x4 g_mWorldViewProjection;

sampler TexSampler = 
sampler_state {
	Texture = <g_texture>;
    MipFilter = LINEAR;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
};

struct VS_OUTPUT
{
    float4 Position   : POSITION;   // vertex position 
    float4 Color      : COLOR0;
    float2 TextureUV  : TEXCOORD0;  // vertex texture coords 
};

VS_OUTPUT BillboardVS( float4 vpos : POSITION,
                       float4 color : COLOR0,
                       float2 vsize : TEXCOORD0,
                       float2 vcorner : TEXCOORD1 )
{
    VS_OUTPUT Output;
    float3 adjustX = (vcorner.x * 2.0f - 1.0f) * g_vecCamRight.xyz * vsize.x;
	float3 adjustY = (vcorner.y * 2.0f - 1.0f) * g_vecCamUp.xyz * vsize.y;

	vpos.xyz += adjustX.xyz + adjustY.xyz;

    // transform to clip space
    Output.Position = mul(vpos, g_mWorldViewProjection);
        
    // copy the tex coord through
    Output.TextureUV = vcorner;
    
    // and the diffuse color
    Output.Color = color;
    
    return Output;
}

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};

PS_OUTPUT BillboardPS( VS_OUTPUT In )
{
    PS_OUTPUT Output;
    
    Output.RGBColor = tex2D(TexSampler, In.TextureUV) * In.Color;
    
    return Output;
}

technique RenderBillboard
{
    pass P0
    {
		Lighting = True;
		AlphaBlendEnable = True;
		AlphaTestEnable = True;

        VertexShader = compile vs_1_1 BillboardVS();
        PixelShader  = compile ps_1_1 BillboardPS();
    }
}


note: i set the ps version to 2.0 when debugging so am i doing something horribly wrong here? i was under the impression using D3DXEffects was pretty straightforward. also, for right now i'm just passing the projection matrix into the shader, as my world and view matricies are still set to the identity matrix until i implement a camera controller and can set g_vecCam* from the real camera values. anything glaringly obvious i'm doing wrong? thanks! [Edited by - robison on September 16, 2004 3:42:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
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!