Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411583 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 06, 2024, 05:38:51 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Glowy vectors in OpenGL via blending
Pages: [1]
Print
Author Topic: Glowy vectors in OpenGL via blending  (Read 3527 times)
JamesGecko
Level 3
***



View Profile WWW
« on: May 24, 2010, 10:17:31 PM »

So, I'm making, um, a dual stick shooter that will look somewhat similar to Geometry Wars. (In my defense, it will play completely differently.)

But there's an issue. This is what I'm currently rendering.


This is what Geometry Wars looks like.


Look at where the lines intersect. In mine, they just blend to a brighter color. In Geometry Wars, they blend to white. How does it do that?

Originally, I had the color set to glColor4f(0.0f,1.0f,0.0f,1.0f), and I couldn't tell that there was any blending going on at all. I'd assumed that when the two greens summed to more than 1.0f, the remainder would be distributed among the other two colors, so that the render would effectively be using glColor4f(0.5f,1.0f,0.5f,1.0f) where the lines intersected. How would one go about setting it up to work like that? Would I have to learn how to write a shader?

Here's where I initialize the relevant stuff in my code:
Code:
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_CULL_FACE);
glDisable(GL_LIGHTING);

glEnable(GL_LINE_SMOOTH); //antialiasing
glEnable(GL_BLEND); // Turn Blending On
glBlendFunc(GL_ONE, GL_SRC_ALPHA); //Additive blending

Here's my drawing function:
Code:
glColor4f(0.0f,0.7f,0.7f,1.0f); //Aqua

glLineWidth(3.0f);
glPushMatrix();
glTranslatef (x, y, 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
std::list<Coord>::iterator it;
for(it = points.begin(); it != points.end(); ++it) {
glVertex2f(it->x, it->y);
}
glEnd();
glPopMatrix();
Logged
Pishtaco
Level 10
*****


View Profile WWW
« Reply #1 on: May 24, 2010, 10:39:20 PM »

If you look at the colour values in the geometry wars screenshot, it looks like he's using straight additive blending, but his cyan is roughly 50% red, 100% green and 100% blue so an overlap gives you white.


(Edited because I realized that I've never done actual blending with a shader)
« Last Edit: May 24, 2010, 10:46:29 PM by Pishtaco » Logged

JamesGecko
Level 3
***



View Profile WWW
« Reply #2 on: May 24, 2010, 10:58:13 PM »

Doh! Facepalm

That makes a lot of sense. Thank you.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #3 on: May 25, 2010, 12:39:32 AM »

Yep your colours are too dark.

GW will probably use a shader to add the glowy bloom effect (this will be well documented on the web). The way I did it in Eufloria was to draw objects using a gradient texture instead of flat polygons. It works well apart from where lines meet, where you either have to cap your line segments which isn't cheap, calculate intersecting angles which also isn't cheap, or stomach some unpleasant overlap. Also it means that you can't do trapezoids without some screwed up projection maths to get the texture mapping right.
Logged

Golds
Loves Juno
Level 10
*


Juno sucks


View Profile WWW
« Reply #4 on: May 25, 2010, 01:09:19 AM »

Like hao said, Geometry wars is probably just doing a pixel shader to gaussian blur the screen and composite the result over the original with add blending.

You can do this kind of glow effect without shaders by rendering your full scene to an FBO, then drawing to the screen a full-screen quad with the fbo texture applied.  On top, draw several staggered full-screen polys offset by small amounts to the left/right/top/bottom, with lower opacity and add blending.
Logged

@doomlaser, mark johns
JamesGecko
Level 3
***



View Profile WWW
« Reply #5 on: May 25, 2010, 12:35:52 PM »

Interesting. I wanted this to run well on low end machines, so I was just planning on generating the blur once per object type, then having it on a transparent texture underneath each object with blending. Wouldn't blurring the FBO each frame slow things down a bit? I guess I'll have to mess around and see if there's a significant difference to how well each method runs on a netbook.
Logged
Golds
Loves Juno
Level 10
*


Juno sucks


View Profile WWW
« Reply #6 on: May 25, 2010, 03:22:18 PM »

Most machines from the last 5 years or so will have support for FBOs.  Heck the iPhone 1G even does.

You can use prebaked blurry textures as another cheap trick, the problem is that when they overlap, you'll double the glow at areas of intersection.  This may not be a big deal, especially if you do glows for the entirety of your vector ships.  But if you're constructing everything out of lines, then you'll see the increased glow at the line intersections.
Logged

@doomlaser, mark johns
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #7 on: May 26, 2010, 03:28:29 AM »

one thing you can do instead of blurring the fbo is to render the finished screen to a smaller buffer, and then scale up and let the bilinear filtering do the blurring for you. cheap
Logged

Christian Knudsen
Level 10
*****



View Profile WWW
« Reply #8 on: May 26, 2010, 04:13:54 AM »

The problem with that approach is that objects at the center of the screen will have less "glow" than objects at the edge...

EDIT: I think I misunderstood your post. I read it as if you'd render the scaled FBO under the normal render to create an edge glow, but if you meant scaling up to apply an overall blur, then you're right.
« Last Edit: May 26, 2010, 04:44:40 AM by chrknudsen » Logged

Laserbrain Studios
Currently working on Hidden Asset (TIGSource DevLog)
raigan
Level 5
*****


View Profile
« Reply #9 on: May 26, 2010, 06:38:53 AM »

one thing you can do instead of blurring the fbo is to render the finished screen to a smaller buffer, and then scale up and let the bilinear filtering do the blurring for you. cheap

Seconded -- GW2 is possibly doing some sort of "real" blur (or at least, something that makes me feel like my eyes are coated in vaseline), but if you look at the screenshot that the OP posted, the "blur" in GW1 is almost definitely render-low-rez-then-upscale.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #10 on: May 26, 2010, 07:01:42 AM »

Cunningly hidden/accentuated by the grid in the background.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic