Skip to content

Instantly share code, notes, and snippets.

@roxlu
Created June 16, 2012 23:28
Show Gist options
  • Save roxlu/2942828 to your computer and use it in GitHub Desktop.
Save roxlu/2942828 to your computer and use it in GitHub Desktop.
Fixing wierd edges with transparent billboarded particles
void GlowiesManager::draw(const Mat4& pm, const Mat4& vm, const Vec3& right, const Vec3& up) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// IMPORTANT: disable depth mask writing to prevent wierd looking edges while using transparency!
// ------------------------------------------------------------------------------------------------
glDepthMask(GL_FALSE);
for(vector<GlowiesData>::iterator git = collections.begin(); git != collections.end(); ++git) {
GlowiesData& gd = (*git);
Glowies& gl = *gd.glowies;
glBindVertexArrayAPPLE(gd.vao); eglGetError();
gd.shader->enable();
gd.shader->uniformMat4fv("u_projection_matrix", pm.getPtr());
gd.shader->uniformMat4fv("u_view_matrix", vm.getPtr());
// set texture.
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, gd.tex);
gd.shader->uniform1i("u_texture", 2);
for(vector<Particle*>::iterator pit = ps.particles.begin(); pit != ps.particles.end(); ++pit) {
Particle& p = *(*pit);
gl.position = p.position;
gl.sort();
for(vector<Glowy>::iterator glit = gl.glowies.begin(); glit != gl.glowies.end(); ++glit) {
Glowy& glowy = (*glit);
Mat4 model_matrix;
model_matrix.setBillboard(right, up);
model_matrix.setPosition(glowy.position);
model_matrix.scale(glowy.radius);
Quat q;
q.rotate(glowy.rotation * DEG_TO_RAD,0,0,1);
model_matrix = model_matrix * q.getMat4();
gd.shader->uniform1f("u_alpha", glowy.agep);
gd.shader->uniformMat4fv("u_model_matrix", model_matrix.getPtr());
glDrawArrays(GL_QUADS, 0, 4);
}
}
gd.shader->disable();
glBindVertexArrayAPPLE(0); eglGetError();
}
glDepthMask(GL_TRUE);
}
@roxlu
Copy link
Author

roxlu commented Jun 16, 2012

Result w/o disabling depth mask:

Result with disabling depth mask.

Using particle image:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment