veloren/assets/voxygen/shaders/terrain-vert.glsl
2020-04-24 16:12:20 +02:00

44 lines
1.0 KiB
GLSL

#version 330 core
#include <globals.glsl>
#include <srgb.glsl>
#include <lod.glsl>
in uint v_pos_norm;
in uint v_col_light;
layout (std140)
uniform u_locals {
vec3 model_offs;
float load_time;
};
out vec3 f_pos;
flat out uint f_pos_norm;
out float f_alt;
out vec4 f_shadow;
out vec3 f_col;
out float f_light;
void main() {
f_pos = vec3((uvec3(v_pos_norm) >> uvec3(0, 8, 16)) & uvec3(0xFFu, 0xFFu, 0x1FFFu)) + model_offs;
f_pos.z *= min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0);
f_pos.z -= min(32.0, pow(distance(focus_pos.xy, f_pos.xy) / (view_distance.x * 0.95), 20.0));
f_col = srgb_to_linear(vec3((uvec3(v_col_light) >> uvec3(8, 16, 24)) & uvec3(0xFFu)) / 255.0);
f_light = float(v_col_light & 0xFFu) / 255.0;
f_pos_norm = v_pos_norm;
// Also precalculate shadow texture and estimated terrain altitude.
f_alt = alt_at(f_pos.xy);
f_shadow = textureBicubic(t_horizon, pos_to_tex(f_pos.xy));
gl_Position =
all_mat *
vec4(f_pos, 1);
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
}