2014-01-08 14:09:04 -05:00
|
|
|
#version 140
|
2013-12-31 20:11:44 -05:00
|
|
|
uniform mat4 ProjectionMatrix;
|
|
|
|
uniform mat4 ViewMatrix;
|
2014-01-07 16:06:06 -05:00
|
|
|
uniform float track_x;
|
|
|
|
uniform float track_z;
|
|
|
|
uniform float track_x_len;
|
|
|
|
uniform float track_z_len;
|
|
|
|
uniform samplerBuffer heightmap;
|
|
|
|
uniform bool hasHeightMap;
|
2014-01-08 13:34:57 -05:00
|
|
|
uniform bool flips;
|
2013-12-31 12:25:10 -05:00
|
|
|
|
2013-12-31 15:39:00 -05:00
|
|
|
in vec2 quadcorner;
|
|
|
|
in vec2 texcoord;
|
2013-12-29 14:24:19 -05:00
|
|
|
in vec3 position;
|
2013-12-31 12:25:10 -05:00
|
|
|
in float lifetime;
|
2013-12-31 20:11:44 -05:00
|
|
|
in float size;
|
2013-12-31 12:25:10 -05:00
|
|
|
|
2014-01-08 13:34:57 -05:00
|
|
|
in vec3 rotationvec;
|
|
|
|
in float anglespeed;
|
|
|
|
|
2013-12-31 12:25:10 -05:00
|
|
|
out float lf;
|
2013-12-31 15:39:00 -05:00
|
|
|
out vec2 tc;
|
2013-12-29 13:23:36 -05:00
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2013-12-31 15:39:00 -05:00
|
|
|
tc = texcoord;
|
2013-12-31 12:25:10 -05:00
|
|
|
lf = lifetime;
|
2014-01-07 16:06:06 -05:00
|
|
|
vec3 newposition = position;
|
|
|
|
|
|
|
|
float i_as_float = clamp(256. * (position.x - track_x) / track_x_len, 0., 255.);
|
|
|
|
float j_as_float = clamp(256. * (position.z - track_z) / track_z_len, 0., 255.);
|
|
|
|
int i = int(i_as_float);
|
|
|
|
int j = int(j_as_float);
|
|
|
|
|
|
|
|
if (hasHeightMap) {
|
|
|
|
float h = position.y - texelFetch(heightmap, i * 256 + j).r;
|
2014-01-08 20:49:06 -05:00
|
|
|
newposition.y = (h > 0.)? position.y : 1000.;
|
2014-01-07 16:06:06 -05:00
|
|
|
}
|
|
|
|
|
2014-01-08 13:34:57 -05:00
|
|
|
if (flips)
|
|
|
|
{
|
|
|
|
// from http://jeux.developpez.com/faq/math
|
|
|
|
float angle = lf * anglespeed;
|
|
|
|
float sin_a = sin(angle / 2.);
|
|
|
|
float cos_a = cos(angle / 2.);
|
|
|
|
|
|
|
|
vec4 quaternion = normalize(vec4(rotationvec * sin_a, cos_a));
|
|
|
|
|
|
|
|
float xx = quaternion.x * quaternion.x;
|
|
|
|
float xy = quaternion.x * quaternion.y;
|
|
|
|
float xz = quaternion.x * quaternion.z;
|
|
|
|
float xw = quaternion.x * quaternion.w;
|
|
|
|
|
|
|
|
float yy = quaternion.y * quaternion.y;
|
|
|
|
float yz = quaternion.y * quaternion.z;
|
|
|
|
float yw = quaternion.y * quaternion.w;
|
|
|
|
|
|
|
|
float zz = quaternion.z * quaternion.z;
|
|
|
|
float zw = quaternion.z * quaternion.w;
|
|
|
|
|
|
|
|
vec4 col1 = vec4(
|
|
|
|
1. - 2. * ( yy + zz ),
|
|
|
|
2. * ( xy + zw ),
|
|
|
|
2. * ( xz - yw ),
|
|
|
|
0.);
|
|
|
|
vec4 col2 = vec4(
|
|
|
|
2. * ( xy - zw ),
|
|
|
|
1. - 2. * ( xx + zz ),
|
|
|
|
2. * ( yz + xw ),
|
|
|
|
0.);
|
|
|
|
vec4 col3 = vec4(
|
|
|
|
2. * ( xz + yw ),
|
|
|
|
2. * ( yz - xw ),
|
|
|
|
1. - 2. * ( xx + yy ),
|
|
|
|
0.);
|
|
|
|
vec4 col4 = vec4(0., 0., 0., 1.);
|
|
|
|
mat4 rotationMatrix = mat4(col1, col2, col3, col4);
|
|
|
|
vec3 newquadcorner = size * vec3(quadcorner, 0.);
|
|
|
|
newquadcorner = (rotationMatrix * vec4(newquadcorner, 0.)).xyz;
|
|
|
|
|
|
|
|
vec4 viewpos = ViewMatrix * vec4(newposition + newquadcorner, 1.0);
|
|
|
|
gl_Position = ProjectionMatrix * viewpos;
|
|
|
|
} else {
|
|
|
|
vec4 viewpos = ViewMatrix * vec4(newposition, 1.0);
|
|
|
|
viewpos += size * vec4(quadcorner, 0., 0.);
|
|
|
|
gl_Position = ProjectionMatrix * viewpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-29 13:23:36 -05:00
|
|
|
}
|