Reverse post glow balloon as glow effect?

Started by
1 comment, last by Mathy 13 years, 8 months ago
I am currently looking for a code that can basically add a glow to a sphere without a texture, since I have this theory that adding a texture to every sphere when there are many of them will slow things down.

So I noticed the NVidia shader called Post Glow Balloon, located here: http://developer.download.nvidia.com/shaderlibrary/webpages/screenshots/shaders/post_glowBalloon.html

This kind of creates a "force field" around my sphere, but I want it to be a glow. In other words, I want it to reverse the colors, so that the yellow-ish color is close to the sphere's center, and the black-ish color is away from the sphere.

Is there any way I can do that?

Is it recommended for me to switch to texture-based shaders and have a texture for every sphere?

I'd love your recommendations on this.
Advertisement

I can't give you specifics, but what your goal here is using the dot product of the camera's view angle and the normal vector of the 'glow' model's faces/verts to determine the alpha (or brightness in the case of an additive blend) of each vertex on the glow model.

The screenshot you have there is doing the same thing kinda, except inverted.


So, your dotproduct is from -1 to 1, where as -1 means they are exactly parallel but going in opposing directions and 1 means they are parallel but traveling in the same direction, and 0 is perpendicular..

What that demo shot is doing to calculate the alpha of the glow model is something like this:

vertex_alpha = 1 - fabs(dotproduct(vertex_normal, camera_facing));

so that basically, when the two vectors are perpendicular to eachother, it's full-alpha, and that alpha decreases as the two vectors find themselves increasingly parallel.

All you want is this:

vertex_alpha = -dotproduct(vertex_normal, camera_facing);

So that when they are perpendicular, there is no alpha, and when they are parallel and traveling in opposite directions, then they are full alpha.


The trouble with this is that if you draw your glow ontop of your sphere, you won't see the sphere underneath because it will be covered by the glow. So you'll have to do some other tricks. I would just draw the sphere after the glow if my scene wasn't particularly complicated. Or I would just blend the glow additively (glBlendFunc(GL_ONE, GL_ONE)) and use vertex_alpha to scale the color of my glow, and modulate it by 0.25 or something so that it doesn't overwhelm the screen pixels into whiteness.

Oh, and another trick with additive blending is make sure you don't have any zeros in any of your RGB components so that as the color blends additively it can ultimately approach whiteness..

eg: an orange ball with RGB = 1, 0.5, 0
when this orange color is additively blended to saturation the color yielded will be 1, 1, 0, which is yellow. but if you make your orange 1, 0.5, 0.1 then eventually it will go from yellow to white, and look a bit more interesting (IMO)..


Good luck!
I almost got the right result now, except for a weird phenomenon!

http://img80.imageshack.us/img80/2696/wtfx.png

Check that out. The glow looks almost flawless, except for the fact that in the right half-circle of a sphere, the shadow is like double as intense as the previous one.

Here's my vertex shader function, inspired by a DirectX 9.0b SDK sample:

glowOutput doVirusGlow(virusInput input, float4x4 instanceTransform, instanceData iInput)
{

float4 worldPosition = mul(input.position, instanceTransform);
float4 worldNormal = mul(input.normal, instanceTransform);

glowOutput output = (glowOutput)0;

float3 N = normalize(mul(worldNormal, (float3x3)View)); // normal (view space)
float3 P = mul(worldPosition, View) + GlowThickness * N; // displaced position (view space)
float3 A = float3(0, 0, 1); // glow axis

float power;

power = dot(N, A);
power *= power;
power = -power;
power *= power;

output.position = mul(float4(P, 1), Projection); // projected position
output.diffuse = (GlowColor * power) + GlowAmbient; // modulated glow color + glow ambient

return output;
}

As you can see, I added "power = -power" to get the effect you told me about. Now the shadow is just acting up (it was also doing this before).

Since you've been a great help so far, could you help me identify the problem?

This topic is closed to new replies.

Advertisement