41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
|
#version 300 es
|
||
|
|
||
|
#define BASE_COLOR vec4(1.0, 1.0, 1.0, 1.0)
|
||
|
#define AMBIENT_LIGHT vec3(0.3, 0.3, 0.3)
|
||
|
#define LIGHT_DIRECTION normalize(vec3(0.85, 0.8, 0.75))
|
||
|
#define LIGHT_COLOR vec3(1.0, 1.0, 1.0)
|
||
|
|
||
|
precision highp float;
|
||
|
|
||
|
layout(location = 0) in vec4 aVertexPosition;
|
||
|
layout(location = 1) in vec3 aVertexNormal;
|
||
|
layout(location = 2) in float aHeight;
|
||
|
flat out vec4 vColor;
|
||
|
|
||
|
uniform mat4 uModelViewMatrix;
|
||
|
uniform mat4 uProjectionMatrix;
|
||
|
uniform mat4 uNormalMatrix;
|
||
|
|
||
|
void main() {
|
||
|
float instanceX =
|
||
|
aVertexPosition.x + float(gl_InstanceID) * 2.0 * abs(aVertexPosition.x);
|
||
|
float vertexY =
|
||
|
aVertexPosition.y > 0.0 ? aVertexPosition.y * aHeight : aVertexPosition.y;
|
||
|
|
||
|
gl_Position = uProjectionMatrix * uModelViewMatrix *
|
||
|
vec4(instanceX, vertexY, aVertexPosition.zw);
|
||
|
|
||
|
vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);
|
||
|
float directionalLight =
|
||
|
max(dot(transformedNormal.xyz, LIGHT_DIRECTION), 0.0);
|
||
|
|
||
|
if (aHeight == 0.0) {
|
||
|
vColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||
|
} else {
|
||
|
vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);
|
||
|
float directionalLight =
|
||
|
max(dot(transformedNormal.xyz, LIGHT_DIRECTION), 0.0);
|
||
|
vColor = vec4(AMBIENT_LIGHT + (directionalLight * LIGHT_COLOR), 1.0);
|
||
|
}
|
||
|
}
|