65 lines
1.4 KiB
GLSL
65 lines
1.4 KiB
GLSL
#version 330
|
|
|
|
layout (location = 0) in vec3 aPos;
|
|
layout (location = 1) in vec3 aTex;
|
|
layout (location = 2) in vec2 aTexY;
|
|
layout (location = 3) in vec3 aChunkOffset;
|
|
layout (location = 4) in vec3 aFlags;
|
|
|
|
out vec3 pLightMapPos;
|
|
out vec3 pTexture;
|
|
out vec3 pPos;
|
|
|
|
flat out int pFlags;
|
|
|
|
uniform mat4 billboard;
|
|
uniform mat4 projection;
|
|
uniform mat4 model;
|
|
uniform mat4 rotated;
|
|
uniform int time;
|
|
|
|
float map(float x, float in_min, float in_max, float out_min, float out_max) {
|
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
|
}
|
|
|
|
mat4 translate(vec3 vec)
|
|
{
|
|
mat4 result = mat4(1);
|
|
|
|
result[0][3] = vec.x;
|
|
result[1][3] = vec.y;
|
|
result[2][3] = vec.z;
|
|
|
|
return result;
|
|
}
|
|
|
|
float getTexY()
|
|
{
|
|
float animate_count = aFlags.x;
|
|
float animate_speed = aFlags.y;
|
|
float animate_index = mod(time / int(animate_speed), animate_count);
|
|
|
|
float tex_y_size = (aTexY.y - aTexY.x) / animate_count;
|
|
|
|
float tex_y = map(
|
|
aTex.y, aTexY.x, aTexY.y,
|
|
aTexY.x + tex_y_size * animate_index,
|
|
aTexY.x + tex_y_size * (animate_index + 1));
|
|
|
|
return tex_y;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
int type = int(aFlags.z);
|
|
|
|
vec4 pos = vec4(aPos, 1) * (mod(type >> 4, 2) == 1 ? billboard : (mod(type, 2) == 1 ? rotated : mat4(1))) *
|
|
translate(aChunkOffset) * model;
|
|
|
|
gl_Position = pos * projection;
|
|
pLightMapPos = pos.xyz;
|
|
|
|
pTexture = vec3(aTex.x, getTexY(), aTex.z);
|
|
pFlags = type;
|
|
pPos = aPos;
|
|
} |