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 › Are alpha gradients possible
Page Index Toggle Pages: 1
Are alpha gradients possible? (Read 913 times)
Are alpha gradients possible?
Jul 22nd, 2008, 4:00am
 
I have a 3D scene (using OpenGL) that draws images and rotates them where they are drawn.  The images display one circle each, but when the images spin you can still see the rectangular edges of the image.  Is there a way I can do some sort of radial alpha gradient where the center of the image is completely opaque but gets more transparent as it radiates out to the edges?  

Or can someone suggest another method for dealing with this?
Re: Are alpha gradients possible?
Reply #1 - Jul 22nd, 2008, 11:10am
 
You can do that with images in PNG format. It has alpha support by default.

You can do that within Processing too, using the mask() method, but it's going to be way more ressource-consuming :
http://dev.processing.org/reference/core/javadoc/processing/core/PImage.html#mas...
Re: Are alpha gradients possible?
Reply #2 - Jul 22nd, 2008, 3:24pm
 
[quote author=antiplastik link=board=OpenGL;num=1216692051;start=0#1 date=07/22/08 at 11:10:55]You can do that with images in PNG format. It has alpha support by default.

How do I adjust the alpha in the image without using a Processing algorithm?
Re: Are alpha gradients possible?
Reply #3 - Jul 23rd, 2008, 12:08am
 
Many image manipulation programs can do that. For instance you can use GIMP which is open-source software :
http://www.gimp.org/
Re: Are alpha gradients possible?
Reply #4 - Jul 23rd, 2008, 8:43pm
 
Aha!  That worked perfectly!  I was able to use GIMP to make everything that was a certain color be transparent, but in the sketch I'm still getting some issues.  Alot of the images look perfect now without their black rectangles around them, but there are still quite a few who don't seem to be "registering" the alpha values on their outer edges and you can still see the image's rectangular borders (even though all of the images drawn use the same source image).  Could this be an issue with resources?  Perhaps my system is just not keeping up with all of the alpha values?
Re: Are alpha gradients possible?
Reply #5 - Jul 23rd, 2008, 9:39pm
 
Quote:
but there are still quite a few who don't seem to be "registering" the alpha values on their outer edges and you can still see the image's rectangular borders (even though all of the images drawn use the same source image).

That's weird. I've made some tests translating and rotating a transparent png and I don't get these edges. Can you upload your source image? Or some code? Or both Smiley (or a screen capture, that could help)
Re: Are alpha gradients possible?
Reply #6 - Jul 23rd, 2008, 10:35pm
 
Sure, and thanks for your help, antiplastik.  First of all, you can download a screen shot of the sketch running as well as my source image here:

http://ilocker.bsu.edu/users/drschultz/world_shared/Processing/

As for the code, it's a fairly large project, but here are some relevent pieces:

//////////////////////////////
PImage img;

void setup(){
 size(screen.width, screen.height, OPENGL);
 hint(ENABLE_OPENGL_4X_SMOOTH);
 frameRate(30);
 . . .  
 img = loadImage("finalglowgradientalpha.png");
 . . .
}

//then the img is passed through a class which passes it to another class

//the constructor copies it
OrganicMotion(float _x, float _y, PImage _img){
 . . .
 img = _img;
}

/*then the image is oriented in the 3D space and displayed at the location of a particle where it rotates around it's own center axis...*/

pushMatrix();
   translate(particles[particles.length-1].position().x(),
                    particles[particles.length-1].position().y(), z2+4);
   rotateZ(radians(angleZ+=10));
   rotateX(radians(90));
   image(img,-2,-2,4,4);
   popMatrix();
/////////////////////////////////

You can see in the screenshot that quite a few images are not displaying correctly.  Not sure what is going on.  Thanks again for you help.



Re: Are alpha gradients possible?
Reply #7 - Jul 23rd, 2008, 11:46pm
 
Some images render correctly and some others don't. I've found a bug which may be related to your issue :

Quote:
Objects with alpha (lines or shapes with an alpha fill or stroke, images with alpha, all fonts) are displayed in OpenGL (and P3D, in fact) based on their drawing order. This creates some annoying effects like making things opaque if they're drawn out of order with objects above or beneath them.

http://dev.processing.org/bugs/show_bug.cgi?id=176

But I don't see any workaround at the moment... :-/
Re: Are alpha gradients possible?
Reply #8 - Jul 24th, 2008, 12:55am
 
Ah, yes, I read one of those related posts a while ago and that would make sense for this project.  Well...I guess reordering the draw methods wouldn't work here because my entire scene can rotate and be navigated, so the order would be constantly changing.  

Yuck.

Well, I'll keep working on it to try and find something that works.  Thanks for your attempts to help, antiplastik.
Re: Are alpha gradients possible?
Reply #9 - Jul 24th, 2008, 8:31am
 
i think these are drawn as textures on a quad. maybe try doing that by hand and set the fill color of the quad to be transparent.

Code:

import processing.opengl.*;

size( 400, 400, OPENGL );

PImage img = loadImage( "finalglowgradientalpha.png" );

translate( width/2, height/2 );
scale( 10 );
rotateY( random( TWO_PI ) );

noStroke();
fill( 255,255,255,0 );

beginShape();
texture( img );
// x, y, z, u, v
// u, v, set which part of the image is pinned to that point
vertex( -2, -2, 0, 0,0 ); // upper left
vertex( 2, -2, 0, img.width, 0 ); // upper right
vertex( 2, 2, 0, img.width, img.height ); // lower right
vertex( -2, 2, 0, 0, img.height ); // lower left
endShape( CLOSE );



good luck
F

Re: Are alpha gradients possible?
Reply #10 - Jul 24th, 2008, 8:18pm
 
Great idea, fjen.  But alas, it didn't help.  I think no matter what, it's still that drawing order that's screwing everything up. So no matter what is being drawn, the alpha values still aren't going to come out right.  

The best I could do is make the color gradient on the png reach further out toward the edges, eliminating as much of the black as possible, therefore eliminating as much of the "100% transparent" area as I could, since that seemed to be the most troublesome when running the sketch.  It did help, and for the purpose of this installation, I think I should get a fair result.  i.e. No one should really be squinting at the screen trying to pick up on this stuff.
Re: Are alpha gradients possible?
Reply #11 - Jul 24th, 2008, 11:26pm
 
I'm not sure if it works in all modes, but try hint(ENABLE_DEPTH_SORT);
Re: Are alpha gradients possible?
Reply #12 - Jul 24th, 2008, 11:51pm
 
Yep, already tried that when I saw it on the bug page.  Didn't work.
Page Index Toggle Pages: 1