Пример #1
0
    void PhotonMap::BuildIndirectPhotonMap(int32_t n)
    {
        for ( LightIter iter = scene->mLights.begin(); iter != scene->mLights.end(); iter++ ) {
            Light *light = *iter;
            int32_t nPhotons = (int) (n * light->mIntensity);
            for ( int32_t i = 0; i < nPhotons; i++ ) {
                Color color;
                Vector pi, dir;
                Shape *shape = NULL;

                while ( true ) {
                    if ( confEnableDirectedPhotons ) {
                        Vector r(gRandom.Rand(), gRandom.Rand(), gRandom.Rand());
                        dir = confPhotonDirectedP1 + r * (confPhotonDirectedP2 - confPhotonDirectedP1) 
                            - light->GetCentroid();
                        dir.Normalize();
                    } else {
                        dir = light->RandomDirection(gRandom);
                    }
                    float dist = MAXDISTANCE;
                    if ( scene->FindNearest(Ray(light->GetCentroid(), dir), dist, shape) == IR_MISS ) 
                        continue;
                    pi = light->GetCentroid() + dir * dist;
                    color = light->Sample(pi);
                    if ( !color.IsBlack() ) break;
                }
                ShootIndirectPhoton(dir, pi, color, shape, 0);
            }
        }
    }