Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 104 additions & 152 deletions README.md

Large diffs are not rendered by default.

Binary file added Thumbs.db
Binary file not shown.
Binary file added armaNormal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bunny1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chart1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added colorInterp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cowFlat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cowPhong.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added donutFlat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added donutMesh.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added donutPhong.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dragonCloud.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion external/src/objUtil/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void obj::buildVBOs(){
for(int i=0; i<IBOvec.size(); i++){
ibo[i] = IBOvec[i];
}
setColor(glm::vec3(.4,.4,.4));

setColor(glm::vec3(.9f,0.6f,0.3f));
}

void obj::compareMaxMin(float x, float y, float z){
Expand Down
Binary file added renders/Thumbs.db
Binary file not shown.
Binary file added renders/debug normal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 123 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,128 @@ int main(int argc, char** argv){
frame = 0;
seconds = time (NULL);
fpstracker = 0;

// Launch CUDA/GL
if (init(argc, argv)) {
// GLFW main loop
mainLoop();
}

return 0;
}


void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
mouseScrollOffset += yoffset;
}
void mainLoop() {
while(!glfwWindowShouldClose(window)){


while(!glfwWindowShouldClose(window)){

//camera rotation, zoom control using mouse
double * mouseX = new double;
double * mouseY = new double;

if(glfwGetMouseButton(window,GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
{
glfwGetCursorPos(window,mouseX,mouseY);
if(mouseButtonIsDown == false)
{
mouseButtonIsDown = true;
mouseClickedX = *mouseX;
mouseClickedY = *mouseY;
}
mouseDeltaX = *mouseX - mouseClickedX;
mouseDeltaY = *mouseY - mouseClickedY;

}

else
{
if(mouseButtonIsDown == true)
{
rotationX += mouseDeltaX;
rotationY += mouseDeltaY;
mouseButtonIsDown = false;
mouseDeltaX = 0.0f;
mouseDeltaY = 0.0f;
}

}
delete mouseX,mouseY;

//camera movement control using keyboard
if(glfwGetKey(window,GLFW_KEY_W) == GLFW_PRESS)
{
deltaZ -= cameraMovementIncrement;
}
if(glfwGetKey(window,GLFW_KEY_S) == GLFW_PRESS)
{
deltaZ += cameraMovementIncrement;
}
if(glfwGetKey(window,GLFW_KEY_A) == GLFW_PRESS)
{
deltaX -= cameraMovementIncrement;
}
if(glfwGetKey(window,GLFW_KEY_D) == GLFW_PRESS)
{
deltaX += cameraMovementIncrement;
}

if(glfwGetKey(window,GLFW_KEY_F) == GLFW_PRESS)
{
isFkeyDown = true;
}
if(glfwGetKey(window,GLFW_KEY_F) == GLFW_RELEASE)
{
if(isFkeyDown)
{
if(!isFlatShading) isFlatShading = 1;
else isFlatShading = 0;
}
isFkeyDown = false;
}

if(glfwGetKey(window,GLFW_KEY_M) == GLFW_PRESS)
{
isMkeyDown = true;
}
if(glfwGetKey(window,GLFW_KEY_M) == GLFW_RELEASE)
{
if(isMkeyDown)
{
if(!isMeshView) isMeshView = 1;
else isMeshView = 0;
}
isMkeyDown = false;
}


//set up transformations
float fov_rad = FOV_DEG * PI / 180.0f;
float AR = width / height;

//glm::mat4 ModelTransform =utilityCore::buildTransformationMatrix(glm::vec3(0.0f),glm::vec3(0.0f,0.0f,0.0f),glm::vec3(1.0f));
glm::mat4 ModelTransform =utilityCore::buildTransformationMatrix(glm::vec3(0.0f),glm::vec3(-(rotationY + mouseDeltaY),- (rotationX + mouseDeltaX + 10.0f),0.0f),glm::vec3(0.6f));

glm::mat4 cameraAimTransform = utilityCore::buildTransformationMatrix(glm::vec3(0.0f),glm::vec3(0.0f),glm::vec3(1.0f));
//glm::mat4 cameraAimTransform = utilityCore::buildTransformationMatrix(glm::vec3(0.0f),glm::vec3(-(rotationY + mouseDeltaY),- (rotationX + mouseDeltaX + 10.0f),0.0f),glm::vec3(1.0f));
glm::mat4 cameraPosTransform = utilityCore::buildTransformationMatrix(glm::vec3(0.0f + deltaX,-.25f+ deltaZ,(2.0f + MOUSE_SCROLL_SPEED * mouseScrollOffset)),glm::vec3(0.0f),glm::vec3(1.0f));
glm::mat4 ViewTransform = cameraAimTransform *cameraPosTransform;
//glm::mat4 ViewTransform =utilityCore::buildTransformationMatrix(glm::vec3(0.0f + deltaX,-.25f,2.0f + deltaZ + MOUSE_SCROLL_SPEED * mouseScrollOffset),glm::vec3(-(rotationY + mouseDeltaY),- (rotationX + mouseDeltaX),0.0f),glm::vec3(1.0f));

glmViewTransform = ViewTransform;
glmProjectionTransform = glm::perspective((float)45.0f,AR, 1.0f,50.0f);
glmMVtransform = ViewTransform * ModelTransform;

//construct light
Light.position = glm::vec3(7.0f,2.0f, -10.0f);
Light.diffColor = glm::vec3(1.0f);
Light.specColor = glm::vec3(1.0f);
Light.specExp = 20;
Light.ambColor = glm::vec3(0.2f,0.6f,0.3f);
glfwPollEvents();

runCuda();

time_t seconds2 = time (NULL);
Expand All @@ -68,6 +177,7 @@ void mainLoop() {
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
glfwSwapBuffers(window);
}

glfwDestroyWindow(window);
glfwTerminate();
}
Expand All @@ -84,22 +194,23 @@ void runCuda(){
vbo = mesh->getVBO();
vbosize = mesh->getVBOsize();

float newcbo[] = {0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 0.0, 0.0};
cbo = newcbo;
cbosize = 9;
cbo = mesh->getCBO();
cbosize = mesh->getCBOsize();

ibo = mesh->getIBO();
ibosize = mesh->getIBOsize();

nbo = mesh->getNBO();
nbosize = mesh->getNBOsize();

cudaGLMapBufferObject((void**)&dptr, pbo);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, vbo, vbosize, cbo, cbosize, ibo, ibosize);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, vbo, vbosize, cbo, cbosize, ibo, ibosize,nbo,nbosize, glmViewTransform, glmProjectionTransform,glmMVtransform,Light, isFlatShading,isMeshView);
cudaGLUnmapBufferObject(pbo);

vbo = NULL;
cbo = NULL;
ibo = NULL;
nbo = NULL;

frame++;
fpstracker++;
Expand All @@ -119,7 +230,7 @@ bool init(int argc, char* argv[]) {

width = 800;
height = 800;
window = glfwCreateWindow(width, height, "CIS 565 Pathtracer", NULL, NULL);
window = glfwCreateWindow(width, height, "CUDA rasterizer", NULL, NULL);
if (!window){
glfwTerminate();
return false;
Expand All @@ -145,6 +256,8 @@ bool init(int argc, char* argv[]) {
glUseProgram(passthroughProgram);
glActiveTexture(GL_TEXTURE0);

glfwSetScrollCallback(window, scroll_callback);

return true;
}

Expand Down
35 changes: 34 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifndef MAIN_H
#define MAIN_H
#include <stdlib.h>

#include <GL/glew.h>
#include <GLFW/glfw3.h>
Expand All @@ -12,10 +13,10 @@
#include <fstream>
#include <glm/glm.hpp>
#include <glslUtil/glslUtility.hpp>
#include "glm/gtc/matrix_transform.hpp"
#include <iostream>
#include <objUtil/objloader.h>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <time.h>

Expand All @@ -25,6 +26,36 @@

using namespace std;

#define FOV_DEG 30
#define MOUSE_SCROLL_SPEED 0.1f

light Light;

//transformations
glm::mat4 glmViewTransform;
glm::mat4 glmProjectionTransform;
glm::mat4 glmMVtransform;

//mouse control stuff
bool mouseButtonIsDown = false;
float mouseScrollOffset = 0.0f;
double mouseClickedX = 0.0f;
double mouseClickedY = 0.0f;
double rotationX = 0.0f;
double rotationY = 0.0f;
double mouseDeltaX = 0.0f;
double mouseDeltaY = 0.0f;
//toggle view
bool isFkeyDown = false;
int isFlatShading = false;
bool isMkeyDown = false;
int isMeshView = false;

//keyboard control
double deltaX = 0.0f;
double deltaZ = 0.0f;
double cameraMovementIncrement = 0.015f;

//-------------------------------
//------------GL STUFF-----------
//-------------------------------
Expand All @@ -49,6 +80,8 @@ float* cbo;
int cbosize;
int* ibo;
int ibosize;
float* nbo;
int nbosize;

//-------------------------------
//----------CUDA STUFF-----------
Expand Down
Loading