Archived

This topic is now archived and is closed to further replies.

eAvatar

Problem with Point Sprites

Recommended Posts

eAvatar    122
I''m currently working on a particle system, but I''m having trouble getting my particles to render. I''ve looked at the point sprites demo, and I think I''m doing all the required steps, but so far no joy. Heres my code for my vertex structure, FVF & render function:
  
#define D3DFVF_PARTICLEFVF ( D3DFVF_XYZ | D3DFVF_DIFFUSE )


struct PARTICLEVERTEX
{
	float x, y, z;
	D3DCOLOR DiffuseColor;
};

Render()
{
    // Set the render state for drawing particles

    g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
    g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    g_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
    g_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

    // Set the render states for using point sprites

    g_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
    g_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );
    g_pDevice->SetRenderState( D3DRS_POINTSIZE,     0.08f );
    g_pDevice->SetRenderState( D3DRS_POINTSIZE_MIN, 5.00f );
    g_pDevice->SetRenderState( D3DRS_POINTSCALE_A,  0.00f );
    g_pDevice->SetRenderState( D3DRS_POINTSCALE_B,  0.00f );
    g_pDevice->SetRenderState( D3DRS_POINTSCALE_C,  1.00f );

    // Create the vertex buffer

    LPDIRECT3DVERTEXBUFFER8 m_pVB = 0;
    g_pDevice->CreateVertexBuffer( sizeof(PARTICLEVERTEX), 
		D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS, 
		D3DFVF_PARTICLEFVF, D3DPOOL_DEFAULT, &m_pVB );
	
    // Lock into vertex buffer

    BYTE* pVBData = 0;
    m_pVB->Lock( 0, sizeof( PARTICLEVERTEX ), &pVBData, 0 );
	
    // Copy the data into the vertex buffer

    CopyMemory( pVBData, &m_Particle.m_Vertex,
                sizeof( m_Particle.m_Vertex ) );

    // Unlock the vertex buffer

    m_pVB->Unlock();

    // Set up the vertex buffer to be rendered

    g_pDevice->SetStreamSource( 0, m_pVB, sizeof(PARTICLEVERTEX) );
    g_pDevice->SetVertexShader( D3DFVF_PARTICLEFVF );

    // Render the particle system

    g_pDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 1);
  
    m_pVB = 0;

    // Reset render states

    g_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
    g_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  FALSE );

    // Reset the render state

    g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
    g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}
  
Any help is appreciated. Steve.

Share this post


Link to post
Share on other sites
Wreakon    121
I suggest making them a bigger size. It is very hard to notice them at that size (0.08f), and especially if they are off the screen (so check your coordinates as by debugging). Note that some point sprite sizes are not supported, this is a psossibility if your video card is old, to my knowledge you dont want to make the point sprite size bigger than 64.0f (which should be plenty).

-------
"Programming is like sex make one mistake, and you have to support it forever."
Homepage: http://students.washington.edu/andrey

Share this post


Link to post
Share on other sites
eAvatar    122
Tried making them bigger, still no joy, alas. Also I''m pretty sure my card supports them because 1) Its a GeForce 4 Ti4600, and 2) I can run the point sprites demo fine. Still, thanks for the suggestion.

Steve.

Share this post


Link to post
Share on other sites
bluescreen    122
First, some minor issue I can see...Why do you create
your vertex buffer every frame? Even you didn't release it.
And, as you know, I think the main problem is
that your D3DRS_POINTSIZE_MIN is bigger(much bigger)
than your D3DRS_POINTSIZE. This should be inverse.
And if you use orthographic projection, do not use
B and C coefficient of point scale(giving them 0s).
Give A 1 only.

[edited by - bluescreen on September 30, 2002 12:48:15 AM]

Share this post


Link to post
Share on other sites
eAvatar    122
Well, currently this code is ''bolted on'' so the vertex buffer issue will be solved later, although now I''m releasing it my program crashes a lot less! Anyway, tried adjusting the parameters but still no joy.

Steve.

Share this post


Link to post
Share on other sites
bluescreen    122
quote:

// Set the render state for drawing particles
g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
g_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
g_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
g_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );



Disabling ZWRITEENABLE is for enabling ALPHABLENDENABLE...
But you gave FALSE to both. Give TRUE to ALPHABLENDENABLE.

quote:

// Create the vertex buffer
LPDIRECT3DVERTEXBUFFER8 m_pVB = 0;
g_pDevice->CreateVertexBuffer( sizeof(PARTICLEVERTEX),
D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS,
D3DFVF_PARTICLEFVF, D3DPOOL_DEFAULT, &m_pVB );
// Lock into vertex buffer
BYTE* pVBData = 0;
m_pVB->Lock( 0, sizeof( PARTICLEVERTEX ), &pVBData, 0 );
// Copy the data into the vertex buffer
CopyMemory( pVBData, &m_Particle.m_Vertex,
sizeof( m_Particle.m_Vertex ) );
// Unlock the vertex buffer
m_pVB->Unlock();
// Set up the vertex buffer to be rendered
g_pDevice->SetStreamSource( 0, m_pVB, sizeof(PARTICLEVERTEX) );
g_pDevice->SetVertexShader( D3DFVF_PARTICLEFVF );
// Render the particle system
g_pDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 1);



Isn't this code drawing only one particle per frame?
Try drawing at least 50 particles and give them 5 seconds(only as an example) of life minimmum...

[edited by - bluescreen on October 2, 2002 1:25:30 PM]

Share this post


Link to post
Share on other sites
eAvatar    122
Thanks for the help people, I''ve got them displaying, so I can now start to implement a proper particle system using point sprites!

Thanks, Steve.

Share this post


Link to post
Share on other sites