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
234 changes: 52 additions & 182 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions external/src/objUtil/obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ obj::obj(){
defaultColor = glm::vec3(0,0,0);
boundingbox = new float[32];
maxminSet = false;
xmax=0; xmin=0; ymax=0; ymin=0; zmax=0; zmin=0;
xmax=0; xmin=0; ymax=0; ymin=0; zmax=0; zmin=0;

}

Expand Down Expand Up @@ -52,7 +52,7 @@ void obj::buildVBOs(){
for(int i=2; i<face.size(); i++){
glm::vec4 p1 = points[face[i-1]];
glm::vec4 p2 = points[face[i]];
VBOvec.push_back(p0[0]) ; VBOvec.push_back(p0[1]); VBOvec.push_back(p0[2]); //VBOvec.push_back(1.0f);
VBOvec.push_back(p0[0]); VBOvec.push_back(p0[1]); VBOvec.push_back(p0[2]); //VBOvec.push_back(1.0f);
VBOvec.push_back(p1[0]); VBOvec.push_back(p1[1]); VBOvec.push_back(p1[2]); //VBOvec.push_back(1.0f);
VBOvec.push_back(p2[0]); VBOvec.push_back(p2[1]); VBOvec.push_back(p2[2]); //VBOvec.push_back(1.0f);

Expand Down
2 changes: 1 addition & 1 deletion objs/tri.obj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
v 0 0 0
v 0.1 0 0
v 0 0.1 0
v 0.1 0.1 0

vn 0 0 1

Expand Down
Binary file added renders/Thumbs.db
Binary file not shown.
Binary file added renders/cow_diffuse_good_2.png
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 renders/cow_phong.png
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 renders/cow_phong_diffuse.png
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 renders/cow_phong_diffuse2.png
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 renders/cow_phong_diffuse_fixed.png
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 renders/cow_phong_diffuse_good.png
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 renders/cow_phong_pretty.png
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 renders/cow_rasterize.png
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 renders/cow_video.wmv
Binary file not shown.
Binary file added renders/diffuse_cube.png
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 renders/raster-triangle.png
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 renders/tesselation_impact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 87 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania

#include "main.h"
#include "glm/gtc/matrix_transform.hpp"

//-------------------------------
//-------------MAIN--------------
//-------------------------------

int main(int argc, char** argv){


/*
bool loadedScene = false;
for(int i=1; i<argc; i++){
string header; string data;
Expand All @@ -23,12 +26,44 @@ int main(int argc, char** argv){
loadedScene = true;
}
}
*/

// Initialize the model
bool loadedScene = false;
string data = std::string("C:\\\\Users\\Dave\\Documents\\Github\\Project4-Rasterizer\\objs\\cow.obj");
mesh = new obj();
objLoader* loader = new objLoader(data, mesh);
mesh->buildVBOs();
delete loader;
loadedScene = true;

if(!loadedScene){
cout << "Usage: mesh=[obj file]" << endl;
return 0;
}

// Initialize the camera
camera_distance = 3.0f;
camera_phi = PI/2.0f;
camera_theta = 3.0f*PI/2.0f;

// Initialize the MVP matrix
glm::mat4 model = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f)) * glm::scale(glm::mat4(), glm::vec3(1.0f));
glm::vec3 eye(camera_distance*sin(camera_phi)*cos(camera_theta), camera_distance*cos(camera_phi), camera_distance*sin(camera_phi)*sin(camera_theta));
glm::vec3 origin(0.0f, 0.0f, 0.0f);
glm::vec3 up(0.0f, 1.0f, 0.0f);
glm::mat4 view = glm::lookAt(eye, origin, up);
glm::mat4 projection = glm::perspective(45.0f, (float)(width / height), 0.1f, 100.0f);
mvp = projection * view * model;

// Initialize the light source (undirected)
light.origin = glm::vec3(-15.0f, -15.0f, -15.0f);
light.color = glm::vec3(1.0f, 1.0f, 1.0f);
glm::vec4 light_temp = mvp*glm::vec4(light.origin, 1.0f);
light.origin.x = light_temp.x/light_temp.w;
light.origin.y = light_temp.y/light_temp.w;
light.origin.z = light_temp.z/light_temp.w;

frame = 0;
seconds = time (NULL);
fpstracker = 0;
Expand Down Expand Up @@ -93,13 +128,26 @@ void runCuda(){
ibo = mesh->getIBO();
ibosize = mesh->getIBOsize();

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

// Update the MVP matrix
glm::mat4 model = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, 0.0f)) * glm::scale(glm::mat4(), glm::vec3(1.0f));
glm::vec3 eye(camera_distance*sin(camera_phi)*cos(camera_theta), camera_distance*cos(camera_phi), camera_distance*sin(camera_phi)*sin(camera_theta));
glm::vec3 origin(0.0f, 0.0f, 0.0f);
glm::vec3 up(0.0f, 1.0f, 0.0f);
glm::mat4 view = glm::lookAt(eye, origin, up);
glm::mat4 projection = glm::perspective(45.0f, (float)(width / height), 0.1f, 100.0f);
mvp = projection * view * model;

