         const vec3 kS_env = F_env;
         const vec3 kD_env = (1.0 - kS_env) * (1.0 - metallic);
 
-        const vec3 filtered = textureLod(environment_samplers[i], corrected_r, mip_level).rgb;
+        const vec3 filtered = textureLod(environment_samplers[i], corrected_R, mip_level).rgb;
         const vec2 brdf  = texture(brdf_lut, vec2(NdotV, roughness)).rg;
 
         const float refractive_index = 1.5;
-        const vec3 refracted_direction = refract(V, normal, 1.0 / refractive_index);
-        const vec3 corrected_refract_direction = box_correct(environments[i].extent, environments[i].position, refracted_direction, fragment.position);
-        const vec3 refraction = textureLod(environment_samplers[i], corrected_refract_direction, mip_level).rgb * material.transmission;
-
-        float horiz = dot(corrected_r, normal);
+        const vec3 RF = refract(V, N, 1.0 / refractive_index);
+        const vec3 corrected_RF = box_correct(environments[i].extent, environments[i].position, RF, fragment.position);
+        const vec3 refraction = textureLod(environment_samplers[i], corrected_RF, mip_level).rgb * material.transmission;
+
+        float horiz = dot(corrected_R,N);
         const float horiz_fade_power = 1.0 - roughness;
         horiz = clamp( 1.0 + horiz_fade_power * horiz, 0.0, 1.0 );
         horiz *= horiz;


    for (int i = 0; i < environments.length(); i++) {
      if (environments[i].strength > 0.0 && inside_box(fragment.position, environments[i].position, environments[i].extent)) {
        const vec3 corrected_normal = box_correct(environments[i].extent, environments[i].position,normal, fragment.position);
        const vec3 corrected_r = box_correct(environments[i].extent, environments[i].position, R, fragment.position);

        const vec2 environment_texture_size = textureSize(environment_samplers[i], 0);
        const float maxsize = max(environment_texture_size.x, environment_texture_size.x);

            const vec3 L = normalize(light.position - fragment.position);
            const vec3 H = normalize(V + L);

            const float NdotL = max(dot(N, L), 0.0);

            const vec3 shadow_map_uv = fragment.proj_shadow[i].xyz / fragment.proj_shadow[i].w;
            const vec2 texel_size = 1.0 / textureSize(shadow_maps[i], 0);
