Slight dust shader optimization.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3313 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-05-09 19:37:09 +00:00
parent 5599e4f375
commit 1d7b85b918
2 changed files with 19 additions and 15 deletions

View File

@ -27,8 +27,7 @@
#define OODUST_SCALE_MAX (float(2))
#define OODUST_SCALE_FACTOR (float(0.002))
#define OODUST_SIZE (float(2000))
#define OODUST_HALF_SIZE (float(1000))
#define OODUST_SIZE (float(2000))
*/
@ -38,7 +37,9 @@
*/
attribute float aWarpiness;
uniform vec4 uWarp;
uniform vec4 uPlayerPosition;
// Dust, offset by -OODUST_SIZE/2 on each coordinate.
uniform vec4 uOffsetPlayerPosition;
varying vec4 vColor;
@ -50,11 +51,10 @@ void main(void)
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;
vec4 position = mod(gl_Vertex - + uOffsetPlayerPosition, OODUST_SIZE) + uOffsetPlayerPosition;
position = position - uWarp * aWarpiness;
/* Project the dust, and find its distance from the camera.
*/
// Project the dust, and find its distance from the camera.
position.w = 1.0;
position = gl_ModelViewProjectionMatrix * position;
gl_Position = position;

View File

@ -162,12 +162,10 @@ MA 02110-1301, USA.
NSString *prefix = [NSString stringWithFormat:
@"#define OODUST_SCALE_MAX (float(%g))\n"
"#define OODUST_SCALE_FACTOR (float(%g))\n"
"#define OODUST_SIZE (float(%g))\n"
"#define OODUST_HALF_SIZE (float(%g))\n",
"#define OODUST_SIZE (float(%g))\n",
FAR_PLANE / NEAR_PLANE,
1.0f / (FAR_PLANE - NEAR_PLANE),
(float)DUST_SCALE,
(float)DUST_SCALE * 0.5f];
(float)DUST_SCALE];
// Reuse tangent attribute ID for "warpiness", as we don't need a tangent.
NSDictionary *attributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kTangentAttributeIndex]
@ -184,19 +182,25 @@ MA 02110-1301, USA.
boundToObject:self
property:@selector(warpVector)
convertOptions:0];
OOShaderUniform *uPlayerPosition = [[OOShaderUniform alloc] initWithName:@"uPlayerPosition"
OOShaderUniform *uOffsetPlayerPosition = [[OOShaderUniform alloc] initWithName:@"uOffsetPlayerPosition"
shaderProgram:shader
boundToObject:[PlayerEntity sharedPlayer]
property:@selector(position)
boundToObject:self
property:@selector(offsetPlayerPosition)
convertOptions:0];
uniforms = [[NSArray alloc] initWithObjects:uWarp, uPlayerPosition, nil];
uniforms = [[NSArray alloc] initWithObjects:uWarp, uOffsetPlayerPosition, nil];
[uWarp release];
[uPlayerPosition release];
[uOffsetPlayerPosition release];
}
return shader;
}
- (Vector) offsetPlayerPosition
{
return vector_subtract([[PlayerEntity sharedPlayer] position], make_vector(DUST_SCALE * 0.5f, DUST_SCALE * 0.5f, DUST_SCALE * 0.5f));
}
#endif