cudaGLMapBufferObject((void**)&dptr, pbo);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, vbo, vbosize, cbo, cbosize, ibo, ibosize);
cudaRasterizeCore(dptr, glm::vec2(width, height), frame, light, vbo, vbosize, cbo, cbosize, ibo, ibosize, nbo, nbosize, mvp);
cudaGLUnmapBufferObject(pbo);

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

frame++;
fpstracker++;
Expand All @@ -126,6 +174,9 @@ bool init(int argc, char* argv[]) {
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, keyCallback);
glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)mouseButtonCallback);
glfwSetCursorPosCallback(window, (GLFWcursorposfun)mousePositionCallback);
glfwSetScrollCallback(window, (GLFWscrollfun)mouseScrollCallback);

// Set up GL context
glewExperimental = GL_TRUE;
Expand Down Expand Up @@ -281,4 +332,39 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS){
glfwSetWindowShouldClose(window, GL_TRUE);
}
}

void mouseButtonCallback(GLFWwindow* window, int button, int action) {

if (button == GLFW_MOUSE_BUTTON_LEFT) {
mouse_pressed = (action == GLFW_PRESS) ? true : false;
if (!mouse_pressed) {
x_last = -1;
y_last = -1;
}
}

}

void mousePositionCallback(GLFWwindow* window, double x, double y) {

if (mouse_pressed) {
if (x_last == -1) {
x_last = x;
y_last = y;
return;
}
camera_theta -= (x-x_last)*0.0005;
camera_phi += (y - y_last)*0.0005;
if (camera_phi <= 0.0005f) {
camera_phi = 0.0005f;
} else if (camera_phi >= PI-0.0005f) {
camera_phi = PI-0.0005f;
}
}

}

void mouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset) {
camera_distance -= yoffset*0.1f;
}
22 changes: 21 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


#include "rasterizeKernels.h"
#include "sceneStructs.h"
#include "utilities.h"

using namespace std;
Expand All @@ -40,7 +41,13 @@ GLuint displayImage;
uchar4 *dptr;

GLFWwindow *window;
bool mouse_pressed = false;
double x_last = -1;
double y_last = -1;

//--------------------------------
//-----------MODEL STUFF----------
//--------------------------------
obj* mesh;

float* vbo;
Expand All @@ -49,6 +56,17 @@ float* cbo;
int cbosize;
int* ibo;
int ibosize;
float* nbo;
int nbosize;

//-------------------------------
//----------CAMERA STUFF---------
//-------------------------------
glm::mat4 mvp;
ray light;
float camera_distance;
float camera_phi;
float camera_theta;

//-------------------------------
//----------CUDA STUFF-----------
Expand Down Expand Up @@ -99,5 +117,7 @@ void deleteTexture(GLuint* tex);
void mainLoop();
void errorCallback(int error, const char *description);
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);

void mouseButtonCallback(GLFWwindow* window, int button, int action);
void mousePositionCallback(GLFWwindow* window, double x, double y);
void mouseScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
#endif
Loading