exposions with particles look bad-FIXED BUT WHY ?!

Started by
15 comments, last by deffer 18 years, 9 months ago
Explosion as I require and as occasionally works in my game : http://myweb.tiscali.co.uk/3drocknroll/explodeblur.bmp However, with the same explosion class and the same settings it most often looks like this: http://myweb.tiscali.co.uk/3drocknroll/explospoor.bmp note the black quad around each particle. So what am i doing wrong ? here is the code I use to draw the explosion:

  glDisable(GL_FOG);
  glDisable(GL_DEPTH_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
 
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, m_texture);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  glEnable(GL_COLOR_MATERIAL);

  scalar_t size;
  CVector pos;
  CVector temp;

  glBegin(GL_QUADS);
  for (int i = 0; i < m_numParticles; ++i)
  {
    size = (scalar_t)m_particleList.m_size/2;
    pos = m_particleList.m_pos;
    glColor4fv(m_particleList.m_color);

    glTexCoord2f(0.0, 0.0); 
	temp=pos + -size*(right+up);
	glVertex3f(temp.x,temp.y, temp.z);

    glTexCoord2f(1.0, 0.0); 
	temp=pos+size*(right - up);
	glVertex3f(temp.x, temp.y, temp.z);

    glTexCoord2f(1.0, 1.0);
	temp=pos+size*(right + up);
	glVertex3f(temp.x, temp.y, temp.z);

    glTexCoord2f(0.0, 1.0); 
	temp=pos+size*(up - right);
	glVertex3f(temp.x, temp.y, temp.z);
  }
  glEnd();

  glDisable(GL_TEXTURE_2D);
  glDisable(GL_BLEND);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_FOG);


[Edited by - ade-the-heat on July 22, 2005 7:57:56 AM]
Advertisement
I don't think you need that glEnable(GL_COLOR_MATERIAL) there.

It looks like an improper glBlendFunc state - but that's weird because you seem to be setting the correct blend func before you render your particles.

explicitly disable lighting and color materials, see if that helps you.

EDIT:
embedded in html tags for clicking fun :)
correct particle rendering: clicky

incorrect particle rendering: clicky
Does your image have an alpha channel?
hmmm made no difference.

However, I notice the following: the quads surrounding each particle only appear when the background is the skybox. eg when the background to the particle is a wall or the terrain then it's fine.

So I guess this means the skybox is done wrong in some way.

skybox code:

	glShadeModel(GL_SMOOTH);//smooth	glDisable(GL_BLEND); //am disable	glEnable(GL_TEXTURE_2D);		glDepthMask(GL_FALSE);  //don't write to depth buffer		glDisable(GL_LIGHTING); //so join between box isn't seen		glBindTexture(GL_TEXTURE_2D, m_toptexture);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(0.0f, 1.0f); glVertex3f(maxx, maxy, maxz);			glTexCoord2f(0.0f, 0.0f); glVertex3f(minx, maxy, maxz);			glTexCoord2f(1.0f, 0.0f); glVertex3f(minx, maxy, minz);			glTexCoord2f(1.0f, 1.0f); glVertex3f(maxx, maxy, minz);		glEnd();		//back		glBindTexture(GL_TEXTURE_2D, m_backtexture);		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(0.0f, 0.0f); glVertex3f(minx, miny, maxz);			glTexCoord2f(0.0f, 1.0f); glVertex3f(minx, maxy, maxz); 			glTexCoord2f(1.0f, 1.0f); glVertex3f(maxx, maxy, maxz);			glTexCoord2f(1.0f, 0.0f); glVertex3f(maxx, miny, maxz);		glEnd();					//front		glBindTexture(GL_TEXTURE_2D, m_fronttexture);		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(0.0f, 0.0f); glVertex3f(minx, miny, minz);			glTexCoord2f(1.0f, 0.0f); glVertex3f(maxx, miny, minz); 			glTexCoord2f(1.0f, 1.0f); glVertex3f(maxx, maxy, minz);			glTexCoord2f(0.0f, 1.0f); glVertex3f(minx, maxy, minz);		glEnd();				//LEFT		glBindTexture(GL_TEXTURE_2D, m_lefttexture);		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(0.0f, 0.0f); glVertex3f(minx, miny, maxz);			glTexCoord2f(1.0f, 0.0f); glVertex3f(minx, miny, minz); 			glTexCoord2f(1.0f, 1.0f); glVertex3f(minx, maxy, minz);			glTexCoord2f(0.0f, 1.0f); glVertex3f(minx, maxy, maxz);		glEnd();		//right		glBindTexture(GL_TEXTURE_2D, m_righttexture);		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(0.0f, 0.0f); glVertex3f(maxx, miny, minz);			glTexCoord2f(1.0f, 0.0f); glVertex3f(maxx, miny, maxz); 			glTexCoord2f(1.0f, 1.0f); glVertex3f(maxx, maxy, maxz);			glTexCoord2f(0.0f, 1.0f); glVertex3f(maxx, maxy, minz);		glEnd();		//bottom		glBindTexture(GL_TEXTURE_2D, m_bottomtexture);		glBegin(GL_QUADS);					// Assign the texture coordinates and vertices for the 			glTexCoord2f(1.0f, 0.0f); glVertex3f(minx, miny, maxz);			glTexCoord2f(1.0f, 1.0f); glVertex3f(maxx, miny, maxz); 			glTexCoord2f(0.0f, 1.0f); glVertex3f(maxx, miny, minz);			glTexCoord2f(0.0f, 0.0f); glVertex3f(minx, miny, minz);		glEnd();		glEnable(GL_LIGHTING); //so join between box isn't seen		glDepthMask(GL_TRUE);  //write to depth buffer

Are you rendering the skybox before or after the particles?
You should probably disable depth writes while rendering your particles as well.
I do disable depth writes for the particles (see code)
The sky box is drawn before anything else, then I draw the terrain, then later on I draw explosions.
Shouldn't it be:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

instead of:
glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);


With the latter, it's a strong suggestion that your skybox somehow has alpha == 0. Don't know how you could do that unintentionaly, though... :/
With that blendfunc, if the skybox had an alpha of 0, it'd mean that the skybox would make no contribution to the final fragment color. But it looks like (and it's hard to tell from such a small screenshot) there's blending between the skybox and particle texture.

If the skybox alpha is something between 0 and 1 (exclusive) though, that could explain it.
I tried the replacement value GL_ONE_MINUS_SRC_ALPHA and it was worse !!
In addition the skybox has no alpha channel - it is a simple bitmap.

Just in case I've done it all wrong - the particle bitmap is loaded without an alpha channel as well -eg the black parts to the bitmap aren't set to see through.

NOW! - I just changed the particle bitmap to have an alpha channel - it made no difference - the same as before.

This topic is closed to new replies.

Advertisement