-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment_rain.vert
48 lines (38 loc) · 1.96 KB
/
environment_rain.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#include "engine/data_transform_3d.glsl"
#include "engine/data_ambient.glsl"
// constant values
const float c_v1MapResolution = 0.42; // normal map resolution
const float c_v1WaterHeight = -20.0; // default water z-position
// shader uniforms
uniform float u_v1Time; // current animation value
uniform float u_v1Offset; // current y-position offset
// shader output
flat varying vec4 v_v4Lighting; // lighting properties (xyz = light direction, w = height offset for smooth shores)
void VertexMain()
{
// transform position
vec4 v4NewPosition = vec4(coreObject3DTransformLow(), 1.0);
gl_Position = u_m4ViewProj * v4NewPosition;
// transform lighting properties (resolved)
v_v3TangentPos = v4NewPosition.xyz * vec3( 1.0, -1.0, 1.0);
v_v3TangentCam = u_v3CamPosition * vec3( 1.0, -1.0, 1.0);
v_v4Lighting.xyz = u_av4LightDir[0].xyz * vec3(-1.0, 1.0, -1.0);
// calculate current mapping base
vec2 v2MapCoord = vec2(a_v2LowTexCoord.x * c_v1MapResolution,
a_v2LowTexCoord.y * c_v1MapResolution + u_v1Offset);
// transform texture coordinates with different animation properties
v_av2TexCoord[0] = (v2MapCoord) * 8.0;
v_av2TexCoord[1] = (v2MapCoord) * 12.0;
v_av2TexCoord[2] = (v2MapCoord + u_v1Time * vec2( 0.5, -0.5) * 1.5) * 2.0;
v_av2TexCoord[3] = (v2MapCoord + u_v1Time * vec2(-0.1, 0.1) * 1.5) * 4.0;
// calculate height offset
v_v4Lighting.w = 0.042 * (u_v3Position.z - c_v1WaterHeight);
}