2019-01-14 23:13:58 +00:00
|
|
|
#version 330 core
|
|
|
|
|
2019-05-12 09:10:13 +00:00
|
|
|
#include <globals.glsl>
|
2019-08-04 21:07:29 +00:00
|
|
|
#include <srgb.glsl>
|
2019-05-12 09:10:13 +00:00
|
|
|
|
2019-06-03 21:35:03 +00:00
|
|
|
in uint v_pos_norm;
|
|
|
|
in uint v_col_light;
|
2019-01-14 23:13:58 +00:00
|
|
|
|
|
|
|
layout (std140)
|
|
|
|
uniform u_locals {
|
|
|
|
vec3 model_offs;
|
2019-09-24 15:43:51 +00:00
|
|
|
float load_time;
|
2019-01-14 23:13:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
out vec3 f_pos;
|
2019-08-03 09:55:45 +00:00
|
|
|
flat out vec3 f_norm;
|
2019-01-14 23:13:58 +00:00
|
|
|
out vec3 f_col;
|
2019-05-31 20:37:11 +00:00
|
|
|
out float f_light;
|
2019-01-14 23:13:58 +00:00
|
|
|
|
2019-08-03 09:55:45 +00:00
|
|
|
// First 3 normals are negative, next 3 are positive
|
|
|
|
vec3 normals[6] = vec3[]( vec3(-1,0,0), vec3(0,-1,0), vec3(0,0,-1), vec3(1,0,0), vec3(0,1,0), vec3(0,0,1) );
|
|
|
|
|
2019-01-14 23:13:58 +00:00
|
|
|
void main() {
|
2019-05-22 18:30:18 +00:00
|
|
|
f_pos = vec3(
|
2019-06-03 21:35:03 +00:00
|
|
|
float((v_pos_norm >> 0) & 0x00FFu),
|
|
|
|
float((v_pos_norm >> 8) & 0x00FFu),
|
|
|
|
float((v_pos_norm >> 16) & 0x1FFFu)
|
2019-05-31 20:37:11 +00:00
|
|
|
) + model_offs;
|
2019-05-22 18:30:18 +00:00
|
|
|
|
2019-09-24 15:43:51 +00:00
|
|
|
f_pos.z *= min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0);
|
|
|
|
|
2019-08-03 09:55:45 +00:00
|
|
|
// TODO: last 3 bits in v_pos_norm should be a number between 0 and 5, rather than 0-2 and a direction.
|
|
|
|
uint norm_axis = (v_pos_norm >> 30) & 0x3u;
|
|
|
|
|
|
|
|
// Increase array access by 3 to access positive values
|
|
|
|
uint norm_dir = ((v_pos_norm >> 29) & 0x1u) * 3u;
|
|
|
|
|
|
|
|
// Use an array to avoid conditional branching
|
|
|
|
f_norm = normals[norm_axis + norm_dir];
|
2019-06-04 13:27:19 +00:00
|
|
|
|
2019-08-04 21:07:29 +00:00
|
|
|
f_col = srgb_to_linear(vec3(
|
2019-06-03 21:35:03 +00:00
|
|
|
float((v_col_light >> 8) & 0xFFu),
|
|
|
|
float((v_col_light >> 16) & 0xFFu),
|
|
|
|
float((v_col_light >> 24) & 0xFFu)
|
2019-08-04 21:07:29 +00:00
|
|
|
) / 255.0);
|
2019-01-14 23:13:58 +00:00
|
|
|
|
2019-06-03 21:35:03 +00:00
|
|
|
f_light = float(v_col_light & 0xFFu) / 255.0;
|
2019-05-31 20:37:11 +00:00
|
|
|
|
2019-01-14 23:13:58 +00:00
|
|
|
gl_Position =
|
|
|
|
proj_mat *
|
|
|
|
view_mat *
|
2019-05-31 20:37:11 +00:00
|
|
|
vec4(f_pos, 1);
|
2019-08-28 18:32:44 +00:00
|
|
|
}
|