 vec3 fresnel_schlick_roughness(float cosTheta, vec3 F0, float roughness);
 float fog_attenuation(const float dist, const float factor);
 
+bool inside_box(const vec3 point, const vec3 position, const vec3 extent) {
+  vec3 mi = position - extent;
+  vec3 ma = position + extent;
+  return (mi.x <= point.x
+      && point.x <= ma.x
+      && mi.y <= point.y
+      && point.y <= ma.y
+      && mi.z <= point.z
+      && point.z <= ma.z);
+}
+
 void main() {
     vec3 normal = fragment.normal;
 

    vec3 ambient = vec3(0.0, 0.0, 0.0);

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

        irradiance /= 8.0;

        const vec3 diffuse_environment = irradiance * albedo * environments[i].strength;
        ambient += clamp((kD_env * diffuse_environment * (1.0 - material.transmission) + specular_environment) * ambient_occlusion, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));
        break;
      }
    }
    out_color.rgb = (1.0 - material.emission) * (direct + ambient) + material.emission * albedo;
