mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Move computations to terrain fragment shaders
This commit is contained in:
parent
c01e19fc05
commit
3279a278b7
@ -4,7 +4,7 @@
|
||||
#include <random.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
flat in vec3 f_norm;
|
||||
flat in uint f_pos_norm;
|
||||
in vec3 f_col;
|
||||
in float f_light;
|
||||
|
||||
@ -26,6 +26,16 @@ vec3 warp_normal(vec3 norm, vec3 pos, float time) {
|
||||
}
|
||||
|
||||
void main() {
|
||||
// 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) );
|
||||
|
||||
// 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 = (f_pos_norm >> 30) & 0x3u;
|
||||
// Increase array access by 3 to access positive values
|
||||
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// Use an array to avoid conditional branching
|
||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
||||
|
||||
/*
|
||||
// Round the position to the nearest triangular grid cell
|
||||
vec3 hex_pos = f_pos * 2.0;
|
||||
@ -46,7 +56,7 @@ void main() {
|
||||
vec3 point_light = light_at(f_pos, f_norm);
|
||||
light += point_light;
|
||||
diffuse_light += point_light;
|
||||
vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||
vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
||||
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);
|
||||
|
@ -13,13 +13,11 @@ uniform u_locals {
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
flat out uint f_pos_norm;
|
||||
flat out vec3 f_norm;
|
||||
out vec3 f_col;
|
||||
out float f_light;
|
||||
|
||||
// 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) );
|
||||
|
||||
void main() {
|
||||
f_pos = vec3(
|
||||
float((v_pos_norm >> 0) & 0x00FFu),
|
||||
@ -27,23 +25,16 @@ void main() {
|
||||
float((v_pos_norm >> 16) & 0x1FFFu)
|
||||
) + model_offs;
|
||||
|
||||
// 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];
|
||||
|
||||
f_col = srgb_to_linear(vec3(
|
||||
f_col = vec3(
|
||||
float((v_col_light >> 8) & 0xFFu),
|
||||
float((v_col_light >> 16) & 0xFFu),
|
||||
float((v_col_light >> 24) & 0xFFu)
|
||||
) / 255.0);
|
||||
) / 255.0;
|
||||
|
||||
f_light = float(v_col_light & 0xFFu) / 255.0;
|
||||
|
||||
f_pos_norm = v_pos_norm;
|
||||
|
||||
gl_Position =
|
||||
proj_mat *
|
||||
view_mat *
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <globals.glsl>
|
||||
|
||||
in vec3 f_pos;
|
||||
flat in vec3 f_norm;
|
||||
flat in uint f_pos_norm;
|
||||
in vec3 f_col;
|
||||
in float f_light;
|
||||
|
||||
@ -19,6 +19,16 @@ out vec4 tgt_color;
|
||||
#include <light.glsl>
|
||||
|
||||
void main() {
|
||||
// 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) );
|
||||
|
||||
// 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 = (f_pos_norm >> 30) & 0x3u;
|
||||
// Increase array access by 3 to access positive values
|
||||
uint norm_dir = ((f_pos_norm >> 29) & 0x1u) * 3u;
|
||||
// Use an array to avoid conditional branching
|
||||
vec3 f_norm = normals[norm_axis + norm_dir];
|
||||
|
||||
vec3 light, diffuse_light, ambient_light;
|
||||
get_sun_diffuse(f_norm, time_of_day.x, light, diffuse_light, ambient_light, 1.0);
|
||||
float point_shadow = shadow_at(f_pos, f_norm);
|
||||
@ -27,7 +37,7 @@ void main() {
|
||||
vec3 point_light = light_at(f_pos, f_norm);
|
||||
light += point_light;
|
||||
diffuse_light += point_light;
|
||||
vec3 surf_color = illuminate(f_col, light, diffuse_light, ambient_light);
|
||||
vec3 surf_color = illuminate(srgb_to_linear(f_col), light, diffuse_light, ambient_light);
|
||||
|
||||
float fog_level = fog(f_pos.xyz, focus_pos.xyz, medium.x);
|
||||
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, true);
|
||||
|
@ -13,13 +13,10 @@ uniform u_locals {
|
||||
};
|
||||
|
||||
out vec3 f_pos;
|
||||
flat out vec3 f_norm;
|
||||
flat out uint f_pos_norm;
|
||||
out vec3 f_col;
|
||||
out float f_light;
|
||||
|
||||
// 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) );
|
||||
|
||||
void main() {
|
||||
f_pos = vec3(
|
||||
float((v_pos_norm >> 0) & 0x00FFu),
|
||||
@ -29,23 +26,16 @@ void main() {
|
||||
|
||||
f_pos.z *= min(1.0001 - 0.02 / pow(tick.x - load_time, 10.0), 1.0);
|
||||
|
||||
// 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];
|
||||
|
||||
f_col = srgb_to_linear(vec3(
|
||||
f_col = vec3(
|
||||
float((v_col_light >> 8) & 0xFFu),
|
||||
float((v_col_light >> 16) & 0xFFu),
|
||||
float((v_col_light >> 24) & 0xFFu)
|
||||
) / 255.0);
|
||||
) / 255.0;
|
||||
|
||||
f_light = float(v_col_light & 0xFFu) / 255.0;
|
||||
|
||||
f_pos_norm = v_pos_norm;
|
||||
|
||||
gl_Position =
|
||||
proj_mat *
|
||||
view_mat *
|
||||
|
Loading…
Reference in New Issue
Block a user