Sign in to follow this  

point sprites not changing color, driving me crazy.

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

I've made a lot of posts about particle systems lately since I'm making my first one, and most of it has gone pretty well but there's one thing I can't fix. I copied my point sprite particle source from a tutorial, and even though its all copy/pasted, the tutorials sprites can change color mine can NOT. I won't paste my point sprite rendering code because its an exact copy of the working one. What I need to find out is what in my code makes my point sprites always be the color they are in the texture? I'm not sure what code to paste, I could paste all my particle functions but since they're exact copies from a working tutorial you won't find any problems with them. Anyone know what kind of thing I could possibly do that would make my particles color value make no difference when I render them? I'll paste any code upon request. Here's my particle rendering function for the heck of it:
//-----------------------------------------------------------------------------
// Name: renderPointSprites()
// Desc: 
//-----------------------------------------------------------------------------
void ParticleSys::renderPointSprites( LPDIRECT3DDEVICE9 m_pD3DDevice )
{
	//
	// Setting D3DRS_ZWRITEENABLE to FALSE makes the Z-Buffer read-only, which 
	// helps remove graphical artifacts generated from  rendering a list of 
	// particles that haven't been sorted by distance to the eye.
	//
    // Setting D3DRS_ALPHABLENDENABLE to TRUE allows particles, which overlap, 
	// to alpha blend with each other correctly.
	//

    m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );

    m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
    m_pD3DDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

	//
	// Set up the render states for using point sprites...
	//

    m_pD3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );    // Turn on point sprites
    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  TRUE );    // Allow sprites to be scaled with distance
    m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE,     FtoDW(1.0) );  // Float value that specifies the size to use for point size computation in cases where point size is not specified for each vertex.
    m_pD3DDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(1.0f) ); // Float value that specifies the minimum size of point primitives. Point primitives are clamped to this size during rendering. 
    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_A,  FtoDW(0.0f) ); // Default 1.0
    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_B,  FtoDW(0.0f) ); // Default 0.0
    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALE_C,  FtoDW(1.0f) ); // Default 0.0

	//
	// Lock the vertex buffer, and set up our point sprites in accordance with 
	// our particles that we're keeping track of in our application.
	//

	Vertex *pPointVertices;

	m_particleVertexBuffer->Lock( 0, MAX_PARTICLES * sizeof(Vertex),
		                   (void**)&pPointVertices, D3DLOCK_DISCARD );

	for( int i = 0; i < MAX_PARTICLES; ++i )
    {
        pPointVertices->posit = g_particles[i].m_vCurPos;
        pPointVertices->color = D3DCOLOR_COLORVALUE( 1.0f, 
                                                      0.0f, 
                                                      1.0f, 
                                                       1.0f );
        pPointVertices++;
    }

    m_particleVertexBuffer->Unlock();
	
	//
	// Render point sprites...
	//

    m_pD3DDevice->SetStreamSource( 0, m_particleVertexBuffer, 0, sizeof(Vertex) );
    m_pD3DDevice->SetFVF( Vertex::FVF_Flags );
	m_pD3DDevice->DrawPrimitive( D3DPT_POINTLIST, 0, MAX_PARTICLES );

	//
    // Reset render states...
	//
	
    m_pD3DDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, FALSE );
    m_pD3DDevice->SetRenderState( D3DRS_POINTSCALEENABLE,  FALSE );

    m_pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
    m_pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}



My particles should be fushia but they're grey (the color in the texture). I'm totally stumped on this one, I don't think it's something in that render code, it's probably something from somewhere outside of my particle system causing problems.

Share this post


Link to post
Share on other sites
after messing around some more I found out if I DONT render one of my mesh's then my point sprites dont show up at all (this is odd since the two should be completely seperate)

Heres the mesh rendering function, if I don't call it, then my point sprites dont show up at all:


void DXEngine::RenderEarth()
{
D3DXMATRIX matEarth, matScale, matRotateY, matOld;

D3DXMatrixIdentity(&matOld);

// Calculate the earths position
D3DXMatrixRotationY(&matRotateY, timeGetTime()/1000.0f);
D3DXMatrixScaling(&matScale, 2.0f, 2.0f, 2.0f);


D3DXMatrixMultiply(&matEarth, &matScale, &matRotateY);

//Render the earth
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matEarth);
m_dwTotalPolygons += m_pEarth->Render();

m_pD3DDevice->SetTransform(D3DTS_WORLD, &matOld); // Reset the world.so everything doesn't rotate together.


}


DWORD CMesh::Render()
{
if(m_pMesh != NULL)
{
for(DWORD i = 0; i < m_dwNumMaterials; i++)
{
m_pD3DDevice->SetMaterial(&m_pMeshMaterials[i]);
m_pD3DDevice->SetTexture(0, m_pMeshTextures[i]);

m_pMesh->DrawSubset(i);
}

return m_pMesh->GetNumFaces();
}
else
{
return 0;
}
}


Share this post


Link to post
Share on other sites
*evil laughter* YESSSS!! alright I solved my own problem. The lighting made all my sprites APPEAR grey. I disabled lighting and now they change color. Which brings me to my next question, how do I make light not affect my point sprites?

Share this post


Link to post
Share on other sites
Quote:
Original post by xegoth
*evil laughter* YESSSS!! alright I solved my own problem. The lighting made all my sprites APPEAR grey. I disabled lighting and now they change color. Which brings me to my next question, how do I make light not affect my point sprites?


You have to disable lighting like you did. Then after rendering th eparticles, just re-enable the lighting.

Share this post


Link to post
Share on other sites
Do you want to know how to keep the lighting so that it affects the particles, yet still be able to modify their color? Sure you do! :) Well, I can't remember. But it's all in how you set your render states and texture stages up. You want to modulate the texture with the diffuse color from the vertex, that much is a given. But then you want to modulate that new color with the value produced by the light. Or vice versa, maybe you have to take the light modulated with texture, then modulate that final value with the diffuse color from the vertex. Does anyone know off the top of their head what the code is for that? I don't have time to look it up right now and I don't want to tell it to you wrong. I think you have to take the texture color from stage 1, where texture is modulated with light, then enable texture stage 2 to modulate with diffuse color for the final color.

Chris

EDIT: I just looked into it, and specifying DIFFUSE as your parameter for a texture stage will use the diffuse color in your vertex FVF structure if lighting is disabled. It will use the result from lighting if it is enabled. So I have no idea how you could combine that with the vertex color and the texture color too. Perhaps if the vertex color is the same everywhere, you could just specify FORCE_DWORD and set it to the color and stick it into a texture stage state and modulate it with the output from DIFFUSE X TEXTURE.

Share this post


Link to post
Share on other sites

This topic is 4862 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.

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