diff --git a/shaders/light_common.glsl b/shaders/light_common.glsl index aed7d107..8fc8216f 100644 --- a/shaders/light_common.glsl +++ b/shaders/light_common.glsl @@ -30,9 +30,11 @@ float calc_shadow() vec2 calc_light(vec3 light_dir) { #ifdef NORMALMAP - vec3 normal = normalize(f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0)); + vec3 normal = normal; #elif defined(WATER) vec3 normal = normal_d; +#elif defined(PARALLAX) + vec3 normal = normal_p; #else vec3 normal = normalize(f_normal); #endif diff --git a/shaders/mat_normalmap.frag b/shaders/mat_normalmap.frag index c4b7a4fa..cae429aa 100644 --- a/shaders/mat_normalmap.frag +++ b/shaders/mat_normalmap.frag @@ -33,6 +33,8 @@ uniform sampler2DShadow shadowmap; uniform samplerCube envmap; #endif +vec3 normal; + #define NORMALMAP #include #include @@ -44,7 +46,10 @@ void main() if (tex_color.a < opacity) discard; - vec3 normal = normalize(f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0)); + normal.xy = (texture(normalmap, f_coord).rg * 2.0 - 1.0); + normal.z = sqrt(1 - clamp((dot(normal.xy, normal.xy)), 0.0, 1.0)); + normal = normalize(f_tbn * normalize(normal.xyz)); + //vec3 normal = normalize(f_tbn * normalize(texture(normalmap, f_coord).rgb * 2.0 - 1.0)); vec3 refvec = reflect(f_pos.xyz, normal); #if ENVMAP_ENABLED vec3 envcolor = texture(envmap, refvec).rgb; diff --git a/shaders/mat_parallax.frag b/shaders/mat_parallax.frag index 2f248f22..1cca810a 100644 --- a/shaders/mat_parallax.frag +++ b/shaders/mat_parallax.frag @@ -35,7 +35,8 @@ uniform sampler2DShadow shadowmap; uniform samplerCube envmap; #endif -#define NORMALMAP +vec3 normal_p; +#define PARALLAX #include #include @@ -51,8 +52,11 @@ void main() if (tex_color.a < opacity) discard; - vec3 normal = normalize(f_tbn * normalize(texture(normalmap, f_coord_p).rgb * 2.0 - 1.0)); - vec3 refvec = reflect(f_pos.xyz, normal); + vec3 normal = f_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)); + vec3 refvec = reflect(f_pos.xyz, normal_p); #if ENVMAP_ENABLED vec3 envcolor = texture(envmap, refvec).rgb; #else diff --git a/shaders/vertex.vert b/shaders/vertex.vert index 7e4ea253..76a4f93b 100644 --- a/shaders/vertex.vert +++ b/shaders/vertex.vert @@ -8,20 +8,24 @@ flat out vec3 f_normal_raw; out vec2 f_coord; out vec4 f_pos; out mat3 f_tbn; -out vec4 f_tangent; +//out vec4 f_tangent; out vec4 f_light_pos; -out vec3 TangentFragPos; + out vec4 f_clip_pos; out vec4 f_clip_future_pos; +//out vec3 TangentLightPos; +//out vec3 TangentViewPos; +out vec3 TangentFragPos; + #include void main() { - f_normal = modelviewnormal * v_normal; + f_normal = normalize(modelviewnormal * v_normal); f_normal_raw = v_normal; f_coord = v_coord; - f_tangent = v_tangent; +// f_tangent = v_tangent; f_pos = modelview * vec4(v_vert, 1.0f); f_light_pos = lightview * f_pos; @@ -32,9 +36,12 @@ void main() gl_PointSize = param[1].x; vec3 T = normalize(modelviewnormal * v_tangent.xyz); - vec3 B = normalize(modelviewnormal * cross(v_normal, v_tangent.xyz) * v_tangent.w); - vec3 N = normalize(modelviewnormal * v_normal); + vec3 N = f_normal; + vec3 B = normalize(cross(N, T)); f_tbn = mat3(T, B, N); - mat3 TBN = transpose(mat3(T, B, N)); + + mat3 TBN = transpose(f_tbn); +// TangentLightPos = TBN * f_light_pos.xyz; +// TangentViewPos = TBN * vec3(0.0f, 0.0f, 0.0f); TangentFragPos = TBN * f_pos.xyz; }