-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertexShader.glsl
56 lines (42 loc) · 1.31 KB
/
vertexShader.glsl
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
49
50
51
52
53
54
55
56
#version 430 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
out VS_OUT {
vec3 FragPos;
vec2 TexCoords;
vec3 TangentLightPos;
vec3 TangentViewPos;
vec3 TangentFragPos;
} vs_out;
out vec3 vPosition;
out vec2 vTexCoord;
uniform sampler2D heightsTexture;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform float terrainSize;
uniform sampler2D normalTexture;
uniform vec3 lightPos;
uniform vec3 viewPos;
void main(){
vec4 curV;
curV = model * vec4(aPos, 1.0);
float texX, texY;
texX = (curV.x + (terrainSize / 2)) / terrainSize;
texY = (curV.z + (terrainSize / 2)) / terrainSize;
vs_out.FragPos = vec3(curV);
vs_out.TexCoords = vec2(texX, texY);
vec3 T = normalize(mat3(model) * aTangent);
vec3 B = normalize(mat3(model) * aBitangent);
vec3 N = normalize(mat3(model) * aNormal);
mat3 TBN = transpose(mat3(T, B, N));
vs_out.TangentLightPos = TBN * lightPos;
vs_out.TangentViewPos = TBN * viewPos;
vs_out.TangentFragPos = TBN * vec3(curV);
vPosition = vec3(aPos.x, 1.f, aPos.z);
vTexCoord = vec2(texX, texY);
gl_Position = vec4(aPos.x, 1.f, aPos.z, 1.0);
}