float PointInShadow(const glm::vec3& point, RayTracerState& state) { Ray shadow_ray(point, position-point); const float z_offset = 10e-4f; float t = -1; float t_min = std::numeric_limits<float>::max(); int k_min=-1; //Loop through all the objects, to find the closest intersection, if any for (unsigned int k=0; k<state.getScene().size(); ++k) { t = state.getScene().at(k)->intersect(shadow_ray); //skipping the cubemap if(t >= (std::numeric_limits<float>::max())) continue; if (t > z_offset && t <= t_min) { k_min = k; t_min = t; } } if (k_min >= 0) { glm::vec3 q = point + shadow_ray.getDirection()*t_min; float light_length = glm::length(position-point); float q_lenght = glm::length(q); if(q_lenght < light_length) return 0.0f; } return 1.0f; }