diff --git a/README.md b/README.md index ae0896a..60c07cd 100644 --- a/README.md +++ b/README.md @@ -5,48 +5,11 @@ Fall 2014 ------------------------------------------------------------------------------- Due Monday 10/27/2014 @ 12 PM ------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- -NOTE: -------------------------------------------------------------------------------- -This project requires an NVIDIA graphics card with CUDA capability! Any card with CUDA compute capability 1.1 or higher will work fine for this project. For a full list of CUDA capable cards and their compute capability, please consult: http://developer.nvidia.com/cuda/cuda-gpus. If you do not have an NVIDIA graphics card in the machine you are working on, feel free to use any machine in the SIG Lab or in Moore100 labs. All machines in the SIG Lab and Moore100 are equipped with CUDA capable NVIDIA graphics cards. If this too proves to be a problem, please contact Patrick or Karl as soon as possible. - -------------------------------------------------------------------------------- -INTRODUCTION: -------------------------------------------------------------------------------- -In this project, you will implement a simplified CUDA based implementation of a standard rasterized graphics pipeline, similar to the OpenGL pipeline. In this project, you will implement vertex shading, primitive assembly, perspective transformation, rasterization, fragment shading, and write the resulting fragments to a framebuffer. More information about the rasterized graphics pipeline can be found in the class slides and in your notes from CIS560. - -The basecode provided includes an OBJ loader and much of the mundane I/O and bookkeeping code. The basecode also includes some functions that you may find useful, described below. The core rasterization pipeline is left for you to implement. - -You MAY NOT use ANY raycasting/raytracing AT ALL in this project, EXCEPT in the fragment shader step. One of the purposes of this project is to see how a rasterization pipeline can generate graphics WITHOUT the need for raycasting! Raycasting may only be used in the fragment shader effect for interesting shading results, but is absolutely not allowed in any other stages of the pipeline. - -Also, you MAY NOT use OpenGL ANYWHERE in this project, aside from the given OpenGL code for drawing Pixel Buffer Objects to the screen. Use of OpenGL for any pipeline stage instead of your own custom implementation will result in an incomplete project. - -Finally, note that while this basecode is meant to serve as a strong starting point for a CUDA rasterizer, you are not required to use this basecode if you wish, and you may also change any part of the basecode specification as you please, so long as the final rendered result is correct. - -------------------------------------------------------------------------------- -CONTENTS: -------------------------------------------------------------------------------- -The Project4 root directory contains the following subdirectories: - -* src/ contains the source code for the project. Both the Windows Visual Studio solution and the OSX makefile reference this folder for all source; the base source code compiles on OSX and Windows without modification. -* objs/ contains example obj test files: cow.obj, cube.obj, tri.obj. -* renders/ contains an example render of the given example cow.obj file with a z-depth fragment shader. -* windows/ contains a Windows Visual Studio 2010 project and all dependencies needed for building and running on Windows 7. - -The Windows and OSX versions of the project build and run exactly the same way as in Project0, Project1, and Project2. - +![alt tag](https://github.com/jianqiaol/Project4-Rasterizer/blob/master/one_more_light.png) ------------------------------------------------------------------------------- -REQUIREMENTS: +Project Overview: ------------------------------------------------------------------------------- -In this project, you are given code for: - -* A library for loading/reading standard Alias/Wavefront .obj format mesh files and converting them to OpenGL style VBOs/IBOs -* A suggested order of kernels with which to implement the graphics pipeline -* Working code for CUDA-GL interop - -You will need to implement the following stages of the graphics pipeline and features: - +In this project, I implemented a standard rasterized graphics pipeline. Following stages of the graphics pipeline are implemented as basic features: * Vertex Shading * Primitive Assembly with support for triangle VBOs/IBOs * Perspective Transformation @@ -56,129 +19,38 @@ You will need to implement the following stages of the graphics pipeline and fea * Fragment to framebuffer writing * A simple lighting/shading scheme, such as Lambert or Blinn-Phong, implemented in the fragment shader -You are also required to implement at least 3 of the following features: - -* Additional pipeline stages. Each one of these stages can count as 1 feature: - * Geometry shader - * Transformation feedback - * Back-face culling - * Scissor test - * Stencil test - * Blending - -IMPORTANT: For each of these stages implemented, you must also add a section to your README stating what the expected performance impact of that pipeline stage is, and real performance comparisons between your rasterizer with that stage and without. - +Following features are implemented as additional features: +* Back-face culling * Correct color interpolation between points on a primitive -* Texture mapping WITH texture filtering and perspective correct texture coordinates -* Support for additional primitices. Each one of these can count as HALF of a feature. - * Lines - * Line strips - * Triangle fans - * Triangle strips - * Points -* Anti-aliasing -* Order-independent translucency using a k-buffer * MOUSE BASED interactive camera support. Interactive camera support based only on the keyboard is not acceptable for this feature. ------------------------------------------------------------------------------- -BASE CODE TOUR: -------------------------------------------------------------------------------- -You will be working primarily in two files: rasterizeKernel.cu, and rasterizerTools.h. Within these files, areas that you need to complete are marked with a TODO comment. Areas that are useful to and serve as hints for optional features are marked with TODO (Optional). Functions that are useful for reference are marked with the comment LOOK. - -* rasterizeKernels.cu contains the core rasterization pipeline. - * A suggested sequence of kernels exists in this file, but you may choose to alter the order of this sequence or merge entire kernels if you see fit. For example, if you decide that doing has benefits, you can choose to merge the vertex shader and primitive assembly kernels, or merge the perspective transform into another kernel. There is not necessarily a right sequence of kernels (although there are wrong sequences, such as placing fragment shading before vertex shading), and you may choose any sequence you want. Please document in your README what sequence you choose and why. - * The provided kernels have had their input parameters removed beyond basic inputs such as the framebuffer. You will have to decide what inputs should go into each stage of the pipeline, and what outputs there should be. - -* rasterizeTools.h contains various useful tools, including a number of barycentric coordinate related functions that you may find useful in implementing scanline based rasterization... - * A few pre-made structs are included for you to use, such as fragment and triangle. A simple rasterizer can be implemented with these structs as is. However, as with any part of the basecode, you may choose to modify, add to, use as-is, or outright ignore them as you see fit. - * If you do choose to add to the fragment struct, be sure to include in your README a rationale for why. - -You will also want to familiarize yourself with: - -* main.cpp, which contains code that transfers VBOs/CBOs/IBOs to the rasterization pipeline. Interactive camera work will also have to be implemented in this file if you choose that feature. -* utilities.h, which serves as a kitchen-sink of useful functions - -------------------------------------------------------------------------------- -SOME RESOURCES: +Progress: ------------------------------------------------------------------------------- -The following resources may be useful for this project: +I started this project by first implement the standard vertex shader. I find this blog really helpful for explaining the whole vertex operation and primitive assembly operation, especially for the projection transformation: http://www.songho.ca/opengl/gl_transform.html -* High-Performance Software Rasterization on GPUs - * Paper (HPG 2011): http://www.tml.tkk.fi/~samuli/publications/laine2011hpg_paper.pdf - * Code: http://code.google.com/p/cudaraster/ Note that looking over this code for reference with regard to the paper is fine, but we most likely will not grant any requests to actually incorporate any of this code into your project. - * Slides: http://bps11.idav.ucdavis.edu/talks/08-gpuSoftwareRasterLaineAndPantaleoni-BPS2011.pdf -* The Direct3D 10 System (SIGGRAPH 2006) - for those interested in doing geometry shaders and transform feedback. - * http://133.11.9.3/~takeo/course/2006/media/papers/Direct3D10_siggraph2006.pdf -* Multi-Fragment Effects on the GPU using the k-Buffer - for those who want to do a k-buffer - * http://www.inf.ufrgs.br/~comba/papers/2007/kbuffer_preprint.pdf -* FreePipe: A Programmable, Parallel Rendering Architecture for Efficient Multi-Fragment Effects (I3D 2010) - * https://sites.google.com/site/hmcen0921/cudarasterizer -* Writing A Software Rasterizer In Javascript: - * Part 1: http://simonstechblog.blogspot.com/2012/04/software-rasterizer-part-1.html - * Part 2: http://simonstechblog.blogspot.com/2012/04/software-rasterizer-part-2.html - -------------------------------------------------------------------------------- -NOTES ON GLM: -------------------------------------------------------------------------------- -This project uses GLM, the GL Math library, for linear algebra. You need to know two important points on how GLM is used in this project: +After the vertex shader and primitiveAssemblyKernel are done, here is the rasterized cow without light: +![alt tag](https://github.com/jianqiaol/Project4-Rasterizer/blob/master/without_light.png) -* In this project, indices in GLM vectors (such as vec3, vec4), are accessed via swizzling. So, instead of v[0], v.x is used, and instead of v[1], v.y is used, and so on and so forth. -* GLM Matrix operations work fine on NVIDIA Fermi cards and later, but pre-Fermi cards do not play nice with GLM matrices. As such, in this project, GLM matrices are replaced with a custom matrix struct, called a cudaMat4, found in cudaMat4.h. A custom function for multiplying glm::vec4s and cudaMat4s is provided as multiplyMV() in intersections.h. +By setting the color of the fragment as its normal, I get this debug picture: +![alt tag](https://github.com/jianqiaol/Project4-Rasterizer/blob/master/debug_normal.png) -------------------------------------------------------------------------------- -README -------------------------------------------------------------------------------- -All students must replace or augment the contents of this Readme.md in a clear -manner with the following: +After I implemented the fragment shader with to add light effect. The diffuse and specular color are calculated based on Blinn-Phong mode:http://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model. The cow now looks like this: +![alt tag](https://github.com/jianqiaol/Project4-Rasterizer/blob/master/with_light.png) -* A brief description of the project and the specific features you implemented. -* At least one screenshot of your project running. -* A 30 second or longer video of your project running. To create the video you - can use http://www.microsoft.com/expression/products/Encoder4_Overview.aspx -* A performance evaluation (described in detail below). +By using the Barycentric interpolation, I get this correct color interpolation between points on a primitive by setting the vertices' color to be red, green and blue in each triangle: +![alt tag](https://github.com/jianqiaol/Project4-Rasterizer/blob/master/color_interpolation.png) -------------------------------------------------------------------------------- -PERFORMANCE EVALUATION -------------------------------------------------------------------------------- -The performance evaluation is where you will investigate how to make your CUDA -programs more efficient using the skills you've learned in class. You must have -performed at least one experiment on your code to investigate the positive or -negative effects on performance. +I then added the mouse based interactive camera. The model is rotating slowly by default.You can change the view angle by holding left button. You can change the distance between the camera and the object by holding right button. A demo can be found here:https://www.youtube.com/watch?v=6bU3c5rq9xY&list=UUUFqyNxl-EHZ0yESB2gGJ-w&spfreload=10 -We encourage you to get creative with your tweaks. Consider places in your code -that could be considered bottlenecks and try to improve them. +At last I implemented the backface culling by calculate the dot product between the eye direction and the face normal. I also used thrust::remove_if as I did in the last project. In theory the performance should improve a lot, since about half primitives should be invisible. However for the cow the FPS doesn't change too much. Before backface culling the FPS is about 15, and after using backface culling the FPS is still around 16. -Each student should provide no more than a one page summary of their -optimizations along with tables and or graphs to visually explain any -performance differences. +Future work: +I would like to try Anti-aliasing and also smoothing the normals for adjacent primitives. +Also try displacement mapping. -------------------------------------------------------------------------------- -THIRD PARTY CODE POLICY -------------------------------------------------------------------------------- -* Use of any third-party code must be approved by asking on Piazza. If it is approved, all students are welcome to use it. Generally, we approve use of third-party code that is not a core part of the project. For example, for the ray tracer, we would approve using a third-party library for loading models, but would not approve copying and pasting a CUDA function for doing refraction. -* Third-party code must be credited in README.md. -* Using third-party code without its approval, including using another student's code, is an academic integrity violation, and will result in you receiving an F for the semester. ------------------------------------------------------------------------------- -SELF-GRADING +ACKNOWLEDGEMENT ------------------------------------------------------------------------------- -* On the submission date, email your grade, on a scale of 0 to 100, to Liam, harmoli+cis565@seas.upenn.edu, with a one paragraph explanation. Be concise and realistic. Recall that we reserve 30 points as a sanity check to adjust your grade. Your actual grade will be (0.7 * your grade) + (0.3 * our grade). We hope to only use this in extreme cases when your grade does not realistically reflect your work - it is either too high or too low. In most cases, we plan to give you the exact grade you suggest. -* Projects are not weighted evenly, e.g., Project 0 doesn't count as much as the path tracer. We will determine the weighting at the end of the semester based on the size of each project. - ---- -SUBMISSION ---- -As with the previous project, you should fork this project and work inside of -your fork. Upon completion, commit your finished project back to your fork, and -make a pull request to the master repository. You should include a README.md -file in the root directory detailing the following - -* A brief description of the project and specific features you implemented -* At least one screenshot of your project running. -* A link to a video of your raytracer running. -* Instructions for building and running your project if they differ from the - base code. -* A performance writeup as detailed above. -* A list of all third-party code used. -* This Readme file edited as described above in the README section. - +Thanks a lot to Patrick and Harmony for the preparation of this project. Thank you! diff --git a/Thumbs.db b/Thumbs.db new file mode 100755 index 0000000..4f6118d Binary files /dev/null and b/Thumbs.db differ diff --git a/color_interpolation.png b/color_interpolation.png new file mode 100755 index 0000000..3e5b175 Binary files /dev/null and b/color_interpolation.png differ diff --git a/debug_normal.png b/debug_normal.png new file mode 100755 index 0000000..3004822 Binary files /dev/null and b/debug_normal.png differ diff --git a/one_more_light.png b/one_more_light.png new file mode 100755 index 0000000..504a56e Binary files /dev/null and b/one_more_light.png differ diff --git a/src/main.cpp b/src/main.cpp index 13d8e67..3aef4ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,36 @@ int main(int argc, char** argv){ void mainLoop() { while(!glfwWindowShouldClose(window)){ glfwPollEvents(); + alpha=alpha+1; + //camera data + cam.view=glm::vec3(0.0f,0.0f,0.0f); + cam.up=glm::vec3(0.0,1.0,0.0); + cam.position.x=D*cos(beta*PI/180.0f)*cos(alpha*PI/180.0f); + cam.position.y=D*sin(beta*PI/180.0f)-0.5f; + cam.position.z=D*cos(beta*PI/180.0f)*sin(alpha*PI/180.0f); + glm::vec3 temp_lateral=glm::normalize(glm::cross(cam.view-cam.position,cam.up)); + cam.up=glm::normalize(glm::cross(temp_lateral,cam.view-cam.position)); + + cam.FOV=80.0f; + z_near=0.1f; + z_far=100.0f; + //Transform points from model to clip coordinates + model=glm::mat4(1.0f); + view=glm::lookAt(cam.position,cam.view,cam.up); + projection=glm::perspective(cam.FOV,(float)width/(float)height,z_near,z_far); + + //test + /*glm::vec4 r=glm::vec4(0.0,2.0,1.0,1.0); + r=projection*view*r; + cout<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,model,view,projection,M,n_modelview, z_near,z_far,cam.position); cudaGLUnmapBufferObject(pbo); vbo = NULL; @@ -109,6 +143,66 @@ void runCuda(){ //------------------------------- //----------SETUP STUFF---------- //------------------------------- +void MouseCallback(GLFWwindow* window,int button,int action,int mods) +{ + if(action==GLFW_PRESS) + { + glfwGetCursorPos(window,&x_pos,&y_pos); + //cout< #include #include - - +#include "../external/include/glm/gtc/matrix_transform.hpp" #include "rasterizeKernels.h" #include "utilities.h" @@ -49,6 +48,34 @@ float* cbo; int cbosize; int* ibo; int ibosize; +float* nbo; +int nbosize; + +struct camera{ + glm::vec3 position; + glm::vec3 view; + glm::vec3 up; + float FOV; +}; + +camera cam; +float z_near; +float z_far; +glm::mat4 model; +glm::mat4 view; +glm::mat4 projection; +glm::mat4 n_modelview; +glm::mat4 M; +glm::vec3 light; +float alpha=90; +float beta=50; +float D=1.5; +bool left_button=false; +bool right_button=false; +bool inside_window=false; +double x_pos; +double y_pos; + //------------------------------- //----------CUDA STUFF----------- diff --git a/src/rasterizeKernels.cu b/src/rasterizeKernels.cu index 10b0000..f4ebfc9 100644 --- a/src/rasterizeKernels.cu +++ b/src/rasterizeKernels.cu @@ -5,15 +5,23 @@ #include #include #include +#include +#include #include "rasterizeKernels.h" #include "rasterizeTools.h" - +using namespace std; glm::vec3* framebuffer; fragment* depthbuffer; float* device_vbo; +float* device_old_vbo; float* device_cbo; int* device_ibo; +float* device_nbo; triangle* primitives; +cudaMat4* MVP; +cudaMat4* device_MVP; +cudaMat4* NMV; +cudaMat4* device_NMV; void checkCUDAError(const char *msg) { cudaError_t err = cudaGetLastError(); @@ -129,33 +137,124 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3* } //TODO: Implement a vertex shader -__global__ void vertexShadeKernel(float* vbo, int vbosize){ +__global__ void vertexShadeKernel(float* vbo, int vbosize,float* nbo,cudaMat4* M,cudaMat4* NMV,glm::vec2 resolution,float z_near,float z_far){ int index = (blockIdx.x * blockDim.x) + threadIdx.x; if(index0); } } -//TODO: Implement a rasterization method, such as scanline. -__global__ void rasterizationKernel(triangle* primitives, int primitivesCount, fragment* depthbuffer, glm::vec2 resolution){ +struct backface_culling +{ + __host__ __device__ + bool operator()(const triangle tri) + { + return tri.visiable; + } +}; + +//TODO: Implement a rasterization method, such as scanline.:http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html +__global__ void rasterizationKernel(triangle* primitives, int primitivesCount, fragment* depthbuffer, glm::vec2 resolution,float z_near,float z_far){ int index = (blockIdx.x * blockDim.x) + threadIdx.x; if(index=0 &&i=0&&jcurrent_frag.position.z &¤t_frag.position.z>z_near &¤t_frag.position.z>>(resolution, depthbuffer,frag); //------------------------------ //memory stuff //------------------------------ + MVP = new cudaMat4; + *MVP = utilityCore::glmMat4ToCudaMat4(M); + device_MVP=NULL; + cudaMalloc((void**)&device_MVP,sizeof(cudaMat4)); + cudaMemcpy(device_MVP,MVP,sizeof(cudaMat4),cudaMemcpyHostToDevice); + NMV = new cudaMat4; + *NMV = utilityCore::glmMat4ToCudaMat4(n_MV); + device_NMV=NULL; + cudaMalloc((void**)&device_NMV,sizeof(cudaMat4)); + cudaMemcpy(device_NMV,NMV,sizeof(cudaMat4),cudaMemcpyHostToDevice); + + primitives = NULL; cudaMalloc((void**)&primitives, (ibosize/3)*sizeof(triangle)); @@ -210,36 +322,63 @@ void cudaRasterizeCore(uchar4* PBOpos, glm::vec2 resolution, float frame, float* cudaMalloc((void**)&device_vbo, vbosize*sizeof(float)); cudaMemcpy( device_vbo, vbo, vbosize*sizeof(float), cudaMemcpyHostToDevice); + device_old_vbo = NULL; + cudaMalloc((void**)&device_old_vbo, vbosize*sizeof(float)); + cudaMemcpy( device_old_vbo, vbo, vbosize*sizeof(float), cudaMemcpyHostToDevice); + device_cbo = NULL; cudaMalloc((void**)&device_cbo, cbosize*sizeof(float)); cudaMemcpy( device_cbo, cbo, cbosize*sizeof(float), cudaMemcpyHostToDevice); + device_nbo = NULL; + cudaMalloc((void**)&device_nbo, nbosize*sizeof(float)); + cudaMemcpy( device_nbo, nbo, nbosize*sizeof(float), cudaMemcpyHostToDevice); + tileSize = 32; int primitiveBlocks = ceil(((float)vbosize/3)/((float)tileSize)); //------------------------------ //vertex shader //------------------------------ - vertexShadeKernel<<>>(device_vbo, vbosize); + vertexShadeKernel<<>>(device_vbo, vbosize,device_nbo,device_MVP,device_NMV,resolution,z_near,z_far); cudaDeviceSynchronize(); //------------------------------ //primitive assembly //------------------------------ primitiveBlocks = ceil(((float)ibosize/3)/((float)tileSize)); - primitiveAssemblyKernel<<>>(device_vbo, vbosize, device_cbo, cbosize, device_ibo, ibosize, primitives); + primitiveAssemblyKernel<<>>(device_vbo, vbosize, device_cbo, cbosize, device_ibo, ibosize, device_nbo,primitives,device_old_vbo,eye); cudaDeviceSynchronize(); + + //backface culling + int Num=ibosize/3; + thrust::device_ptr start(primitives); + thrust::device_ptr end=start+Num; + end=thrust::remove_if(start,end,backface_culling()); + Num=(int)(end-start); + //------------------------------ //rasterization //------------------------------ - rasterizationKernel<<>>(primitives, ibosize/3, depthbuffer, resolution); + rasterizationKernel<<>>(primitives, Num, depthbuffer, resolution,z_near,z_far); cudaDeviceSynchronize(); //------------------------------ //fragment shader //------------------------------ - fragmentShadeKernel<<>>(depthbuffer, resolution); + //glm::vec3 light=glm::vec3(0.0f,2.0f,1.0f); + glm::vec3 light=glm::vec3(0.0f,2.0f,-1.0f); + /* glm::vec4 light_p=multiplyMV(*MVP,glm::vec4(light,1.0f)); + light.x=light_p.x/light_p.w; + light.y=light_p.y/light_p.w; + light.z=light_p.z/light_p.w; + light.x=(light.x+1.0f)/2.0f*resolution.x; + light.y=(light.y+1.0f)/2.0f*resolution.y; + light.z=z_near+(light.z+1.0f)/2.0f*(z_far-z_near); + cout << light.x<<" "<>>(depthbuffer, resolution,light,eye,model,view,projection); cudaDeviceSynchronize(); //------------------------------ @@ -258,8 +397,12 @@ void cudaRasterizeCore(uchar4* PBOpos, glm::vec2 resolution, float frame, float* void kernelCleanup(){ cudaFree( primitives ); cudaFree( device_vbo ); + cudaFree(device_old_vbo); cudaFree( device_cbo ); cudaFree( device_ibo ); + cudaFree(device_nbo); + cudaFree(device_MVP); + cudaFree(device_NMV); cudaFree( framebuffer ); cudaFree( depthbuffer ); } diff --git a/src/rasterizeKernels.h b/src/rasterizeKernels.h index 784be17..cf0d508 100644 --- a/src/rasterizeKernels.h +++ b/src/rasterizeKernels.h @@ -10,7 +10,8 @@ #include #include "glm/glm.hpp" + void kernelCleanup(); -void cudaRasterizeCore(uchar4* pos, glm::vec2 resolution, float frame, float* vbo, int vbosize, float* cbo, int cbosize, int* ibo, int ibosize); +void cudaRasterizeCore(uchar4* pos, glm::vec2 resolution, float frame, float* vbo, int vbosize, float* cbo, int cbosize, int* ibo, int ibosize,float* nbo,int nbosize,glm::mat4 model,glm::mat4 view,glm::mat4 projection,glm::mat4 M,glm::mat4 n_MV,float z_near,float z_far,glm::vec3 eye); #endif //RASTERIZEKERNEL_H diff --git a/src/rasterizeTools.h b/src/rasterizeTools.h index e9b5dcc..bac21f5 100644 --- a/src/rasterizeTools.h +++ b/src/rasterizeTools.h @@ -16,20 +16,31 @@ struct triangle { glm::vec3 c0; glm::vec3 c1; glm::vec3 c2; + glm::vec3 n0; + glm::vec3 n1; + glm::vec3 n2; + glm::vec3 old_p0; + glm::vec3 old_p1; + glm::vec3 old_p2; + bool visiable; }; struct fragment{ glm::vec3 color; glm::vec3 normal; glm::vec3 position; + glm::vec3 originial_position; }; + + //Multiplies a cudaMat4 matrix and a vec4 -__host__ __device__ glm::vec3 multiplyMV(cudaMat4 m, glm::vec4 v){ - glm::vec3 r(1,1,1); +__host__ __device__ glm::vec4 multiplyMV(cudaMat4 m, glm::vec4 v){ + glm::vec4 r(1,1,1,1); r.x = (m.x.x*v.x)+(m.x.y*v.y)+(m.x.z*v.z)+(m.x.w*v.w); r.y = (m.y.x*v.x)+(m.y.y*v.y)+(m.y.z*v.z)+(m.y.w*v.w); r.z = (m.z.x*v.x)+(m.z.y*v.y)+(m.z.z*v.z)+(m.z.w*v.w); + r.w = (m.w.x*v.x)+(m.w.y*v.y)+(m.w.z*v.z)+(m.w.w*v.w); return r; } diff --git a/windows/PROJ4_Rasterizer/PROJ4_Rasterizer/PROJ4_Rasterizer.vcxproj b/windows/PROJ4_Rasterizer/PROJ4_Rasterizer/PROJ4_Rasterizer.vcxproj index f640485..ce57096 100644 --- a/windows/PROJ4_Rasterizer/PROJ4_Rasterizer/PROJ4_Rasterizer.vcxproj +++ b/windows/PROJ4_Rasterizer/PROJ4_Rasterizer/PROJ4_Rasterizer.vcxproj @@ -1,92 +1,95 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {6F351C80-6834-4F35-9CB3-C70F56161CBC} - PROJ4_Rasterizer - - - - Application - true - MultiByte - - - Application - false - true - MultiByte - - - - - - - - - - - - - - - - Level3 - Disabled - $(SolutionDir)..\..\external\include;%(AdditionalIncludeDirectories) - - - true - $(SolutionDir)..\..\external\lib\win\GLFW;$(SolutionDir)..\..\external\lib\win\GL;%(AdditionalLibraryDirectories) - cudart.lib;glew32s.lib;glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - $(SolutionDir)..\..\external\include;%(AdditionalIncludeDirectories) - - - true - true - true - $(SolutionDir)..\..\external\lib\win\GLFW;$(SolutionDir)..\..\external\lib\win\GL;%(AdditionalLibraryDirectories) - cudart.lib;glew32s.lib;glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - Document - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {6F351C80-6834-4F35-9CB3-C70F56161CBC} + PROJ4_Rasterizer + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + + Level3 + Disabled + $(SolutionDir)..\..\external\include;%(AdditionalIncludeDirectories) + + + true + $(SolutionDir)..\..\external\lib\win\GLFW;$(SolutionDir)..\..\external\lib\win\GL;%(AdditionalLibraryDirectories) + cudart.lib;glew32s.lib;glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + $(SolutionDir)..\..\external\include;%(AdditionalIncludeDirectories) + + + true + true + true + $(SolutionDir)..\..\external\lib\win\GLFW;$(SolutionDir)..\..\external\lib\win\GL;%(AdditionalLibraryDirectories) + cudart.lib;glew32s.lib;glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + $(ProjectDir)%(Filename)%(Extension).obj + + + + + + + + + + + + + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/with_light.png b/with_light.png new file mode 100755 index 0000000..244f2de Binary files /dev/null and b/with_light.png differ diff --git a/without_light.png b/without_light.png new file mode 100755 index 0000000..800664c Binary files /dev/null and b/without_light.png differ