         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;

}

void main() {
    vec3 normal = fragment.normal;

    vec3 normal_from_map = texture(material.normal_map, fragment.uv).rgb * 2.0 - vec3(1.0);
    normal_from_map = normalize(fragment.tbn * normal_from_map);

    float amount = texture(material.normal_map, fragment.uv).a;

    if (amount > 0.0f){
        normal = normalize(mix(normal, normal_from_map, amount));
    }

    vec4 albedo_from_map = texture(material.albedo_map, fragment.uv);

    }

    const vec3 V = normalize(camera.position - fragment.position);
    const vec3 R = -reflect(fragment.camera_to_surface, N);

    const float NdotV = max(dot(N, V), 0.0);

    vec3 F0 = vec3(0.04);
    F0 = mix(F0, albedo, metallic);
