Merge branch 'capucho/player-effects' into 'master'

Fix the problems of players walking over water with dithering

See merge request veloren/veloren!890
This commit is contained in:
Imbris 2020-04-07 22:50:02 +00:00
commit 611359e52f
4 changed files with 39 additions and 13 deletions

View File

@ -46,13 +46,15 @@ void main() {
vec3 fog_color = get_sky_color(normalize(f_pos - cam_pos.xyz), time_of_day.x, cam_pos.xyz, f_pos, 0.5, true, clouds);
vec3 color = mix(mix(surf_color, fog_color, fog_level), clouds.rgb, clouds.a);
float opacity = 1.0;
if ((flags & 1) == 1 && int(cam_mode) == 1) {
float distance = distance(vec3(cam_pos), f_pos) - 1;
float distance = distance(vec3(cam_pos), vec3(model_mat * vec4(vec3(0), 1))) - 2;
float opacity = clamp(distance / distance_divider, 0, 1);
opacity = clamp(distance / 3, 0, 1);
if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
discard;
}
}
tgt_color = vec4(color, opacity);
tgt_color = vec4(color, 1.0);
}

View File

@ -13,5 +13,17 @@ uniform u_globals {
uvec4 medium;
ivec4 select_pos;
vec4 gamma;
// 0 - FirstPerson
// 1 - ThirdPerson
uint cam_mode;
};
// Specifies the pattern used in the player dithering
mat4 threshold_matrix = mat4(
vec4(1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0),
vec4(13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0),
vec4(4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0),
vec4(16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0)
);
float distance_divider = 2;
float shadow_dithering = 0.5;

View File

@ -29,5 +29,17 @@ uniform u_bones {
out vec4 tgt_color;
void main() {
float distance = distance(vec3(cam_pos), vec3(model_mat * vec4(vec3(0), 1))) - 2;
float opacity = clamp(distance / distance_divider, 0, 1);
if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > opacity) {
discard;
}
if(threshold_matrix[int(gl_FragCoord.x) % 4][int(gl_FragCoord.y) % 4] > shadow_dithering) {
discard;
}
tgt_color = vec4(0.0,0.0,0.0, 1.0);
}

View File

@ -403,14 +403,6 @@ impl Scene {
// Render the skybox.
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
self.terrain.render_translucent(
renderer,
&self.globals,
&self.lights,
&self.shadows,
self.camera.get_focus_pos(),
);
self.figure_mgr.render_player(
renderer,
state,
@ -422,6 +414,14 @@ impl Scene {
&self.camera,
);
self.terrain.render_translucent(
renderer,
&self.globals,
&self.lights,
&self.shadows,
self.camera.get_focus_pos(),
);
renderer.render_post_process(
&self.postprocess.model,
&self.globals,