Beispiel #1
0
void GlutIdle()
{
    static int lastRenderedPixels = 0;
    if ( mode == MODE_RENDERING ) {
        int nrp = renderImage.GetNumRenderedPixels();
        if ( lastRenderedPixels != nrp ) {
            lastRenderedPixels = nrp;
            if ( renderImage.IsRenderDone() ) {
                mode = MODE_RENDER_DONE;
                int endTime = (int) time(NULL);
                int t = endTime - startTime;
                int h = t / 3600;
                int m = (t % 3600) / 60;
                int s = t % 60;
                printf("\nRender time is %d:%02d:%02d.\n",h,m,s);

                renderImage.ComputeZBufferImage();
                
                std::string fileloc ("/Users/varunk/Desktop/RayTracerProj1/RayTracePrj11/RayTracePrj11/");
                
                renderImage.SaveZImage((fileloc + "zbuffer.ppm").c_str());
                
                renderImage.SaveImage((fileloc + "renderimage.ppm").c_str());
                
                renderImage.ComputeSampleCountImage();
                
                renderImage.SaveSampleCountImage((fileloc + "samplecountimage.ppm").c_str());
        
            }
            glutPostRedisplay();
        }
         if ( viewMode == VIEWMODE_IRRADCOMP ) glutPostRedisplay();
    }
}
Beispiel #2
0
void BeginRender()
{
	Color24 *temp;
	temp = renderImage.GetPixels();
	float *zBuffer = renderImage.GetZBuffer();
	Color materialColor;
	Color24 newColor;
	for (int i = 0; i < camera.imgWidth; i++)
	{
		for (int j = 0; j < camera.imgHeight; j++)
		{
			Ray currentRay = ComputeCameraRay(i, j);
			HitInfo hInfo;
			hInfo.Init();
			bool value = TraceRay(currentRay, hInfo, &rootNode);
			if (value) {
				hInfo.node->FromNodeCoords(hInfo);
				const Material *m = hInfo.node->GetMaterial();
				materialColor = m->Shade(currentRay, hInfo, lights);
				temp[camera.imgWidth*j + i].r = (materialColor.r)*255;
				temp[camera.imgWidth*j + i].g = (materialColor.g)*255;
				temp[camera.imgWidth*j + i].b = (materialColor.b)*255;
			}
			else {
				temp[camera.imgWidth*j + i].r = 0;
				temp[camera.imgWidth*j + i].g = 0;
				temp[camera.imgWidth*j + i].b = 0;
			}
			zBuffer[camera.imgWidth*j + i] = hInfo.z;
		}
	}
	renderImage.ComputeZBufferImage();
	renderImage.SaveImage("Output");
}
Beispiel #3
0
void BeginRender()
{

    cout<<"\nBeginning Render...";
    
    float alpha = camera.fov;
    float l = 1.0;
    float h = l * tan(alpha/2.0 *(M_PI/180));
    float aspectRatio = (float)camera.imgWidth/camera.imgHeight;
    float s = aspectRatio * h;
    float dx = (2 * s)/camera.imgWidth;
    float dy = -(2 * h)/camera.imgHeight;
    float dxx = dx/2,dyy=dy/2;
    Point3 K(-s,h,-l);
    K.x += dxx;
    K.y += dyy;
    for(int i = 0; i< camera.imgHeight; i++){
        
        for(int j = 0; j<camera.imgWidth; j++){
            
            K.x += dx;
            Matrix3 RotMat;
            
            Point3 dvec = camera.dir - camera.pos;
            Point3 svec = camera.up.Cross(dvec);
            dvec.Normalize();
            svec.Normalize();
            camera.up.Normalize();
            RotMat.Set(svec,camera.up, dvec);
            Ray r(camera.pos, K);
            
            r.dir=r.dir*RotMat;
            
            r.dir.Normalize();
            
            HitInfo hInfo;
            hInfo.Init();
            if(rootNode.GetNumChild()>0){
//                for(int k=0; k < rootNode.GetNumChild(); ++k){
//                    RayTrace(rootNode.GetChild(k),r,i * camera.imgWidth + j);
//                }
                if(RayTrace_2(r, hInfo))
                {
                    renderImage.PutPixel(i *camera.imgWidth+j, white, hInfo.z);
                }
                else renderImage.PutPixel(i *camera.imgWidth+j, black, BIGFLOAT);
            }
            
            
        }
        K.x = -s;
        K.x += dxx;
        K.y += dy;
    }
    cout<<"Render Complete"<<endl;
    renderImage.ComputeZBufferImage();
    renderImage.SaveZImage("/Users/varunk/Desktop/RayTracerProj1/RayTracerProj1/zbuffer.ppm");
    renderImage.SaveImage("/Users/varunk/Desktop/RayTracerProj1/RayTracerProj1/renderimage.ppm");
    
}
Beispiel #4
0
void Renderer::startRendering(size_t i_threadCount)
{
	threadCount = i_threadCount;
	mThreadHandle = ThreadHandle(threadCount);
	imageWidth = renderImage.GetWidth();
	imageHeight = renderImage.GetHeight();
	noOfRowsToRenderPerThread = imageHeight / threadCount;
	renderingImage = renderImage.GetPixels();
	zBufferImage = renderImage.GetZBuffer();
	sampleCountImage = renderImage.GetSampleCount();
	operationCountImage = renderImage.GetOperationCountImage();

	myEngine::Timing::Clock *clock = myEngine::Timing::Clock::createAndStart();

	/*for (int i = 0; i < renderImage.GetHeight(); ++i)
	{
		for (int j = 0; j < renderImage.GetWidth(); ++j)
		{
			calculatePixelColor(rootNode,lights,j, i);
		}
	}*/

	

	int *threadVal = new int[threadCount];
	for (size_t i = 0; i < threadCount; i++)
	{
		threadVal[i] = i;
		std::cout << "\nPassing Value to thread" << threadVal[i];
		mThreadHandle.thread[i] = CreateThread(nullptr, 0, static_cast<LPTHREAD_START_ROUTINE>(renderPixel), &threadVal[i], CREATE_SUSPENDED, nullptr);
	}

	for (size_t i = 0; i < threadCount;i++)
	{
		ResumeThread(mThreadHandle.thread[i]);
	}
	
	std::cout << "Wait Val"<<std::endl << WaitForMultipleObjects(threadCount, mThreadHandle.thread, TRUE, INFINITE) << std::endl;;
	std::cout << "Wait finished";
	
	if (WaitForMultipleObjects(threadCount + 1, mThreadHandle.thread, TRUE, INFINITE))
	{
		mThreadHandle.destroyThread();
	}

	TCHAR* mutexName = __T("WritingMutex");
	HANDLE mutexHandle = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutexName);
	CloseHandle(mutexHandle);


	renderImage.SaveImage("RayCasted.ppm");
	renderImage.ComputeZBufferImage();
	renderImage.SaveZImage("RayCastWithZ.ppm");
	renderImage.ComputeSampleCountImage();
	renderImage.SaveSampleCountImage("SampleCountImage.ppm");
	clock->updateDeltaTime();
	double time = clock->getdeltaTime();
	printf("Time to render ray casting  %f", clock->getdeltaTime());
}
Beispiel #5
0
void GlutDisplay()
{
    switch ( viewMode ) {
        case VIEWMODE_OPENGL:
            if ( dofImage ) {
                if ( dofDrawCount < MAX_DOF_DRAW ) {
                    DrawScene();
                    glReadPixels( 0, 0, camera.imgWidth, camera.imgHeight, GL_RGB, GL_UNSIGNED_BYTE, dofBuffer );
                    for ( int i=0; i<camera.imgWidth*camera.imgHeight; i++ ) {
                        dofImage[i] = (dofImage[i]*dofDrawCount + dofBuffer[i].ToColor())/(dofDrawCount+1);
                    }
                    dofDrawCount++;
                }
                glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
                glDrawPixels( camera.imgWidth, camera.imgHeight, GL_RGB, GL_FLOAT, dofImage );
                if ( dofDrawCount < MAX_DOF_DRAW ) {
                    DrawProgressBar(float(dofDrawCount)/MAX_DOF_DRAW);
                    glutPostRedisplay();
                }
            } else {
                DrawScene();
            }
            break;
        case VIEWMODE_IMAGE:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, renderImage.GetPixels() );
            DrawRenderProgressBar();
            break;
        case VIEWMODE_Z:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( ! renderImage.GetZBufferImage() ) renderImage.ComputeZBufferImage();
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetZBufferImage() );
            break;
        case VIEWMODE_SAMPLECOUNT:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( ! renderImage.GetSampleCountImage() ) renderImage.ComputeSampleCountImage();
            glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetSampleCountImage() );
            break;
        case VIEWMODE_IRRADCOMP:
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
            if ( renderImage.GetIrradianceComputationImage() ) {
                glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetIrradianceComputationImage() );
            }
            break;
    }
    
    glutSwapBuffers();
}
Beispiel #6
0
void GlutDisplay()
{
	switch ( viewMode ) {
	case VIEWMODE_OPENGL:
		DrawScene();
		break;
	case VIEWMODE_IMAGE:
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
		glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, renderImage.GetPixels() );
		DrawRenderProgressBar();
		break;
	case VIEWMODE_Z:
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
		if ( ! renderImage.GetZBufferImage() ) renderImage.ComputeZBufferImage();
		glDrawPixels( renderImage.GetWidth(), renderImage.GetHeight(), GL_LUMINANCE, GL_UNSIGNED_BYTE, renderImage.GetZBufferImage() );
		break;
	}

	glutSwapBuffers();
}