Archive for March, 2007

Mini-tutorial: Additive Blending

Saturday, March 31st, 2007

I have been getting a few requests lately about the hows and whys of additive blending so I thought I would whip up a quickie little tutorial to get those interested parties on the path to easy glowiness. But first, the standard disclaimer.

I AM NOT A GOOD TEACHER!!! Here is why. I dont really know OpenGL. I dont know much about the limitations of JOGL either. What I do know is that with Processing, I can make OpenGL calls that can do great things but as for why they work or why they might be better or why I didnt optimize them further, the simple answer is that I am learning just like the rest of you. So please keep these 2 points in mind when you read the rest of this post.

1) If you have problems with the source code, please research the answer yourself. I wont be able to help you understand why you are getting an error with Processing v.123 on Windows running Vista with 2 webcams attached and Java version 1.4 with a cat on your lap and the right mouse button pressed. I would probably just refer you to the Discourse section of Processing.org.

2) If you can improve this code or help me understand more about why it works, please post your comments here instead of emailing me so that others can benefit from your knowledge. Im sure there are ways to make the following info much tighter and stronger… so chip in your 2 cents so we can all be a bit richer.

On the left is a screengrab from the supernova project without any blending. On the right, I have added additive blending and disabled the depth test. Suddenly, the orb glows are more glowy and the overlap issue goes away entirely. Lets look at the code.

First, you will need to make a new PGraphicsOpenGL and GL object. Before you can do this, you need to make sure you import the proper libraries. Stick this code in with your other import statements if you have any. The top one makes sure you can use the OPENGL renderer specified in your size() method, and the second is the JOGL stuff you will need.

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

Then you make your PGraphicsOpenGL and GL objects.

PGraphicsOpenGL pgl;
GL gl;

In your setup code, you will need to define these pgl and gl objects so put in the following after your size() method.

pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;

Almost there! The only thing left is to do the additive blending magic. It is soooo easy! You will kick yourself. Stick this at the beginning of your draw method.

pgl.beginGL();

// This fixes the overlap issue
gl.glDisable(GL.GL_DEPTH_TEST);

// Turn on the blend mode
gl.glEnable(GL.GL_BLEND);

// Define the blend mode
gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);

pgl.endGL();

Voila! Glowy good times. The BlendFunc takes several parameters. Check here for a sample as to why I dont bother getting too invested in the ‘why’ this works.

Go and glow.

UPDATE (April 4, 2007)…………………………………………….
Got a correction from up high. Mr. Fry informs us that:
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;

should go inside draw(). in fact, it should just look like:

void draw() {
pgl = (PGraphicsOpenGL) g; // g may change
gl = pgl.beginGL(); // ho ho fancy

// blah blah blah
}

because in some (rare) cases, ‘g’ will have changed, and in others, the
‘gl’ object associated may also have changed (so beginGL() is set to
return the gl object to insulate you from such cases).

Danke Mr. Fry.

Birds!!!

Wednesday, March 21st, 2007

No video for this one yet. Just a quickie screen grab of the flocking project with proper birdage. For this version, which features 3,000 or so flocking objects, I took 7 different silhouette images of birds in mid flight (from various Flickr photos) and created an image array. Each flocking object chooses a random image every frame. So yeah, they kinda flap around, but it is totally faked… for now. I want to eventually model out a simple bird in 3D and let it flap about with texture mapped wings. But that is for another day.

For now, I need to make the flocking behaviour a little less clumped. They tend to form vortices and linear strings so I must readdress the mechanics behind the movement before I get bogged down with the actual bird images.

Green thumbs down

Friday, March 16th, 2007

I will begin by reposting something I had on my other short-lived attempt at blogging. I tried Vox for a while but it didn’t stick. Nothing wrong with it. Just wasn’t in the mood to keep it updated.

————————————————————————–
The first time I managed to find myself in Golden Gate Park, I hit the Conservatory of Flowers. I didnt know what to expect, aside from flowers of course. It was humid. Very very humid. There were some pink things. And ooh, look, a pool. Where are the frogs, I wondered. No butterflies? How odd. Ha, that one looks like a penis!

Then I saw them. The orchids. The resplendent orchids, all dewy and inviting. I thought, ‘If that is what vaginas actually looked like, then let me at ‘em!’

Dont get me wrong. I am not going to sit here and tell you that every orchid is a beauty to behold. Some of them are downright nasty. Weird curly hairs and pustules… Yuck.

A few weeks later, I found myself walking up Fillmore in a martini haze. It was a Saturday afternoon and Lance and I wanted some Kiehls. We passed by a hole-in-the-wall flowery. Er, a flowerery. A flower place. There in the window was the most lovely pair of beautifully potted white phalaenopsiseseseseses. ‘Orchids’ to the lay person.

I had to have them. I thought, ‘OMG, LOL, they are so purty!!! :P

But they wanted nothing to do with me. Even as the cabbie with the horribly long nails was driving me and my three loves back to my apartment, they began to wilt. They lost their sheen. Maybe they didn’t want me to be their care-giver. Maybe they were just reacting to the sweaty cab driver, and seriously, his nails were like talons! Maybe they wanted nothing to do with Duboce Triangle and my fantastic city view.

