Exemplo n.º 1
0
void runCuda() {
    if (camchanged) {
        iteration = 0;
        Camera &cam = renderState->camera;
        glm::vec3 v = cam.view;
        glm::vec3 u = cam.up;
        glm::vec3 r = glm::cross(v, u);
        glm::mat4 rotmat = glm::rotate(theta, r) * glm::rotate(phi, u);
        cam.view = glm::vec3(rotmat * glm::vec4(v, 0.f));
        cam.up = glm::vec3(rotmat * glm::vec4(u, 0.f));
        cam.position += cammove.x * r + cammove.y * u + cammove.z * v;
        theta = phi = 0;
        cammove = glm::vec3();
        camchanged = false;
    }

    // Map OpenGL buffer object for writing from CUDA on a single GPU
    // No data is moved (Win & Linux). When mapped to CUDA, OpenGL should not use this buffer

    if (iteration == 0) {
        pathtraceFree();
        pathtraceInit(scene);
    }

    if (iteration < renderState->iterations) {
        uchar4 *pbo_dptr = NULL;
        iteration++;
        cudaGLMapBufferObject((void**)&pbo_dptr, pbo);

        // execute the kernel
        if( scene->blur ) {
        	for( int frame = 0; frame<(scene->frames); frame++ ){
        		pathtrace(pbo_dptr, frame, scene->frames, iteration);
        		//printf("frame is : %d", frame);
        	}
        } else {
        	pathtrace(pbo_dptr, 0, 0, iteration);
        }

        // unmap buffer object
        cudaGLUnmapBufferObject(pbo);
    } else {
        saveImage();
        pathtraceFree();
        cudaDeviceReset();
        exit(EXIT_SUCCESS);
    }
}
Exemplo n.º 2
0
void runCuda() {
    if (camchanged) {
        iteration = 0;
        Camera &cam = renderState->camera;
        glm::vec3 v = cam.view;
        glm::vec3 u = cam.up;
        glm::vec3 r = glm::cross(v, u);
        glm::mat4 rotmat = glm::rotate(theta, r) * glm::rotate(phi, u);
        cam.view = glm::vec3(rotmat * glm::vec4(v, 0.f));
        cam.up = glm::vec3(rotmat * glm::vec4(u, 0.f));
        cam.position += cammove.x * r + cammove.y * u + cammove.z * v;

		// Camera to grid center
		float distance = cam.resolution.x / 2 / tan(cam.fov.x / 2);
		cam.toGrid = glm::vec3(cam.view.x*distance, cam.view.y*distance, cam.view.z*distance);
		// Find camera right vector
		float rAngle = -PI / 2;
		float qx = cam.view.x * sin(rAngle / 2);
		float qy = cam.view.y * sin(rAngle / 2);
		float qz = cam.view.z * sin(rAngle / 2);
		float qw = cos(rAngle / 2);

		glm::quat q = glm::quat(qw, qx, qy, qz);
		cam.right = q * cam.up;

        theta = phi = 0;
        cammove = glm::vec3();
        camchanged = false;
    }

    // Map OpenGL buffer object for writing from CUDA on a single GPU
    // No data is moved (Win & Linux). When mapped to CUDA, OpenGL should not use this buffer

    if (iteration == 0) {
        pathtraceFree();
        pathtraceInit(scene);
    }

    if (iteration < renderState->iterations) {
        uchar4 *pbo_dptr = NULL;
        iteration++;
        cudaGLMapBufferObject((void**)&pbo_dptr, pbo);

        // execute the kernel
        int frame = 0;
        pathtrace(pbo_dptr, frame, iteration);

        // unmap buffer object
        cudaGLUnmapBufferObject(pbo);
    } else {
        saveImage();
        pathtraceFree();
        cudaDeviceReset();
        exit(EXIT_SUCCESS);
    }
}
Exemplo n.º 3
0
void Renderer::render(const Camera& camera, float time) {

	// calc cam vars
  glm::vec3 A,B,C;
  {
    // camera ray
    C = glm::normalize(camera.getLookAt()-camera.getPosition());

    // calc A (screen x)
    // calc B (screen y) then scale down relative to aspect
    // fov is for screen x axis
    A = glm::normalize(glm::cross(C,camera.getUp()));
    B = 1.0f/camera.getAspect()*glm::normalize(glm::cross(A,C));

    // scale by FOV
    float tanFOV = tan(glm::radians(camera.getFOV()));
    A *= tanFOV;
    B *= tanFOV;
  }

  // cuda call
  unsigned int* out_data;
	checkCudaErrors(cudaGLMapBufferObject((void**)&out_data, pbo));
  
  if (mode == RAYTRACE) {
    raytrace1(out_data, image_width, image_height, time,
      camera.getPosition(), A, B, C,
      scene_d, sceneSize);
  }
  else if (mode == PATHTRACE) {
    ++filmIters;

    pathtrace(out_data, image_width, image_height, time,
      camera.getPosition(), A, B, C,
      camera.m_lensRadius, camera.m_focalDist,
      scene_d, sceneSize,
      rand_d, rays_d, col_d, idx_d,
      film_d, filmIters);
  }

	checkCudaErrors(cudaGLUnmapBufferObject(pbo));

	// download texture from destination PBO
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
  glActiveTexture(GL_TEXTURE0 + RENDER_TEXTURE);
	glBindTexture(GL_TEXTURE_2D, result_texture);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_width, image_height, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
  glActiveTexture(GL_TEXTURE0 + UNUSED_TEXTURE);

	SDK_CHECK_ERROR_GL();

  
  fullScreenQuad.display();
}
Exemplo n.º 4
0
fluidControlWidget::fluidControlWidget(QWidget *parent)
	: QWidget(parent)
{

	mySimulation = NULL;

	animationTimer = new QTimer(this);
	connect( animationTimer, SIGNAL(timeout()), this, SLOT(doAnimation()) ); 

	//setUp Gui

	QPushButton * but_resetFlux = new QPushButton("Reset Flux!");
	connect(but_resetFlux, SIGNAL(released()), this, SLOT(resetToCollectedFlux()));
	//QPushButton * butt_defForce = new QPushButton("Define Force!");
	//connect(butt_defForce, SIGNAL(released()), this, SLOT(setForceFlux()));
	//QPushButton * butt = new QPushButton("Flux 2 Vorticity 2 Flux!");
	//connect(butt, SIGNAL(released()), this, SLOT(flux2vort2flux()));

	QPushButton * butt_simStep = new QPushButton("Do 1 Timestep");
	connect(butt_simStep, SIGNAL(released()), this, SLOT(singleSimulationStep()));
	QPushButton * butt_startSim = new QPushButton("Start/Stop Simulation");
	connect(butt_startSim , SIGNAL(released()), this, SLOT(startSim()));


	QPushButton * but_borderconstr = new QPushButton("Define Border Constraints");//"Debug (harmonic flow)!");
	connect(but_borderconstr , SIGNAL(released()), this, SLOT(debugSome()));

	QPushButton * debug2 = new QPushButton("Debug (pathtracing/vorts)!");
	connect(debug2 , SIGNAL(released()), this, SLOT(debugSome2()));

	stepSliderLabel = new QLabel("Timestep Size ()");
	viscosityLabel = new QLabel("Viscosity [0,10]");
	forceAgeLabel = new QLabel("ForceAge (nr Iteratons): ");
	forceStrengthLabel = new QLabel("Force Strength (): ");


	stepSlider = new QSlider(Qt::Horizontal, this);
	stepSlider->setMinimum(0);
	stepSlider->setMaximum(1000);
	stepSlider->setTickPosition(QSlider::TicksAbove);
	stepSlider->setValue(0);
	connect(stepSlider,SIGNAL(sliderReleased()), this, SLOT(updateTimeStep()));


	viscositySlider = new QSlider(Qt::Horizontal, this);
	viscositySlider->setMinimum(0);
	viscositySlider->setMaximum(200);
	viscositySlider->setTickPosition(QSlider::TicksAbove);
	viscositySlider->setValue(0);
	connect(viscositySlider,SIGNAL(sliderReleased()), this, SLOT(updateViscosity()));


	forceAgeSlider = new QSlider(Qt::Horizontal, this);
	forceAgeSlider->setMinimum(0);
	forceAgeSlider->setMaximum(100);
	forceAgeSlider->setTickPosition(QSlider::TicksAbove);
	forceAgeSlider->setValue(5);
	connect(forceAgeSlider,SIGNAL(sliderReleased()), this, SLOT(forceAgeChanged()));
	forceAgeChanged();

	forceStrengthSlider = new QSlider(Qt::Horizontal, this);
	forceStrengthSlider->setMinimum(0);
	forceStrengthSlider->setMaximum(480);
	forceStrengthSlider->setTickPosition(QSlider::TicksAbove);
	forceStrengthSlider->setValue(80);
	connect(forceStrengthSlider,SIGNAL(sliderReleased()), this, SLOT(forceStrengthChanged()));
	forceStrengthChanged();


//	viscosityAndTimestep = new QLabel("");
//	updateViscTimeLabel();
	animationLabel = new QLabel("");

	vectorInput = new QLineEdit();
	vectorInput->setText("");
	//vectorInput->setInputMask("#09.00 #09.00 #09.00");
	connect(vectorInput,SIGNAL(textChanged( const QString& )), this, SLOT(borderDirInput(const QString & )));

	//////////////////////////////////////////////////////////////////////////
	//display settings
	//////////////////////////////////////////////////////////////////////////
	QCheckBox * showStreamLines;
	QCheckBox * doInterpolation;
	QCheckBox * showVortNotSpeed;
	QCheckBox * texLine;
	showStreamLines = new QCheckBox();
	showStreamLines->setChecked(false);
	connect(showStreamLines, SIGNAL(stateChanged(int)), this, SLOT(showStreamLn(int)));

	doInterpolation = new QCheckBox();
	doInterpolation->setChecked(true);
	connect(doInterpolation, SIGNAL(stateChanged(int)), this, SLOT(doInterpl(int)));

	showVortNotSpeed = new QCheckBox();
	showVortNotSpeed->setChecked(true);
	connect(showVortNotSpeed, SIGNAL(stateChanged(int)), this, SLOT(showVorticity(int)));

	texLine = new QCheckBox();
	texLine->setChecked(true);
	connect(texLine, SIGNAL(stateChanged(int)), this, SLOT(showTexLines(int)));

	QLabel * streamLinesInterpolationLable = new QLabel("Lines/Interpol/Linelength/Vort/Tex/Color");
	QSpinBox * lineLength = new QSpinBox(this);
	lineLength->setMinimum(1);
	lineLength->setMaximum(50);
	lineLength->setSingleStep(1);
	connect(lineLength, SIGNAL(valueChanged(int)), this, SLOT(streamLineLengthChanged(int)));

	QSpinBox * colorScale = new QSpinBox(this);
	colorScale->setMinimum(1);
	colorScale->setMaximum(100);
	colorScale->setSingleStep(1);
	colorScale->setValue(50);
	connect(colorScale, SIGNAL(valueChanged(int)), this, SLOT(colorScaleChanged(int)));



	QVBoxLayout * layout = new QVBoxLayout();

	layout->addWidget(animationLabel);
	layout->addWidget(vectorInput);
	layout->addWidget(but_borderconstr);
	//layout->addWidget(butt);
	//layout->addWidget(butt_defForce);
	layout->addWidget(butt_startSim);
	layout->addWidget(but_resetFlux);
	layout->addWidget(butt_simStep);

	layout->addWidget(stepSliderLabel);
	layout->addWidget(stepSlider);
	layout->addWidget(viscosityLabel);
	layout->addWidget(viscositySlider);
	layout->addWidget(forceAgeLabel);
	layout->addWidget(forceAgeSlider);
	layout->addWidget(forceStrengthLabel);
	layout->addWidget(forceStrengthSlider);
//	layout->addWidget(viscosityAndTimestep);



	layout->addWidget(streamLinesInterpolationLable);

	QHBoxLayout * hlayout = new QHBoxLayout();
	hlayout->addWidget(showStreamLines);
	hlayout->addWidget(doInterpolation);
	hlayout->addWidget(lineLength);
	hlayout->addWidget(showVortNotSpeed);
	hlayout->addWidget(texLine);
	hlayout->addWidget(colorScale);
	layout->addLayout(hlayout);

	layout->addWidget(debug2);


	QPushButton * dbg1 = new QPushButton("PathTr");
	connect(dbg1 , SIGNAL(released()), this, SLOT(pathtrace()));
	QPushButton * dbg2= new QPushButton("VortPart");
	connect(dbg2 , SIGNAL(released()), this, SLOT(showVorticityPart()));
	QHBoxLayout * hlayout2 = new QHBoxLayout();
	hlayout2->addWidget(dbg1);
	hlayout2->addWidget(dbg2);
	layout->addLayout(hlayout2);

	this->setLayout(layout);

	Model::getModel()->attach(this);


	this->selectedBorder = 0;
	for(int i = 0; i < Model::getModel()->getMeshInfo()->getBorder().size(); i++){
		borderConstrDirs.push_back(tuple3f());
	}

}