Greetings!
So I’ve finally decided to pull my head out Paint and get some decent-looking effects in my game… Obviously by learning OpenGL. Although I am using ES1.1 at the moment, I believe my question is pretty generic within OpenGL-land.
In my 2D-platform shooter, I’m currently implementing lights. I obviously want the objects to cast shadow - which in my case is “absence of light” more than actual shadows.
Here’s a screenshot of my current result:
http://i260.photobucket.com/albums/ii36/gneldre/Skjermbilde2011-08-11kl230543.png
I’m not gonna post the entire code itself, as it’s probably gonna be a bitch to read. Here’s the pseudo-version of it.
-(void) update:(ccTime)dt {
do {
b2Vec2 point1 = RayCast( a, b );
b2Vec2 point2 = RayCast( a, c );
//Emit-position. relative to source's position
vertices[Vcounter] = 0.0; Vcounter++;
vertices[Vcounter] = 0.0; Vcounter++;
//P1
vertices[Vcounter] = point1.x; Vcounter++;
vertices[Vcounter] = point1.y; Vcounter++;
//p2
vertices[Vcounter] = point2.x; Vcounter++;
vertices[Vcounter] = point2.y; Vcounter++;
//Emit-color
color[Ccounter] = {0.6, 0.6, 0.5, 0.4}; Ccounter++;
//Faded color
color[Ccounter] = {0.0, 0.0, 0.0, 0.0}; Ccounter++;
color[Ccounter] = {0.0, 0.0, 0.0, 0.0}; Ccounter++;
} while ( curAngle < endAngle );
}
As you can see, the color is fading regardless of the distance, which in fact is exactly what I told it to do. How can I avoid this? I want the colors to fade when they reach N meters away from the source, not N percents as it is now.
One fix I’ve been considering is calculating this in the function I posted. Setting the color of point B and C based on their relative position to A. I think this will take too much processing power though.
Any input is highly appreciated!
/Pimms