Experimenting with additive blending in particleEntity.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@880 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-04-01 13:25:02 +00:00
parent ce7270caa3
commit cd9d2260de
3 changed files with 68 additions and 9 deletions

View File

@ -824,7 +824,7 @@ BOOL global_testForVAR;
OOLog(kOOLogFileNotLoaded, @"ERROR no basefile for entity %@"); OOLog(kOOLogFileNotLoaded, @"ERROR no basefile for entity %@");
} }
} }
glShadeModel(GL_SMOOTH); if (!is_smooth_shaded) glShadeModel(GL_SMOOTH);
checkGLErrors([NSString stringWithFormat:@"Entity after drawing %@", self]); checkGLErrors([NSString stringWithFormat:@"Entity after drawing %@", self]);
NS_HANDLER NS_HANDLER

View File

@ -37,6 +37,30 @@ MA 02110-1301, USA.
#define kOOLogUnconvertedNSLog @"unclassified.ParticleEntity" #define kOOLogUnconvertedNSLog @"unclassified.ParticleEntity"
#ifndef ADDITIVE_BLENDING
#define ADDITIVE_BLENDING 1
#endif
#if ADDITIVE_BLENDING
static inline void BeginAdditiveBlending(void)
{
glPushAttrib(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
static inline void EndAdditiveBlending(void)
{
glPopAttrib();
}
#else
#define BeginAdditiveBlending() do {} while (0)
#define EndAdditiveBlending() do {} while (0)
#endif
static Vector circleVertex[65]; // holds vector coordinates for a unit circle static Vector circleVertex[65]; // holds vector coordinates for a unit circle
@implementation ParticleEntity @implementation ParticleEntity
@ -1257,7 +1281,13 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
- (void) updateExhaust2:(double) delta_t - (void) updateExhaust2:(double) delta_t
{ {
GLfloat ex_emissive[4] = {0.6, 0.8, 1.0, 0.9}; // pale blue #if ADDITIVE_BLENDING
#define OVERALL_ALPHA 0.3f
#else
#define OVERALL_ALPHA 1.0f
#endif
GLfloat ex_emissive[4] = {0.6, 0.8, 1.0, 0.9 * OVERALL_ALPHA}; // pale blue
GLfloat s1[8] = { 0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707}; GLfloat s1[8] = { 0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707};
GLfloat c1[8] = { 1.0, 0.707, 0.0, -0.707, -1.0, -0.707, 0.0, 0.707}; GLfloat c1[8] = { 1.0, 0.707, 0.0, -0.707, -1.0, -0.707, 0.0, 0.707};
ShipEntity *ship =(ShipEntity *)[universe entityForUniversalID:owner]; ShipEntity *ship =(ShipEntity *)[universe entityForUniversalID:owner];
@ -1341,7 +1371,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
int i; int i;
float r1; float r1;
// //
ex_emissive[3] = flare_factor; // fade alpha towards rear of exhaust ex_emissive[3] = flare_factor * OVERALL_ALPHA; // fade alpha towards rear of exhaust
ex_emissive[1] = green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = red_factor; // diminish red part towards rear of exhaust
verts[iv++] = f03.position.x + b03.x;// + zero.k.x * flare_factor * 4.0; verts[iv++] = f03.position.x + b03.x;// + zero.k.x * flare_factor * 4.0;
@ -1352,7 +1382,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
exhaustBaseColors[ci++] = ex_emissive[2]; exhaustBaseColors[ci++] = ex_emissive[2];
exhaustBaseColors[ci++] = ex_emissive[3]; exhaustBaseColors[ci++] = ex_emissive[3];
// //
ex_emissive[3] = 0.9 * flare_factor; // fade alpha towards rear of exhaust ex_emissive[3] = 0.9 * flare_factor * OVERALL_ALPHA; // fade alpha towards rear of exhaust
ex_emissive[1] = 0.9 * green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = 0.9 * green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = 0.9 * red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = 0.9 * red_factor; // diminish red part towards rear of exhaust
Vector k1 = f01.k; Vector k1 = f01.k;
@ -1376,7 +1406,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
exhaustBaseColors[ci++] = ex_emissive[3]; exhaustBaseColors[ci++] = ex_emissive[3];
} }
// //
ex_emissive[3] = 0.6 * flare_factor; // fade alpha towards rear of exhaust ex_emissive[3] = 0.6 * flare_factor * OVERALL_ALPHA; // fade alpha towards rear of exhaust
ex_emissive[1] = 0.6 * green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = 0.6 * green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = 0.6 * red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = 0.6 * red_factor; // diminish red part towards rear of exhaust
k1 = f03.k; k1 = f03.k;
@ -1396,7 +1426,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
exhaustBaseColors[ci++] = ex_emissive[3]; exhaustBaseColors[ci++] = ex_emissive[3];
} }
// //
ex_emissive[3] = 0.4 * flare_factor; // fade alpha towards rear of exhaust ex_emissive[3] = 0.4 * flare_factor * OVERALL_ALPHA; // fade alpha towards rear of exhaust
ex_emissive[1] = 0.4 * green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = 0.4 * green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = 0.4 * red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = 0.4 * red_factor; // diminish red part towards rear of exhaust
k1 = f06.k; k1 = f06.k;
@ -1416,7 +1446,7 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
exhaustBaseColors[ci++] = ex_emissive[3]; exhaustBaseColors[ci++] = ex_emissive[3];
} }
// //
ex_emissive[3] = 0.2 * flare_factor; // fade alpha towards rear of exhaust ex_emissive[3] = 0.2 * flare_factor * OVERALL_ALPHA; // fade alpha towards rear of exhaust
ex_emissive[1] = 0.2 * green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = 0.2 * green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = 0.2 * red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = 0.2 * red_factor; // diminish red part towards rear of exhaust
k1 = f08.k; k1 = f08.k;
@ -1640,11 +1670,12 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
glColor4fv( color_fv); glColor4fv( color_fv);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color_fv); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color_fv);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBindTexture(GL_TEXTURE_2D, texName); glBindTexture(GL_TEXTURE_2D, texName);
BeginAdditiveBlending();
glBegin(GL_QUADS); glBegin(GL_QUADS);
viewdir = [universe viewDir]; viewdir = [universe viewDir];
@ -1739,6 +1770,8 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
break; break;
} }
glEnd(); glEnd();
EndAdditiveBlending();
} }
- (void) drawLaser - (void) drawLaser
@ -1754,6 +1787,8 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
glColor4fv(color_fv); glColor4fv(color_fv);
BeginAdditiveBlending();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f(0.25, 0.0, 0.0); glVertex3f(0.25, 0.0, 0.0);
@ -1768,6 +1803,8 @@ static Vector circleVertex[65]; // holds vector coordinates for a unit circle
glEnd(); glEnd();
EndAdditiveBlending();
glEnable(GL_CULL_FACE); // face culling glEnable(GL_CULL_FACE); // face culling
} }
@ -1794,6 +1831,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glDisable( GL_CULL_FACE); // face culling glDisable( GL_CULL_FACE); // face culling
glShadeModel( GL_SMOOTH); glShadeModel( GL_SMOOTH);
BeginAdditiveBlending();
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, GL_FLOAT, 0, verts); glVertexPointer( 3, GL_FLOAT, 0, verts);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
@ -1809,6 +1848,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glDrawElements( GL_QUAD_STRIP, 18, GL_UNSIGNED_INT, qstrip3); glDrawElements( GL_QUAD_STRIP, 18, GL_UNSIGNED_INT, qstrip3);
glDrawElements( GL_TRIANGLE_FAN, 10, GL_UNSIGNED_INT, tfan2); glDrawElements( GL_TRIANGLE_FAN, 10, GL_UNSIGNED_INT, tfan2);
EndAdditiveBlending();
glEnable( GL_CULL_FACE); // face culling glEnable( GL_CULL_FACE); // face culling
glEnable( GL_TEXTURE_2D); glEnable( GL_TEXTURE_2D);
} }
@ -1826,6 +1867,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
BeginAdditiveBlending();
//NSLog(@"... drawing hyppering inner_radius:%.1f alpha:%.2f", ring_inner_radius, aleph); //NSLog(@"... drawing hyppering inner_radius:%.1f alpha:%.2f", ring_inner_radius, aleph);
// movies: // movies:
@ -1841,6 +1884,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
} }
glEnd(); glEnd();
EndAdditiveBlending();
glEnable(GL_CULL_FACE); // face culling glEnable(GL_CULL_FACE); // face culling
glPopMatrix(); glPopMatrix();
} }
@ -1854,6 +1899,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glDisable(GL_CULL_FACE); // face culling glDisable(GL_CULL_FACE); // face culling
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
BeginAdditiveBlending();
int step = 4; int step = 4;
glColor4fv( color_fv); glColor4fv( color_fv);
@ -1865,6 +1912,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
// NSLog(@"DEBUG ENERGY BOMB radius: %.3f, expansion: %.3f, color: [ %.3f, %.3f, %.3f, %.3f]", collision_radius, velocity.z, color_fv[0], color_fv[1], color_fv[2], alpha); // NSLog(@"DEBUG ENERGY BOMB radius: %.3f, expansion: %.3f, color: [ %.3f, %.3f, %.3f, %.3f]", collision_radius, velocity.z, color_fv[0], color_fv[1], color_fv[2], alpha);
EndAdditiveBlending();
glEnable(GL_CULL_FACE); // face culling glEnable(GL_CULL_FACE); // face culling
} }
@ -1877,6 +1926,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glBindTexture(GL_TEXTURE_2D, texName); glBindTexture(GL_TEXTURE_2D, texName);
glPushMatrix(); glPushMatrix();
BeginAdditiveBlending();
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (i = 0; i < n_vertices; i++) for (i = 0; i < n_vertices; i++)
{ {
@ -1885,6 +1936,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
} }
glEnd(); glEnd();
EndAdditiveBlending();
glPopMatrix(); glPopMatrix();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }
@ -1898,6 +1951,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
glBindTexture(GL_TEXTURE_2D, texName); glBindTexture(GL_TEXTURE_2D, texName);
glPushMatrix(); glPushMatrix();
BeginAdditiveBlending();
glBegin(GL_QUADS); glBegin(GL_QUADS);
for (i = 0; i < n_vertices; i++) for (i = 0; i < n_vertices; i++)
{ {
@ -1906,6 +1961,8 @@ GLuint tfan2[10] = { 33, 25, 26, 27, 28, 29, 30, 31, 32, 25}; // final fan 64..7
} }
glEnd(); glEnd();
EndAdditiveBlending();
glPopMatrix(); glPopMatrix();
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
} }

View File

@ -625,6 +625,8 @@ GLuint max_texture_dimension = 512; // conservative start
void fillSquareImageDataWithBlur(unsigned char * imageBuffer, int width, int nplanes) void fillSquareImageDataWithBlur(unsigned char * imageBuffer, int width, int nplanes)
{ {
OOLog(@"texture.generatingBlur", @"Genrating blur - %u pixels wide, %u planes.", width, nplanes);
int x, y; int x, y;
int r = width / 2; int r = width / 2;
float r1 = 1.0 / r; float r1 = 1.0 / r;