2012-11-30 20:02:16 -05:00
|
|
|
uniform mat4 mWorldViewProj;
|
|
|
|
uniform mat4 mInvWorld;
|
|
|
|
uniform mat4 mTransWorld;
|
2014-03-20 20:32:00 -04:00
|
|
|
uniform mat4 mWorld;
|
|
|
|
|
2012-12-02 07:24:58 -05:00
|
|
|
uniform float dayNightRatio;
|
2013-12-03 11:21:40 -05:00
|
|
|
uniform vec3 eyePosition;
|
2014-05-14 17:19:31 -04:00
|
|
|
uniform float animationTimer;
|
2012-11-30 20:02:16 -05:00
|
|
|
|
|
|
|
varying vec3 vPosition;
|
2014-03-20 20:32:00 -04:00
|
|
|
varying vec3 worldPosition;
|
|
|
|
|
2013-12-03 11:21:40 -05:00
|
|
|
varying vec3 eyeVec;
|
2014-03-20 20:32:00 -04:00
|
|
|
varying vec3 lightVec;
|
|
|
|
varying vec3 tsEyeVec;
|
|
|
|
varying vec3 tsLightVec;
|
|
|
|
|
2014-05-14 17:19:31 -04:00
|
|
|
const float e = 2.718281828459;
|
2014-03-20 20:32:00 -04:00
|
|
|
const float BS = 10.0;
|
2012-11-30 20:02:16 -05:00
|
|
|
|
2014-05-14 17:19:31 -04:00
|
|
|
float smoothCurve( float x ) {
|
|
|
|
return x * x *( 3.0 - 2.0 * x );
|
|
|
|
}
|
|
|
|
float triangleWave( float x ) {
|
|
|
|
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
|
|
|
|
}
|
|
|
|
float smoothTriangleWave( float x ) {
|
|
|
|
return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;
|
|
|
|
}
|
|
|
|
|
2012-11-30 20:02:16 -05:00
|
|
|
void main(void)
|
|
|
|
{
|
2014-05-14 17:19:31 -04:00
|
|
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
|
|
|
|
|
|
|
#if (MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER
|
|
|
|
vec4 pos = gl_Vertex;
|
|
|
|
pos.y -= 2.0;
|
|
|
|
pos.y -= sin (pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT
|
|
|
|
+ sin ((pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;
|
|
|
|
gl_Position = mWorldViewProj * pos;
|
|
|
|
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
|
|
|
|
vec4 pos = gl_Vertex;
|
|
|
|
vec4 pos2 = mWorld * gl_Vertex;
|
|
|
|
pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;
|
|
|
|
pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;
|
|
|
|
pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;
|
|
|
|
gl_Position = mWorldViewProj * pos;
|
|
|
|
#elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
|
|
|
|
vec4 pos = gl_Vertex;
|
|
|
|
vec4 pos2 = mWorld * gl_Vertex;
|
|
|
|
if (gl_TexCoord[0].y < 0.05) {
|
|
|
|
pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;
|
|
|
|
pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;
|
|
|
|
}
|
|
|
|
gl_Position = mWorldViewProj * pos;
|
2013-12-09 07:25:43 -05:00
|
|
|
#else
|
|
|
|
gl_Position = mWorldViewProj * gl_Vertex;
|
|
|
|
#endif
|
2013-12-03 11:21:40 -05:00
|
|
|
|
2014-05-14 17:19:31 -04:00
|
|
|
vPosition = gl_Position.xyz;
|
2014-03-20 20:32:00 -04:00
|
|
|
worldPosition = (mWorld * gl_Vertex).xyz;
|
|
|
|
vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
|
|
|
|
|
|
|
|
vec3 normal, tangent, binormal;
|
|
|
|
normal = normalize(gl_NormalMatrix * gl_Normal);
|
|
|
|
if (gl_Normal.x > 0.5) {
|
|
|
|
// 1.0, 0.0, 0.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
|
|
|
|
} else if (gl_Normal.x < -0.5) {
|
|
|
|
// -1.0, 0.0, 0.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
|
|
|
|
} else if (gl_Normal.y > 0.5) {
|
|
|
|
// 0.0, 1.0, 0.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
|
|
|
|
} else if (gl_Normal.y < -0.5) {
|
|
|
|
// 0.0, -1.0, 0.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
|
|
|
|
} else if (gl_Normal.z > 0.5) {
|
|
|
|
// 0.0, 0.0, 1.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
|
|
|
|
} else if (gl_Normal.z < -0.5) {
|
|
|
|
// 0.0, 0.0, -1.0
|
|
|
|
tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
|
|
|
|
binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
|
|
|
|
}
|
|
|
|
mat3 tbnMatrix = mat3( tangent.x, binormal.x, normal.x,
|
|
|
|
tangent.y, binormal.y, normal.y,
|
|
|
|
tangent.z, binormal.z, normal.z);
|
|
|
|
|
|
|
|
lightVec = sunPosition - worldPosition;
|
|
|
|
tsLightVec = lightVec * tbnMatrix;
|
2013-12-03 11:21:40 -05:00
|
|
|
eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
2014-03-20 20:32:00 -04:00
|
|
|
tsEyeVec = eyeVec * tbnMatrix;
|
2012-11-30 20:02:16 -05:00
|
|
|
|
2014-08-16 08:02:50 -04:00
|
|
|
gl_FrontColor = gl_BackColor = gl_Color;
|
2012-11-30 20:02:16 -05:00
|
|
|
}
|