RayBuffer RayTracer::traceRays() { // #pragma omp parallel for for (uint y = 0; y < HEIGHT; y++) { // #pragma omp parallel for for (uint x = 0; x < WIDTH; x++) { Ray r = computeRay(x, y); Intersection in = scene->calculateRayIntersection(r); SColor c = shadeIntersection(in, depth); PX_Color color; color.R = (uint8_t) (255 * c.R()); color.G = (uint8_t) (255 * c.G()); color.B = (uint8_t) (255 * c.B()); buffer.setPixel(x, y, color); } } return buffer; }
// Computes weighted rays vector<RayWeights> Pinhole::computeRaysAndWeights(int i, int j) { vector<RayWeights> rayWeights; // TODO: Violation of DRY? (Think Lense.cpp) /* if (numPixelSamples == 1) { Ray ray } */ double samplesInOneDimension = sqrt(numPixelSamples); double sampleSpacing = 1.0 / samplesInOneDimension; double uJitter = 0.5; double vJitter = 0.5; double distance = computeDistanceToImagePlane(); if (jitteringEnabled) { uJitter = (double)rand() / (double)RAND_MAX; vJitter = (double)rand() / (double)RAND_MAX; } for (int iSample = 0; iSample <= samplesInOneDimension /* < (samplesInOneDimension - 1)*/; iSample++) { for (int jSample = 0; jSample <= samplesInOneDimension /* < (samplesInOneDimension - 1)*/; jSample++) { double u = i + (iSample + uJitter) * sampleSpacing; double v = j + (jSample + vJitter) * sampleSpacing; double weight = (numPixelSamples == 1) ? 3.0 : (double) numPixelSamples; Ray ray = computeRay(u, v, distance); RayWeights rayWeight = {ray, 1.0 / weight }; // set the bound to constant, either .1 or .2 rayWeights.push_back(rayWeight); // maybe allow customization as parameter ("brightness", how bright do you want } // this to be } return rayWeights; }