1 uniform mat4 mWorldViewProj;
\r
2 uniform mat4 mInvWorld;
\r
3 uniform mat4 mTransWorld;
\r
6 uniform float dayNightRatio;
\r
7 uniform vec3 eyePosition;
\r
8 uniform float animationTimer;
\r
10 varying vec3 vPosition;
\r
11 varying vec3 worldPosition;
\r
13 varying vec3 eyeVec;
\r
14 varying vec3 lightVec;
\r
15 varying vec3 tsEyeVec;
\r
16 varying vec3 tsLightVec;
\r
17 varying float area_enable_parallax;
19 const float e = 2.718281828459;
\r
20 const float BS = 10.0;
\r
22 float smoothCurve(float x)
24 return x * x * (3.0 - 2.0 * x);
26 float triangleWave(float x)
28 return abs(fract(x + 0.5) * 2.0 - 1.0);
30 float smoothTriangleWave(float x)
32 return smoothCurve(triangleWave(x)) * 2.0 - 1.0;
37 gl_TexCoord[0] = gl_MultiTexCoord0;
\r
38 //TODO: make offset depending on view angle and parallax uv displacement
\r
39 //thats for textures that doesnt align vertically, like dirt with grass
\r
40 //gl_TexCoord[0].y += 0.008;
42 //Allow parallax/relief mapping only for certain kind of nodes
\r
43 //Variable is also used to control area of the effect
44 #if (DRAW_TYPE == NDT_NORMAL || DRAW_TYPE == NDT_LIQUID || DRAW_TYPE == NDT_FLOWINGLIQUID)
45 area_enable_parallax = 1.0;
47 area_enable_parallax = 0.0;
50 #if ((MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE) && ENABLE_WAVING_WATER)
51 vec4 pos = gl_Vertex;
\r
54 float posYbuf = (pos.z / WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH);
\r
56 pos.y -= sin(posYbuf) * WATER_WAVE_HEIGHT + sin(posYbuf / 7.0) * WATER_WAVE_HEIGHT;
\r
57 gl_Position = mWorldViewProj * pos;
\r
58 #elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_LEAVES && ENABLE_WAVING_LEAVES
\r
59 vec4 pos = gl_Vertex;
\r
60 vec4 pos2 = mWorld * gl_Vertex;
\r
63 * Mathematic optimization: pos2.x * A + pos2.z * A (2 multiplications + 1 addition)
\r
64 * replaced with: (pos2.x + pos2.z) * A (1 addition + 1 multiplication)
\r
65 * And bufferize calcul to a float
\r
67 float pos2XpZ = pos2.x + pos2.z;
\r
69 pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2XpZ * 0.01) * 2.0 - 1.0) * 0.4;
\r
70 pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2XpZ * -0.01) * 2.0 - 1.0) * 0.2;
\r
71 pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2XpZ * -0.01) * 2.0 - 1.0) * 0.4;
\r
72 gl_Position = mWorldViewProj * pos;
\r
73 #elif MATERIAL_TYPE == TILE_MATERIAL_WAVING_PLANTS && ENABLE_WAVING_PLANTS
\r
74 vec4 pos = gl_Vertex;
\r
75 vec4 pos2 = mWorld * gl_Vertex;
\r
76 if (gl_TexCoord[0].y < 0.05) {
\r
78 * Mathematic optimization: pos2.x * A + pos2.z * A (2 multiplications + 1 addition)
\r
79 * replaced with: (pos2.x + pos2.z) * A (1 addition + 1 multiplication)
\r
80 * And bufferize calcul to a float
\r
82 float pos2XpZ = pos2.x + pos2.z;
\r
84 pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2XpZ * 0.1) * 2.0 - 1.0) * 0.8;
\r
85 pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2XpZ * -0.5) * 2.0 - 1.0) * 0.4;
\r
87 gl_Position = mWorldViewProj * pos;
\r
89 gl_Position = mWorldViewProj * gl_Vertex;
\r
92 vPosition = gl_Position.xyz;
\r
93 worldPosition = (mWorld * gl_Vertex).xyz;
\r
95 // Don't generate heightmaps when too far from the eye
96 float dist = distance (vec3(0.0, 0.0 ,0.0), vPosition);
98 area_enable_parallax = 0.0;
101 vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
\r
103 vec3 normal, tangent, binormal;
\r
104 normal = normalize(gl_NormalMatrix * gl_Normal);
\r
105 tangent = normalize(gl_NormalMatrix * gl_MultiTexCoord1.xyz);
106 binormal = normalize(gl_NormalMatrix * gl_MultiTexCoord2.xyz);
110 lightVec = sunPosition - worldPosition;
\r
111 v.x = dot(lightVec, tangent);
112 v.y = dot(lightVec, binormal);
113 v.z = dot(lightVec, normal);
114 tsLightVec = normalize (v);
116 eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz;
117 v.x = dot(eyeVec, tangent);
118 v.y = dot(eyeVec, binormal);
119 v.z = dot(eyeVec, normal);
120 tsEyeVec = normalize (v);
123 float day = gl_Color.r;
\r
124 float night = gl_Color.g;
\r
125 float light_source = gl_Color.b;
\r
127 float rg = mix(night, day, dayNightRatio);
\r
128 rg += light_source * 2.5; // Make light sources brighter
\r
131 // Moonlight is blue
\r
132 b += (day - night) / 13.0;
\r
133 rg -= (day - night) / 23.0;
\r
135 // Emphase blue a bit in darker places
\r
136 // See C++ implementation in mapblock_mesh.cpp finalColorBlend()
\r
137 b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);
\r
139 // Artificial light is yellow-ish
\r
140 // See C++ implementation in mapblock_mesh.cpp finalColorBlend()
\r
141 rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);
\r
147 color.a = gl_Color.a;
\r
148 gl_FrontColor = gl_BackColor = clamp(color,0.0,1.0);
\r