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
197 changes: 55 additions & 142 deletions README.md

Large diffs are not rendered by default.

Binary file added result/PROJ4_Rasterizer.wmv
Binary file not shown.
Binary file added result/antialias.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 result/antialiasing2.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 result/backFace.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 result/chart.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 result/color interpolate.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 result/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 result/lockCube.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 result/normal.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 result/orgCube.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 result/shading.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 result/table.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 result/withut light.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 69 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,42 @@ 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};
float newcbo[] = {1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0};
cbo = newcbo;
cbosize = 9;

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

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

//Rx += 1.0 * PI / 180.0;
Ry += 1.0 * PI / 180.0;
//Ry = PI/4.0;

float viewLength = glm::length(center - eye);
eye.x = center.x + viewLength * cos(Rx) * cos(Ry);
eye.y = center.y + viewLength * sin(Rx);
eye.z = center.z + viewLength * cos(Rx) * sin(Ry);

glm::mat4 modelView = glm::lookAt(eye, center, up);
glm::mat4 projection = glm::perspective(fovy, width / (float)height, 0.1f, 100.0f);
glm::mat4 mvp = viewPort * projection * modelView;
modelViewProj.x = mvp[0]; modelViewProj.y = mvp[1]; modelViewProj.z = mvp[2]; modelViewProj.w = mvp[3];

glm::vec4 lightP = projection * modelView * glm::vec4(lightPos, 1.0f);
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, modelViewProj,/* viewPort,*/ glm::vec3(lightP.x, lightP.y,lightP.z), lightRGB,
true, center-eye, false);
cudaGLUnmapBufferObject(pbo);

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

frame++;
fpstracker++;
Expand Down Expand Up @@ -138,12 +158,16 @@ bool init(int argc, char* argv[]) {
initTextures();
initCuda();
initPBO();

GLuint passthroughProgram;
passthroughProgram = initShader();

glUseProgram(passthroughProgram);
glActiveTexture(GL_TEXTURE0);

//interactive
//glutMouseFunc(onMouseButton);
//glutMotionFunc(onMouseDrag);

return true;
}
Expand Down Expand Up @@ -281,4 +305,44 @@ 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 onMouseButton(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON) {
if (state == GLUT_DOWN) {
lastMousePos.x = x;
lastMousePos.y = y;

mouseMode = TransMode;
}
}
else if (button == GLUT_RIGHT_BUTTON) {
if (state == GLUT_DOWN) {
lastMousePos.x = x;
lastMousePos.y = y;

mouseMode = RotateMode;
}
}
}

void onMouseDrag(int x, int y)
{
float dx = (x - lastMousePos.x) * translateStep;
float dy = (y - lastMousePos.y) * translateStep;

if (mouseMode == TransMode) {
eye.x += dx;
eye.y += dy;
center.x += dx;
center.y += dy;

lastMousePos.x = x;
lastMousePos.y = y;
}
else if (mouseMode == RotateMode) {

}
}
44 changes: 44 additions & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#define MAIN_H

#include <GL/glew.h>
#include <GL/glut.h>
#include <GLFW/glfw3.h>

#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#include <fstream>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glslUtil/glslUtility.hpp>
#include <iostream>
#include <objUtil/objloader.h>
Expand Down Expand Up @@ -49,13 +51,40 @@ float* cbo;
int cbosize;
int* ibo;
int ibosize;
float* nbo;
int nbosize;

//-------------------------------
//----------CUDA STUFF-----------
//-------------------------------

int width = 800; int height = 800;

//-------------------------------
//----------Camera STUFF-----------
//-------------------------------

glm::vec3 view(0, 0, -1);
glm::vec3 up(0, 1, 0);
glm::vec3 eye(0,0,1.5f);
glm::vec3 center(0, 0.3, 0);
float fovy = 60;
float Rx = 0;
float Ry = 0;

cudaMat4 modelViewProj;
cudaMat4 inverseMVP;
glm::mat4 viewPort(-width/2.0, 0, 0, 0, 0, -height/2.0, 0, 0, 0, 0, 0.5, 0, width/2.0, height/2.0, 0.5, 1.0);
//glm::mat4 viewPort(-1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, width/2.0, height/2.0, 1, 1);
glm::vec3 lightPos(10, 10, 10);
glm::vec3 lightRGB(1, 1, 1);

//interaction
int mouseMode = 0;
enum MOUSEMODE{None, TransMode, RotateMode};
glm::vec2 lastMousePos(0, 0);
float translateStep = 1.0f/256.0f;

//-------------------------------
//-------------MAIN--------------
//-------------------------------
Expand Down Expand Up @@ -85,6 +114,7 @@ void initTextures();
void initVAO();
GLuint initShader();


//-------------------------------
//---------CLEANUP STUFF---------
//-------------------------------
Expand All @@ -100,4 +130,18 @@ void mainLoop();
void errorCallback(int error, const char *description);
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);

//------------------------------
//------- Helper ---------------
//------------------------------

//void computeProjection(float fovy, float aspect, float zNear, float zFar);
//void computeViewMat(glm::vec3 );

//------------------------------
//------- Interactive ----------
//------------------------------
void onMouseButton(int button, int state, int x, int y);

void onMouseDrag(int x, int y);

#endif
Loading