From 934044e0a99bb7689258967e0e3a6f23a57aa0a4 Mon Sep 17 00:00:00 2001 From: stele Date: Fri, 3 May 2019 17:48:42 +0200 Subject: [PATCH] Z-normal reconstruction for water shader. --- shaders/mat_parallax.frag | 2 +- shaders/mat_water.frag | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/shaders/mat_parallax.frag b/shaders/mat_parallax.frag index 1cca810a..41b11a63 100644 --- a/shaders/mat_parallax.frag +++ b/shaders/mat_parallax.frag @@ -52,7 +52,7 @@ void main() if (tex_color.a < opacity) discard; - vec3 normal = f_normal; + vec3 normal; normal.xy = (texture(normalmap, f_coord_p).rg * 2.0 - 1.0); normal.z = sqrt(1 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0)); normal_p = normalize(f_tbn * normalize(normal.xyz)); diff --git a/shaders/mat_water.frag b/shaders/mat_water.frag index 2b0649bf..3eba83ea 100644 --- a/shaders/mat_water.frag +++ b/shaders/mat_water.frag @@ -56,7 +56,10 @@ void main() vec2 total_distorted_tex_coord = (texture(dudvmap, distorted_tex_coord).rg * 2.0 - 1.0 ) * param[2].y; texture_coords += total_distorted_tex_coord; - normal_d = f_tbn * normalize(texture(normalmap, texture_coords).rgb * 2.0 - 1.0); + vec3 normal; + normal.xy = (texture(normalmap, texture_coords).rg * 2.0 - 1.0); + normal.z = sqrt(1 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0)); + normal_d = normalize(f_tbn * normalize(normal.xyz)); vec3 refvec = reflect(f_pos.xyz, normal_d); #if ENVMAP_ENABLED vec3 envcolor = texture(envmap, refvec).rgb;