We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › point volumetric lighting
Page Index Toggle Pages: 1
point volumetric lighting (Read 2024 times)
point volumetric lighting
Nov 11th, 2008, 12:46am
 
Hi,

I had been trying to search for examples for the 'firefly' effect (e.g. similar to this: http://vimeo.com/653177  from http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Exhibition;action=display;num=1201858601).

I had tired searching so hard and it seems like there is no way of doing such effect from native processing API (I will be happy if anybody tell me i am wrong!) - can anybody show me the light to the solution?

I wouldnt mind a simple code/pseudo-code example with some references, the above post referring to 'semi-transparent object' without references was just a bit beyond me :S

Many thanks!
Re: point volumetric lighting
Reply #1 - Nov 11th, 2008, 1:22am
 
hi.

i dont really understand your question, what do you mean by the "firefly effect"? is it the glowy visuals?

if thats the case it is done using additive blend in opengl.
just add this to your code
Code:


import processing.opengl.*;
import javax.media.opengl.GL;

PGraphicsOpenGL pgl;
GL gl;

void setup(){
//just put what you would normaly put here
}

void draw(){
//here you just add this code:
pgl = (PGraphicsOpenGL)g;
gl = pgl.beginGL(); //getting the GL object used by processing
gl.glEnable(GL.GL_BLEND);  // enabling blend
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); //defining additive blend
pgl.endGL();

//now everything you draw will be drawn using additive blend
//making glows more glowy!
}


if this is not what you are asking for then i dont know... Smiley


Re: point volumetric lighting
Reply #2 - Nov 11th, 2008, 2:00am
 
Thank you pelintra... I am quite new to both opengl and processing so I might be using the wrong terms.  Essentially I am trying to achieve what the light effcect of the demo above (http://vimeo.com/653177 )

I tried to modify things a bit based on your code but without putting on a background the screen keeps flickring when i tried it.  For example:

Code:

import processing.opengl.*;
import javax.media.opengl.GL;

PGraphicsOpenGL pgl;
GL gl;

void setup(){
//just put what you would normaly put here
size(400,400,OPENGL);
}

void draw(){
 //XXX: should this be here?
 //  if i dont put on background, screen will flickr
 //background(0);
//here you just add this code:
pgl = (PGraphicsOpenGL)g;
gl = pgl.beginGL(); //getting the GL object used by processing
gl.glEnable(GL.GL_BLEND);  // enabling blend
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); //defining additive blend
pgl.endGL();

//now everything you draw will be drawn using additive blend
//making glows more glowy!  

//XXX: this is just a solid shape - doesnt glow :(
beginShape(TRIANGLE_FAN);
vertex(57.5, 50);
vertex(57.5, 15);
vertex(92, 50);
vertex(57.5, 85);
vertex(22, 50);
vertex(57.5, 15);
endShape();
}


Please let me know if what I am doing wrong!

Thanks!

p.s. found an example using leprcolor (http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1186336072) to do such effect - however I am trying to visualize large amount of data and would love to know if there's a clever way to make things glow in opengl
Re: point volumetric lighting
Reply #3 - Nov 11th, 2008, 3:56am
 
Pelintra is correct. You want additive blending on billboards (Quads that always face the camera) with a feathered semi-transparent texture. If you decide you like regular alpha transparency better than additive blending, you'll want to render the transparent sprites from back to front order in relation to the camera. (Transform all sprite positions into camera space and sort based on z value) However if you just stick to additive blending this isn't an issue. Also with additive blending make sure to disable depth tests when rendering so you don't render a close sprite first and have background sprites not render over it.

Unfortunately if you want to have non-transparent objects in the scene you'll still need to sort your billboards from back to front even if you're using additive blending. In that case you render all the non transparent objects first, then you render transparent objects with depth checks on from back to front. This way any transparent objects that fall behind solid objects will not draw but they will still draw over previously drawn transparent objects.

Hope that info helps! Transparency is one of those things that seems easy at first but can really be a pain to do right.

Jack
Re: point volumetric lighting
Reply #4 - Nov 11th, 2008, 7:57pm
 
additive blend means all objects with transparency that overlap will result in colors that are added together and clipped at white. the rest of your sketch should be exactly the same, just adding that code will make everything more glowy. and webDext is right you should disable depth sorting, it will make things more glowy and eliminate some image artifacts that appear if you dont. i just forgot to add that in the previous post Tongue in your draw function just add this line
Code:

gl.glDisable(GL.GL_DEPTH_TEST);


you should keep the beckground() in there.
try drawing some semi transparent overlapping shapes with and without the additive blend, you should see a difference.
also check this mini tutorial byt robert hodgin (flight404)
http://www.flight404.com/blog/?p=71

and you can also look in his blog for some source codes, he has some stuff in there that uses additive blend and png images to draw particles.

hope that helps Wink

rui


Page Index Toggle Pages: 1