Color Raytracer::CalnDiffusion( Collider* collider , int* hash, int rc, Color weight) { Primitive* pri = collider->GetPrimitive(); Color color = pri->GetMaterial()->color; if (pri->GetMaterial()->texture != NULL) { if (pri->getName() == 0) color = color * pri->GetTexture(collider->C); else color = color * pri->GetTexture(Vector3(collider->u, collider->v, 0)); } Color ret = color * scene->GetBackgroundColor() * pri->GetMaterial()->diff; for ( Light* light = scene->GetLightHead() ; light != NULL ; light = light->GetNext() ) ret += color * light->GetIrradiance( collider , scene->GetPrimitiveHead() , scene->GetCamera()->GetShadeQuality() , hash ); if (camera->GetAlgorithm() == "PM") ret += color * photonmap->GetIrradiance( collider , camera->GetSampleDist() , camera->GetSamplePhotons() ); if (camera->GetAlgorithm() == "PPM" || camera->GetAlgorithm() == "SPPM") { Hitpoint hitpoint; hitpoint.pos = collider->C; hitpoint.dir = collider->I; hitpoint.N = collider->N; hitpoint.primitive = collider->GetPrimitive(); hitpoint.rc = rc; hitpoint.weight = weight * color; hitpoint.R2 = photonmap->GetRadius2(collider, camera->GetSampleDist(), camera->GetSamplePhotons()); hitpointMap->Store(hitpoint); } return ret; }
bool Engine::render(void) { std::ofstream debugfile; debugfile.open("E:\\code\\debug2.txt", std::ios_base::app); debugfile << "Starting currLine = " << currLine << std::endl; // render scene Vector3 o(0.0, 0.0, -5.0); // initialize timer unsigned int msecs = get_msec(); // reset last found primitive pointer Primitive *lastprim = nullptr; // render remaining lines for (unsigned int y = currLine; y < (height - 20); y++) { SX = WX1; // render pixels for current line for (unsigned int x = 0; x < width; x++) { // fire primary ray Color acc(0.0, 0.0, 0.0); Vector3 dir = Vector3(SX, SY, 0) - o; dir.normalize(); Ray r(o, dir); double dist; unsigned int prev = get_msec(); Primitive *prim = raytrace(r, acc, 1, 1.0, dist); unsigned int post = get_msec(); if (post - prev != 0) { if (prim) debugfile << prim->getName() << " @ "; debugfile << x << ", " << y << ": "; debugfile << post - prev << std::endl; } int red = (int)(acc.R() * 256); int green = (int)(acc.G() * 256); int blue = (int)(acc.B() * 256); if (red > 255) red = 255; if (green > 255) green = 255; if (blue > 255) blue = 255; dest[ppos++] = RGBA_to_Pixel(red, green, blue); SX += DX; } SY += DY; // see if we've been working to long already // TODO if ((get_msec() - msecs) > 100) { // return control to windows so the screen gets updated currLine = y + 1; debugfile << "exiting currLine = " << currLine << std::endl; debugfile.close(); return false; } } // all done debugfile.close(); return true; }