Three weeks later, they were dead.

I tried to help them. Really I did. When their leaves began to yellow, Lance convinced me to go back to the flowerery and asked them what might be wrong. An employee with a harsh accent said, “Hmm, yellow leaves? That either means they don’t have enough water or they have too much water.”

Thanks for that, Mr. german flower guy. Huge help. What was I to do? Should I starve one of water and not the other to see which bounces back and which takes a turn for death? I couldn’t separate them. I just couldn’t. They were bought together so they should die together if that is to be their fate. I decided it was an abundance of water which was causing them stress so I cut back on the wetness.

I was wrong.

Here they are. Dead. Sure, one still has a wrinkled blossom clinging to it, but not submitting to gravity isn’t the same as being alive and happy.

I am not yet sure if I will attempt orchids again. They seem a bit too complicated and are difficult to keep healthy, which is pretty much my understanding of vaginas as well. Small world.
————————————————————————–

But if you think my days of being a plant killer are long gone, much like the sublime white blossoms of my short lived affair with the orchid, think again. I decided to give it another go. Ficuses, I thought! If they can thrive under fluorescents in the windowless waiting room of my dentist, how could I go wrong!

But wrong I did go.

Here is the first to go. A simple ficus which was in its prime before it ended up back at Chez Hodgin. It was dead within 2 weeks. First the leaves lost their spunk, then they began to discolor, and eventually, they dropped to the ground leaving brittle branches that mock.

Following close behind is his cousin, the variegated ficus. I had really high hopes for him. He made it through the first 2 weeks! That is something! He did do a little drooping in the first few days but eventually began to thrive. I even did a little bonzai-style trimming to the branches to give him the proper shape. He loved it! He had a beautiful profile and spunky leaf patterning. He was my bestest plant friend.

Was. A week ago, he started to show the signs of impending doom. The leaves started to sag, the colors started to fade, and here he is… the bastard!

Not all is lost. My philodendron is still doing well. But as is my understanding, you cant really kill the philo. It is the cockroach of the plant work. Starve it, pee on it, tell it there is no God… it will still grow with an intense indifference to the ills of the world.

Hang in there philo. Dont leave me like the others did. I couldn’t bear it.

Oh, I almost forgot…

Tuesday, March 13th, 2007

I made this a couple days ago and forgot to post it. Its not that great… I think the last couple experiments from the supernova project came out better than this one, but it does have a couple nice moments so I thought I would go ahead and post it anyways.

The audio is by Helios.

Click here to view the quicktime. It fairly big… sorry!

Flocking

Tuesday, March 13th, 2007

Its a bit hard to see what is going on with this piece in terms of movement so I whipped up this quickie video to show off the flocking behavior of the particles moving in the Perlin noise flowfield.

There are 10,000 objects moving about this space. I love that they occasionally get caught up in eddies within the flowfield and start travelling in a circle. Have a peek. Dont worry, this one is only 9 MB. Or you can watch the Vimeo version below.

Flocking in a flowfield on Vimeo

Flow

Tuesday, March 13th, 2007

Good ol’ Shiffman. Hooked me up once again. After a little email back-and-forth, I tweaked the flowfield project and got a nice speed boost. I was going about things all wrong. Well, not entirely wrong, but I was going from A to B by visiting C briefly.

In the original version, for some reason, I decided the best way to deal with the flowfield was to make a ton of vectors and stick them in the space. These vectors are stationary and only contain velocity information. I would use Perlin noise to adjust each vector’s velocity and just leave them there. Pretty much an invisible 3D array of floating arrows. I would then throw a bunch of objects in this 3D array and have each object check the nearest vector for its velocity information and apply this information to the objects own velocity.

Turns out, this was way more work than I needed. Instead, I should simply apply the Perlin noise data directly to my object’s velocity vectors and voila, done and done. And without needing to worry about placing thousands of vector arrows into a space that simply didnt need it. In a way, the Perlin noise data can represent an infinite space with an infinite number of vector arrows, and for cheap too.

So what you are going to see in the video is similar to the last one I posted. However, I implemented the webcam history so there is a bit more movement. This ‘history’ is basically a stack of the last 40 webcam input images. The one closest the applet camera is the newest image, the one behind it is the second oldest image, etc. The flocking ribbon forms are getting their color data from this constantly changing stack of images.

Click here to view the quicktime (40 MB).

Taking a break…

Tuesday, March 13th, 2007

The magnetosphere project was getting away from me. It happens. It was option overload. So many things I wanted to do with it. My fuses got blown. So I decided to get back to my roots.

One of my first interests when I started working with Processing was the simple beauty of Perlin noise. I am not going to get into the explanation of Perlin noise for two simple reasons.

1) Its after midnight and I should start thinking about getting to bed.
2) I dont really understand it enough to explain it.

