             const float attenuation = 1.0 / (light_fragment_distance * light_fragment_distance);
             const vec3 radiance = light.strength * 0.09 * light.color * attenuation;
 
-            const float NDF = distribution_GGX(normal, H, roughness);
-            const float G = geometry_smith(normal, V, L, roughness);
+            const float NDF = distribution_GGX(N, H, roughness);
+            const float G = geometry_smith(N, V, L, roughness);
             const vec3 F = fresnel_schlick(clamp(dot(H, V), 0.0, 1.0), F0);
 
             const vec3 nominator = NDF * G * F;

        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 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 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_N = box_correct(environments[i].extent, environments[i].position, N, 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);
