src/mcrt/scene.cc
// Store the resulting photons in the photons vector.
Store the resulting photons in the photons vector.
Store the resulting photons in the photons vector .
bool Scene::photonTrace(const Ray& ray, const glm::dvec3& partialFlux, const size_t depth = 0) {
        if(depth >= Scene::maxRayDepth)
            return false;
        Ray::Intersection rayHit = intersect(ray);
        glm::dvec3 rayHitPosition { ray.origin + ray.direction * rayHit.distance };
        if (rayHit.material == nullptr) return false;
        if(rayHit.material->type == Material::Type::Diffuse) {
            getPhotons(ray, partialFlux);
            return true;
        } else if(rayHit.material->type == Material::Type::Reflective) {
            Ray reflectionRay { ray.reflect(rayHitPosition, rayHit.normal) };
            return photonTrace(reflectionRay, partialFlux, depth + 1);
        } else if(rayHit.material->type == Material::Type::Refractive) {
            double kr = ray.fresnel(rayHit.normal, rayHit.material->refractionIndex);
            bool outside = glm::dot(ray.direction, rayHit.normal) < 0.0;
            if(kr < 1.0) { 
                Ray refractionRay { ray.refract(rayHitPosition, rayHit.normal,
                                                rayHit.material->refractionIndex) };
                return photonTrace(refractionRay, partialFlux, depth + 1);
            }
            Ray reflectionRay; 
            if (outside) reflectionRay = ray.reflect(rayHitPosition, rayHit.normal);
            else reflectionRay = ray.insideReflect(rayHitPosition, rayHit.normal);
            return photonTrace(reflectionRay, partialFlux, depth + 1);
        } else if(rayHit.material->type == Material::Type::LightSource) {
            return false;
        }
        return false;
    }
bool Scene :: photonTrace ( const Ray & ray , const glm :: dvec3 & partialFlux , const size_t depth = 0 ) { if ( depth >= Scene :: maxRayDepth ) return false ; Ray :: Intersection rayHit = intersect ( ray ) ; glm :: dvec3 rayHitPosition { ray . origin + ray . direction * rayHit . distance } ; if ( rayHit . material == nullptr ) return false ; if ( rayHit . material -> type == Material :: Type :: Diffuse ) { getPhotons ( ray , partialFlux ) ; return true ; } else if ( rayHit . material -> type == Material :: Type :: Reflective ) { Ray reflectionRay { ray . reflect ( rayHitPosition , rayHit . normal ) } ; return photonTrace ( reflectionRay , partialFlux , depth + 1 ) ; } else if ( rayHit . material -> type == Material :: Type :: Refractive ) { double kr = ray . fresnel ( rayHit . normal , rayHit . material -> refractionIndex ) ; bool outside = glm :: dot ( ray . direction , rayHit . normal ) < 0.0 ; if ( kr < 1.0 ) { Ray refractionRay { ray . refract ( rayHitPosition , rayHit . normal , rayHit . material -> refractionIndex ) } ; return photonTrace ( refractionRay , partialFlux , depth + 1 ) ; } Ray reflectionRay ; if ( outside ) reflectionRay = ray . reflect ( rayHitPosition , rayHit . normal ) ; else reflectionRay = ray . insideReflect ( rayHitPosition , rayHit . normal ) ; return photonTrace ( reflectionRay , partialFlux , depth + 1 ) ; } else if ( rayHit . material -> type == Material :: Type :: LightSource ) { return false ; } return false ; }
Store the resulting photons in the photons vector.
Store the resulting photons in the photons vector .
// Make sure we don't bounce forever // We have hit nothing or something like that I guess..... // We terminate path // Check if ray isn't completely parallel to graze. // If we need to invert the bias if we are inside.