fix_code() { { yy yyb; yy yy_2_1; yy yy_4_1; yy yy_6_1; yy yy_8_1_1; yy yy_8_1_2_1; yy yy_8_2_1_1; yy yy_8_2_3_1; yy yy_9_1; yy yy_11_1; yy yy_13_1; yy yy_15_1; yy yy_17_1; yy yy_19_1; yy yy_21_1; yy yy_23_1; yy yy_25_1; yy yy_27_1; yy yy_29_1; yy yy_31_1; yy yy_33_1; yy yy_35_1; yy yy_37_1; yy yy_39_1; yy yy_41_1; yy yy_43_1; yy yy_45_1; yy yy_47_1; yy yy_49_1; yy yy_51_1; yy yy_53_1; yy yy_55_1; yy yy_57_1; yy yy_59_1; yy yy_61_1; yy yy_63_1; yy yy_65_1; yy yy_67_1; yy yy_69_1; yy yy_71_1; yy yy_73_1; yy yy_75_1; yy yy_77_1; yy yy_79_1; yy yy_81_1; yy yy_83_1; yy yy_85_1; yy yy_87_1; yy yy_89_1; yy yy_91_1; yy yy_93_1; yy yy_95_1; yy yy_97_1; yy yy_99_1; yy yy_101_1; Nl(); yy_2_1 = ((yy)"extern YYSTYPE yylval;"); Put(yy_2_1); Nl(); yy_4_1 = ((yy)"YYSTYPE yylval;"); Put(yy_4_1); Nl(); yy_6_1 = ((yy)"extern long yypos;"); Put(yy_6_1); Nl(); { yy yysb = yyb; yy_8_1_1 = yyglov_GentleFlag; if (yy_8_1_1 == (yy) yyu) yyErr(1,41); if (yy_8_1_1[0] != 1) goto yyfl_3_1_8_1; yy_8_1_2_1 = ((yy)"/* GentleFlag = yes */"); Put(yy_8_1_2_1); Nl(); goto yysl_3_1_8; yyfl_3_1_8_1 : ; yy_8_2_1_1 = ((yy)"long yypos = 1;"); Put(yy_8_2_1_1); Nl(); yy_8_2_3_1 = ((yy)"/* GentleFlag = no */"); Put(yy_8_2_3_1); Nl(); goto yysl_3_1_8; yysl_3_1_8 : ; yyb = yysb; } yy_9_1 = ((yy)""); Put(yy_9_1); Nl(); yy_11_1 = ((yy)"typedef struct LEXELEMSTRUCT {"); Put(yy_11_1); Nl(); yy_13_1 = ((yy)" YYSTYPE val;"); Put(yy_13_1); Nl(); yy_15_1 = ((yy)" long pos;"); Put(yy_15_1); Nl(); yy_17_1 = ((yy)" long sym;"); Put(yy_17_1); Nl(); yy_19_1 = ((yy)" char * text;"); Put(yy_19_1); Nl(); yy_21_1 = ((yy)" struct LEXELEMSTRUCT *next;"); Put(yy_21_1); Nl(); yy_23_1 = ((yy)"} LEXELEM;"); Put(yy_23_1); Nl(); yy_25_1 = ((yy)" "); Put(yy_25_1); Nl(); yy_27_1 = ((yy)"LEXELEM *first_lexelem, *cur_lexelem;"); Put(yy_27_1); Nl(); yy_29_1 = ((yy)""); Put(yy_29_1); Nl(); yy_31_1 = ((yy)"init_lexelem()"); Put(yy_31_1); Nl(); yy_33_1 = ((yy)"{"); Put(yy_33_1); Nl(); yy_35_1 = ((yy)" cur_lexelem = first_lexelem;"); Put(yy_35_1); Nl(); yy_37_1 = ((yy)"}"); Put(yy_37_1); Nl(); yy_39_1 = ((yy)""); Put(yy_39_1); Nl(); yy_41_1 = ((yy)"first_lexval () {"); Put(yy_41_1); Nl(); yy_43_1 = ((yy)" LEXELEM *p;"); Put(yy_43_1); Nl(); yy_45_1 = ((yy)" p = (LEXELEM *)malloc(sizeof(LEXELEM));"); Put(yy_45_1); Nl(); yy_47_1 = ((yy)" if (! p) yymallocerror();"); Put(yy_47_1); Nl(); yy_49_1 = ((yy)" p->val = yylval;"); Put(yy_49_1); Nl(); yy_51_1 = ((yy)" p->pos = yypos;"); Put(yy_51_1); Nl(); yy_53_1 = ((yy)" p->next = 0;"); Put(yy_53_1); Nl(); yy_55_1 = ((yy)" cur_lexelem = p;"); Put(yy_55_1); Nl(); yy_57_1 = ((yy)" first_lexelem = p;"); Put(yy_57_1); Nl(); yy_59_1 = ((yy)"}"); Put(yy_59_1); Nl(); yy_61_1 = ((yy)""); Put(yy_61_1); Nl(); yy_63_1 = ((yy)"next_lexval() {"); Put(yy_63_1); Nl(); yy_65_1 = ((yy)" LEXELEM *p;"); Put(yy_65_1); Nl(); yy_67_1 = ((yy)" p = (LEXELEM *)malloc(sizeof(LEXELEM));"); Put(yy_67_1); Nl(); yy_69_1 = ((yy)" if (! p) yymallocerror();"); Put(yy_69_1); Nl(); yy_71_1 = ((yy)" cur_lexelem-> next = p;"); Put(yy_71_1); Nl(); yy_73_1 = ((yy)" p->val = yylval;"); Put(yy_73_1); Nl(); yy_75_1 = ((yy)" p->pos = yypos;"); Put(yy_75_1); Nl(); yy_77_1 = ((yy)" p->next = 0;"); Put(yy_77_1); Nl(); yy_79_1 = ((yy)" cur_lexelem = p;"); Put(yy_79_1); Nl(); yy_81_1 = ((yy)"}"); Put(yy_81_1); Nl(); yy_83_1 = ((yy)""); Put(yy_83_1); Nl(); yy_85_1 = ((yy)"get_lexval() {"); Put(yy_85_1); Nl(); yy_87_1 = ((yy)" extern int FREE_LEXELEMS;"); Put(yy_87_1); Nl(); yy_89_1 = ((yy)" LEXELEM *p;"); Put(yy_89_1); Nl(); yy_91_1 = ((yy)" yylval = cur_lexelem->val;"); Put(yy_91_1); Nl(); yy_93_1 = ((yy)" yypos = cur_lexelem->pos;"); Put(yy_93_1); Nl(); yy_95_1 = ((yy)" p = cur_lexelem;"); Put(yy_95_1); Nl(); yy_97_1 = ((yy)" cur_lexelem = cur_lexelem->next;"); Put(yy_97_1); Nl(); yy_99_1 = ((yy)" free(p);"); Put(yy_99_1); Nl(); yy_101_1 = ((yy)"}"); Put(yy_101_1); Nl(); Nl(); return; } }
void PhotonShootingTask::Run() { // Declare local variables for _PhotonShootingTask_ MemoryArena arena; RNG rng(31 * taskNum); vector<Photon> localDirectPhotons, localIndirectPhotons, localCausticPhotons; vector<RadiancePhoton> localRadiancePhotons; uint32_t totalPaths = 0; bool causticDone = (integrator->nCausticPhotonsWanted == 0); bool indirectDone = (integrator->nIndirectPhotonsWanted == 0); PermutedHalton halton(6, rng); vector<Spectrum> localRpReflectances, localRpTransmittances; while (true) { // Follow photon paths for a block of samples const uint32_t blockSize = 4096; for (uint32_t i = 0; i < blockSize; ++i) { float u[6]; halton.Sample(++totalPaths, u); // Choose light to shoot photon from float lightPdf; int lightNum = lightDistribution->SampleDiscrete(u[0], &lightPdf); const Light *light = scene.lights[lightNum]; // Generate _photonRay_ from light source and initialize _alpha_ LightSample ls(u[1], u[2], u[3]); LightInfo2 li = light->Sample_L(scene, ls, u[4], u[5], time); Spectrum Le(li.L); RayDifferential photonRay(li.ray); Normal Nl(li.N); if (li.pdf == 0.f || Le.IsBlack()) continue; Spectrum alpha = (AbsDot(Nl, photonRay.d) * Le) / (li.pdf * lightPdf); if (!alpha.IsBlack()) { // Follow photon path through scene and record intersections PBRT_PHOTON_MAP_STARTED_RAY_PATH(&photonRay, &alpha); bool specularPath = true; int nIntersections = 0; auto optPhotonIsect = scene.Intersect(photonRay); while (optPhotonIsect) { ++nIntersections; // Handle photon/surface intersection alpha *= renderer->Transmittance(scene, photonRay, NULL, rng, arena); BSDF *photonBSDF = optPhotonIsect->GetBSDF(photonRay, arena); BxDFType specularType = BxDFType(BSDF_REFLECTION | BSDF_TRANSMISSION | BSDF_SPECULAR); bool hasNonSpecular = (photonBSDF->NumComponents() > photonBSDF->NumComponents(specularType)); Vector wo = -photonRay.d; if (hasNonSpecular) { // Deposit photon at surface Photon photon(optPhotonIsect->dg.p, alpha, wo); bool depositedPhoton = false; if (specularPath && nIntersections > 1) { if (!causticDone) { PBRT_PHOTON_MAP_DEPOSITED_CAUSTIC_PHOTON(&optPhotonIsect->dg, &alpha, &wo); depositedPhoton = true; localCausticPhotons.push_back(photon); } } else { // Deposit either direct or indirect photon // stop depositing direct photons once indirectDone is true; don't // want to waste memory storing too many if we're going a long time // trying to get enough caustic photons desposited. if (nIntersections == 1 && !indirectDone && integrator->finalGather) { PBRT_PHOTON_MAP_DEPOSITED_DIRECT_PHOTON(&optPhotonIsect->dg, &alpha, &wo); depositedPhoton = true; localDirectPhotons.push_back(photon); } else if (nIntersections > 1 && !indirectDone) { PBRT_PHOTON_MAP_DEPOSITED_INDIRECT_PHOTON(&optPhotonIsect->dg, &alpha, &wo); depositedPhoton = true; localIndirectPhotons.push_back(photon); } } // Possibly create radiance photon at photon intersection point if (depositedPhoton && integrator->finalGather && rng.RandomFloat() < .125f) { Normal n = optPhotonIsect->dg.nn; n = Faceforward(n, -photonRay.d); localRadiancePhotons.push_back(RadiancePhoton(optPhotonIsect->dg.p, n)); Spectrum rho_r = photonBSDF->rho(rng, BSDF_ALL_REFLECTION); localRpReflectances.push_back(rho_r); Spectrum rho_t = photonBSDF->rho(rng, BSDF_ALL_TRANSMISSION); localRpTransmittances.push_back(rho_t); } } if (nIntersections >= integrator->maxPhotonDepth) break; // Sample new photon ray direction Vector wi; float pdf; BxDFType flags; Spectrum fr = photonBSDF->Sample_f(wo, &wi, BSDFSample(rng), &pdf, BSDF_ALL, &flags); if (fr.IsBlack() || pdf == 0.f) break; Spectrum anew = alpha * fr * AbsDot(wi, photonBSDF->dgShading.nn) / pdf; // Possibly terminate photon path with Russian roulette float continueProb = min(1.f, anew.y() / alpha.y()); if (rng.RandomFloat() > continueProb) break; alpha = anew / continueProb; specularPath &= ((flags & BSDF_SPECULAR) != 0); if (indirectDone && !specularPath) break; photonRay = RayDifferential(optPhotonIsect->dg.p, wi, photonRay, optPhotonIsect->rayEpsilon); optPhotonIsect = scene.Intersect(photonRay); } PBRT_PHOTON_MAP_FINISHED_RAY_PATH(&photonRay, &alpha); } arena.FreeAll(); } // Merge local photon data with data in _PhotonIntegrator_ { MutexLock lock(mutex); // Give up if we're not storing enough photons if (abortTasks) return; if (nshot > 500000 && (unsuccessful(integrator->nCausticPhotonsWanted, causticPhotons.size(), blockSize) || unsuccessful(integrator->nIndirectPhotonsWanted, indirectPhotons.size(), blockSize))) { Error("Unable to store enough photons. Giving up.\n"); causticPhotons.erase(causticPhotons.begin(), causticPhotons.end()); indirectPhotons.erase(indirectPhotons.begin(), indirectPhotons.end()); radiancePhotons.erase(radiancePhotons.begin(), radiancePhotons.end()); abortTasks = true; return; } progress.Update(localIndirectPhotons.size() + localCausticPhotons.size()); nshot += blockSize; // Merge indirect photons into shared array if (!indirectDone) { integrator->nIndirectPaths += blockSize; for (uint32_t i = 0; i < localIndirectPhotons.size(); ++i) indirectPhotons.push_back(localIndirectPhotons[i]); localIndirectPhotons.erase(localIndirectPhotons.begin(), localIndirectPhotons.end()); if (indirectPhotons.size() >= integrator->nIndirectPhotonsWanted) indirectDone = true; nDirectPaths += blockSize; for (uint32_t i = 0; i < localDirectPhotons.size(); ++i) directPhotons.push_back(localDirectPhotons[i]); localDirectPhotons.erase(localDirectPhotons.begin(), localDirectPhotons.end()); } // Merge direct, caustic, and radiance photons into shared array if (!causticDone) { integrator->nCausticPaths += blockSize; for (uint32_t i = 0; i < localCausticPhotons.size(); ++i) causticPhotons.push_back(localCausticPhotons[i]); localCausticPhotons.erase(localCausticPhotons.begin(), localCausticPhotons.end()); if (causticPhotons.size() >= integrator->nCausticPhotonsWanted) causticDone = true; } for (uint32_t i = 0; i < localRadiancePhotons.size(); ++i) radiancePhotons.push_back(localRadiancePhotons[i]); localRadiancePhotons.erase(localRadiancePhotons.begin(), localRadiancePhotons.end()); for (uint32_t i = 0; i < localRpReflectances.size(); ++i) rpReflectances.push_back(localRpReflectances[i]); localRpReflectances.erase(localRpReflectances.begin(), localRpReflectances.end()); for (uint32_t i = 0; i < localRpTransmittances.size(); ++i) rpTransmittances.push_back(localRpTransmittances[i]); localRpTransmittances.erase(localRpTransmittances.begin(), localRpTransmittances.end()); } // Exit task if enough photons have been found if (indirectDone && causticDone) break; } }