Float Camera::GenerateRayDifferential(const CameraSample &sample, RayDifferential *rd) const { Float wt = GenerateRay(sample, rd); // Find camera ray after shifting one pixel in the $x$ direction CameraSample sshift = sample; sshift.pFilm.x++; Ray rx; Float wtx = GenerateRay(sshift, &rx); if (wtx == 0) return 0; rd->rxOrigin = rx.o; rd->rxDirection = rx.d; // Find camera ray after shifting one pixel in the $y$ direction sshift.pFilm.x--; sshift.pFilm.y++; Ray ry; Float wty = GenerateRay(sshift, &ry); if (wty == 0) return 0; rd->ryOrigin = ry.o; rd->ryDirection = ry.d; rd->hasDifferentials = true; return wt; }
//ray tracing void CPURayTracer::RayTrace() { //reset the timer m_Timer.Reset(); //start the timer m_Timer.Start(); //bind the buffer BindBuffer(); for( int j = m_iImageHeight - 1 ; j > -1 ; j-- ) { for( int i = 0 ; i < m_iImageWidth; i++ ) { //current index int currentIndex = j * m_iImageWidth + i; //current ray _float4 dir , ori; //generate a ray for current pixel GenerateRay( i , j , &ori , &dir ); //copy the image m_pImageBackBuffer[ currentIndex ] = Trace( ori , dir ); //copy the image m_pImageBuffer[ currentIndex ] = RGB_FLOAT4( m_pImageBackBuffer[ currentIndex ] ); //update current pixel number m_iCurrentPixelNum++; if( m_bForceStop ) break; } if( m_bForceStop ) break; } //clear the noise ClearNoise( m_pImageBackBuffer ); //end the timer m_Timer.Stop(); m_ElapsedTime = (int)m_Timer.GetElapsedTime(); }
void FattalCPU::ComputePropagation( int idPropagation, bool fristSweep, int writeUId ) { //FIXME: Warning: Handle only cube volume // Pour chaque elements de la LPM #pragma omp parallel for for (short x = 0; x < m_media->Size.x; x++) { for (short y = 0; y < m_media->Size.x; y++) { for (unsigned short idRay = 0; idRay < NbSamples*NbSamples; idRay++) { // Generate Ray Ray r; GenerateRay(r,x,y,idRay,Factor,NbSamples, idPropagation); // Initialize Ray value r.Position += r.Direction*0.001f; SPECTRUM rayValue = SPECTRUM_INIT(0.f); if(fristSweep) { // FIXME: Add ligthing method /*if(idPropagation == 1) rayValue = 40.f/81;*/ rayValue = m_light->getRadiance(idPropagation,x,y,idRay,NbSamples); } // Prepare other data float maxDirectionCoord = std::max(abs(r.Direction.x),std::max(abs(r.Direction.y),abs(r.Direction.z))); int nbElements = m_media->Size.x*m_media->Size.y*m_media->Size.y; //////////////////////////////// // Loop (Ray martching ) //////////////////////////////// TraversingVolumeAlgorithm rayTraversing(r); glm::ivec3 oldCurrendVoxID; do { while(isInGrid(rayTraversing.voxID, m_media->Size.x)) { //std::cout << rayTraversing.voxID.x << "x" << rayTraversing.voxID.y << "x" << rayTraversing.voxID.z << std::endl; oldCurrendVoxID = rayTraversing.voxID; rayTraversing.Traverse(r); // Je sais que c'est dans la grille // Car tout les points initialisee sont dedant int indiceVox = (oldCurrendVoxID.z*m_media->Size.x + oldCurrendVoxID.y)*m_media->Size.x + oldCurrendVoxID.x; float density = m_media->Density[indiceVox]; if(density > 0.000001) { // Calcul de la valeur SPECTRUM scatteringTerm = rayValue*(1 - exp(-1*m_media->ScatteringCoeff*density*rayTraversing.DeltaLength/maxDirectionCoord)); // float extinctionCoeff = (m_media->ScatteringCoeff+m_media->AbsorptionCoeff)*density; float extinctionFactor = exp(-1*extinctionCoeff*rayTraversing.DeltaLength/maxDirectionCoord); SPECTRUM UValue = m_Us[(writeUId+1)%2][idPropagation*nbElements + indiceVox]; rayValue = rayValue*extinctionFactor+(UValue*(1 - extinctionFactor)/extinctionCoeff); SPECTRUM value = scatteringTerm; // TODO: nbRays // TODO: Cell dim value *= 1.f / (NbSamples*NbSamples); #pragma omp critical { // Update I m_I[indiceVox] += value; for (int k = 0; k < 6; k++ ) { m_Us[writeUId][k*nbElements + indiceVox] += value / (SPECTRUM)6.f; } } } } rayTraversing.wrapCurrentVoxID(m_media->Size.x); rayValue = SPECTRUM_INIT(0.f); } while(isInGrid(rayTraversing.voxID, m_media->Size.x)); } // End For rayID } // End for Y } // End for X }
Ray PinholeLens::GenerateRay(const Vec2f& uv, const Vec2f& auv, float time) { return GenerateRay(uv,time); }