More dust fun: dust box repeating is now handled in shader, so dust is now static geometry in shader mode.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3312 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
7c674d3d4a
commit
5599e4f375
@ -22,6 +22,7 @@
|
||||
"Troubleshooting Dumps", $troubleShootingDump,
|
||||
"Entity State", $entityState,
|
||||
"Data Cache Debug", $dataCacheDebug,
|
||||
"Rendering Errors", "rendering.opengl.error",
|
||||
"Texture Debug", $textureDebug,
|
||||
"Sound Debug", $soundDebug
|
||||
)
|
||||
|
@ -22,28 +22,44 @@
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/* The following macros are provided by Oolite, to ensure that they stay in
|
||||
sync with the values used in non-shader mode.
|
||||
|
||||
#define OODUST_SCALE_MAX (float(2))
|
||||
#define OODUST_SCALE_FACTOR (float(0.002))
|
||||
#define OODUST_SIZE (float(2000))
|
||||
#define OODUST_HALF_SIZE (float(1000))
|
||||
*/
|
||||
|
||||
|
||||
/* “Warpiness”: 0 for dots when not warping and the near end of lines when
|
||||
warping, 1 for the far end of lines when warping. (Note that both “ends”
|
||||
have the same input coordinates, and the shader applies the warp effect.)
|
||||
*/
|
||||
attribute float aWarpiness;
|
||||
varying vec4 vColor;
|
||||
uniform vec4 uWarp;
|
||||
uniform vec4 uPlayerPosition;
|
||||
|
||||
/* The following macros are provided by Oolite, to ensure that they stay in
|
||||
sync with the values used in non-shader mode.
|
||||
|
||||
#define OODUST_SCALE_MAX (float(2))
|
||||
#define OODUST_SCALE_FACTOR (float(0.002))
|
||||
*/
|
||||
varying vec4 vColor;
|
||||
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec4 position = gl_Vertex - uWarp * aWarpiness;
|
||||
/* Dust particles are arranged in a cube of 2000×2000×2000 metres
|
||||
(OO_DUST_SIZE) around the universe origin. The following code offsets
|
||||
each particle to be somewhere in a cube of the same size around the
|
||||
player, creating an infinite repeating pattern.
|
||||
*/
|
||||
vec4 position = mod(gl_Vertex - uPlayerPosition + OODUST_HALF_SIZE, OODUST_SIZE) - OODUST_HALF_SIZE + uPlayerPosition;
|
||||
position = position - uWarp * aWarpiness;
|
||||
|
||||
/* Project the dust, and find its distance from the camera.
|
||||
*/
|
||||
position.w = 1.0;
|
||||
float distance = length(gl_ModelViewMatrix * position);
|
||||
position = gl_ModelViewProjectionMatrix * position;
|
||||
gl_Position = position;
|
||||
|
||||
float distance = length(position);
|
||||
|
||||
/* The original non-shader code fades to black using linear fog, with a
|
||||
near plane of 500 and a far plane of 1000.
|
||||
@ -55,6 +71,4 @@ void main(void)
|
||||
*/
|
||||
float alpha = clamp(OODUST_SCALE_MAX - distance * OODUST_SCALE_FACTOR, 0.0, 1.0);
|
||||
vColor = vec4(gl_Color.rgb, alpha * gl_Color.a);
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * position;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ MA 02110-1301, USA.
|
||||
#if OO_SHADERS
|
||||
GLfloat warpinessAttr[DUST_N_PARTICLES * 2];
|
||||
OOShaderProgram *shader;
|
||||
OOShaderUniform *warpUniform;
|
||||
NSArray *uniforms;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ MA 02110-1301, USA.
|
||||
indices[vi * 2 + 1] = vi + DUST_N_PARTICLES;
|
||||
|
||||
#if OO_SHADERS
|
||||
vertices[vi + DUST_N_PARTICLES] = vertices[vi];
|
||||
warpinessAttr[vi] = 0.0f;
|
||||
warpinessAttr[vi + DUST_N_PARTICLES] = 1.0f;
|
||||
#endif
|
||||
@ -91,7 +92,7 @@ MA 02110-1301, USA.
|
||||
|
||||
#if OO_SHADERS
|
||||
DESTROY(shader);
|
||||
DESTROY(warpUniform);
|
||||
DESTROY(uniforms);
|
||||
#endif
|
||||
|
||||
[super dealloc];
|
||||
@ -120,6 +121,11 @@ MA 02110-1301, USA.
|
||||
|
||||
- (void) update:(OOTimeDelta) delta_t
|
||||
{
|
||||
#if OO_SHADERS
|
||||
// Shader takes care of repositioning.
|
||||
if ([UNIVERSE shaderEffectsLevel] > SHADERS_OFF) return;
|
||||
#endif
|
||||
|
||||
PlayerEntity* player = [PlayerEntity sharedPlayer];
|
||||
assert(player != nil);
|
||||
|
||||
@ -155,9 +161,13 @@ MA 02110-1301, USA.
|
||||
{
|
||||
NSString *prefix = [NSString stringWithFormat:
|
||||
@"#define OODUST_SCALE_MAX (float(%g))\n"
|
||||
"#define OODUST_SCALE_FACTOR (float(%g))\n",
|
||||
"#define OODUST_SCALE_FACTOR (float(%g))\n"
|
||||
"#define OODUST_SIZE (float(%g))\n"
|
||||
"#define OODUST_HALF_SIZE (float(%g))\n",
|
||||
FAR_PLANE / NEAR_PLANE,
|
||||
1.0f / (FAR_PLANE - NEAR_PLANE)];
|
||||
1.0f / (FAR_PLANE - NEAR_PLANE),
|
||||
(float)DUST_SCALE,
|
||||
(float)DUST_SCALE * 0.5f];
|
||||
|
||||
// Reuse tangent attribute ID for "warpiness", as we don't need a tangent.
|
||||
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kTangentAttributeIndex]
|
||||
@ -168,12 +178,21 @@ MA 02110-1301, USA.
|
||||
prefix:prefix
|
||||
attributeBindings:attributes] retain];
|
||||
|
||||
DESTROY(warpUniform);
|
||||
warpUniform = [[OOShaderUniform alloc] initWithName:@"uWarp"
|
||||
DESTROY(uniforms);
|
||||
OOShaderUniform *uWarp = [[OOShaderUniform alloc] initWithName:@"uWarp"
|
||||
shaderProgram:shader
|
||||
boundToObject:self
|
||||
property:@selector(warpVector)
|
||||
convertOptions:0];
|
||||
OOShaderUniform *uPlayerPosition = [[OOShaderUniform alloc] initWithName:@"uPlayerPosition"
|
||||
shaderProgram:shader
|
||||
boundToObject:[PlayerEntity sharedPlayer]
|
||||
property:@selector(position)
|
||||
convertOptions:0];
|
||||
|
||||
uniforms = [[NSArray alloc] initWithObjects:uWarp, uPlayerPosition, nil];
|
||||
[uWarp release];
|
||||
[uPlayerPosition release];
|
||||
}
|
||||
|
||||
return shader;
|
||||
@ -243,7 +262,7 @@ MA 02110-1301, USA.
|
||||
if (useShader)
|
||||
{
|
||||
[[self shader] apply];
|
||||
[warpUniform apply];
|
||||
[uniforms makeObjectsPerformSelector:@selector(apply)];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -264,10 +283,8 @@ MA 02110-1301, USA.
|
||||
#if OO_SHADERS
|
||||
if (useShader)
|
||||
{
|
||||
// Duplicate vertices.
|
||||
OOGL(glEnableVertexAttribArrayARB(kTangentAttributeIndex));
|
||||
OOGL(glVertexAttribPointerARB(kTangentAttributeIndex, 1, GL_FLOAT, GL_FALSE, 0, warpinessAttr));
|
||||
memcpy(vertices + DUST_N_PARTICLES, vertices, sizeof *vertices * DUST_N_PARTICLES);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -317,6 +334,12 @@ MA 02110-1301, USA.
|
||||
{
|
||||
#if OO_SHADERS
|
||||
DESTROY(shader);
|
||||
DESTROY(uniforms);
|
||||
|
||||
/* Duplicate vertex data. This is only required if we're switching from
|
||||
non-shader mode to a shader mode, but let's KISS.
|
||||
*/
|
||||
memcpy(vertices + DUST_N_PARTICLES, vertices, sizeof *vertices * DUST_N_PARTICLES);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1985,7 +1985,7 @@ static OOPolygonSprite *IconForMissileRole(NSString *role)
|
||||
}
|
||||
|
||||
float cosAngle = dot_product(vector_normal(rpn), forward);
|
||||
float visibility = 1.0f - ((visMax - cosAngle) * 1.0f / (visMax - visMin));
|
||||
float visibility = 1.0f - ((visMax - cosAngle) * (1.0f / (visMax - visMin)));
|
||||
alpha *= OOClamp_0_1_f(visibility);
|
||||
|
||||
if (alpha > 0.0f)
|
||||
|
Loading…
x
Reference in New Issue
Block a user