What I can say is that noise() in Processing will give you a smoothly changing set of numbers from 0.0 to 1.0 based on Perlin’s noise algorithm. Combined with the new-found wonderfulness of Shiffman’s Vector Library for Processing, I decided to take another stab at making a 3D flowfield based on Perlin noise.

I had attempted it a couple years back and had some decent results, but the z-axis part of it never quite made it over to the left side of my brain so I shelved it for a later attempt. That attempt happened tonight.

Okay, lets see if I can explain what is going on so when you view the video linked at the end of this post, you will get what I was going for.

First, I took short movie, in this case, a movie of me waving a cellphone in front of my iSight. It was short… 33 frames. I brought these frames into Processing and put them into a PImage array. These images were then rendered out in space from back to front so I ended up with a cube of images. The point wasnt to show these images, but I put them there for effect and for testing. The actual goal was to do three dimensional flow-field painting with several thousand particles.

Okay, so I made a 3D flow-field. With any luck and a little free time, I will get into the details of it at some point this week. This flow-field basically allows me to drop objects into the space and they will move based on the 3D vector which is closest to it. Think of a 3D space filled with arrows. The arrows tell objects near them which way to travel. The orientation of these arrows is based on Perlin noise. Throw 10,000 objects into this arrow field and you end up with a nice faux-flocking behaviour.

The images come into play when I color the objects moving through this space. Each object compares its position in the 3D space with the images in the 3D space and grabs the color from the pixel it is closest to.

I did a quick render of the thousands of objects moving through this space. It turned out fairly well. The next step is to use a webcam history instead of using a precanned video. I dont think the images will be all that recognizable, but the colors will cycle nicely.

Click here to view the quicktime.

Superer-nova

Friday, March 9th, 2007

Got a quick video test of the supernova up and running. Its only a few seconds long, but I throttled back the H.264 compression so you could see the detail. It comes in at 29 MB.

Like the others, this responds to audio as well, but the video is audio-less. Since I only decided to render out a few seconds, the audio was left out. The original render was set at 2048×2048 and uses 3000 particles (stars).

There are also quite a few other graphic elements in play here. If the stars are close enough, a nearly transparent line is drawn between the two. So in the beginning when all the stars are near the center, there are thousands of line segments drawn which overlap enough to cause the bright white globe.

Additionally, there are ribbon trails. Instead of just drawing where the star used to be, it factors in the distance of the star from the center. The further away from the center, the more the ribbon pushes away from the center. That is what is causing the rainbow explosion effect.

Click here to view the quicktime. Vimeo version coming soon.

Quick update regarding bandwidth

Friday, March 9th, 2007

There has been a bit of shuffling of late. I am trying to balance quality versus filesize with my videos and by erring on the side of big beautiful quicktimes, I dug myself into a bit of a bandwidth hole. I am now using S3 by Amazon thanks to research and a good writeup by my boyfriend.

So here is a quick clickable recap if you dont want to go digging through my old posts.

Magnetosphere with audio by Trentemoller

Magnetosphere (kaleidoscope) with audio by Boards of Canada

Magnetosphere (particle emitter) with audio by Royksopp

Magnetosphere (AKA HP/Target ad) with audio by Royksopp remix by Trentemoller

The same as above, but with an audio-created diagonal line glitch

Supernova with audio by Helios

Magnetoquilt! Quiltosphere!

Thursday, March 8th, 2007

Call it what you want, but you cannot deny its complete awesomeness. The magnetosphere has been quiltified by none other than my dear mom, Yuko.

Okay, a little back story. My mom makes amazing quilts. She has been making quilts for a long time and has gotten really good at it. Hand-stitched, machine-stitched, doesn’t matter. She can knock it out of the park (hmmm, baseball metaphor to describe quilting… doubt that has been done before).

Last Christmas, we got to talking. She wanted me to design her a quilt pattern and I though, “Processing seems to be perfect for every aspect of my life, why not quilts too!”. I tossed about a few ideas but nothing seemed quite right. Then she saw one of my older magnetosphere images on flickr and said, “oooh, thats pretty. I can make a quilt out of that.”

Here is the original Flickr photo.

She was on to something. I whipped up a version of the program that made the original image and spit out a few screengrabs with different compositions. Mom choose one and started quilting. This was back in January. Right away, we ran into a little snag. She wasn’t able to find any fabric wider than 4′ to make the backing. She asked me what I wanted her to do instead, and that is when I rocked her world with 5 simple words.

How about one inch squares?

I love my mom and when she showed me the final backing, several hundred bright red one inch squares, I knew she loved me back. She probably despised me as she was sewing, but the end result was quite lovely! Textured but not distracting. And hey, it harkens back to pixels in a way, so the thematic sensibilities were enhanced.

Above, you can see the original image on the left and the final quilt on the right. Dare I say it, I think hers looks even better than mine. Processing may be powerful, but it aint got nothin on a tiny Japanese woman armed with needles and thread. Seriously though, check out the detail! Mom, you rule!

Thanks to dear dad for taking the photos for me. He even took the time to photoshop out the reflection in the mirror on the first photo. My whole family is addicted to details! Fantastic!