Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW2 submission #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Binary file added PROJ1_WIN/565Raytracer.suo
Binary file not shown.
21 changes: 21 additions & 0 deletions PROJ1_WIN/565Raytracer/Release/565Raytracer.Build.CppClean.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\565RAYTRACER.EXE.INTERMEDIATE.MANIFEST
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\cl.command.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\CL.read.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\CL.write.1.tlog
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\GLSLUTILITY.OBJ
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\IMAGE.OBJ
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\link.command.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\link.read.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\link.write.1.tlog
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\MAIN.OBJ
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\mt.command.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\mt.read.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\mt.write.1.tlog
H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Release\raytraceKernel.cu.cache
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\SCENE.OBJ
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\STB_IMAGE.OBJ
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\STB_IMAGE_WRITE.OBJ
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\UTILITIES.OBJ
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\VC100.PDB
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\RELEASE\565RAYTRACER.EXE
H:\CIS565 GPU\GITHUB\PROJECT2-PATHTRACER\PROJ1_WIN\RELEASE\565RAYTRACER.PDB
15 changes: 15 additions & 0 deletions PROJ1_WIN/565Raytracer/Release/565Raytracer.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Build started 10/12/2012 11:27:58 PM.
1>Project "H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\565Raytracer.vcxproj" on node 2 (clean target(s)).
1>_PrepareForClean:
Deleting file "Release\565Raytracer.lastbuildstate".
CudaClean:
cmd.exe /C "C:\Users\ntndeyx\AppData\Local\Temp\f4793ac191f940d7af98e53079fd1efa.cmd"
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -ccbin "S:\VS2010\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/common/inc" -I"../shared/glew/includes" -I"../shared/freeglut/includes" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" --keep-dir "Release" -maxrregcount=0 --machine 32 --compile -Xcompiler "/EHsc /nologo /Od /Zi /MD " -o "H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Win32/Release/raytraceKernel.cu.obj" "H:\CIS565 GPU\GitHub\Project2-Pathtracer\src\raytraceKernel.cu" -clean

H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -ccbin "S:\VS2010\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/common/inc" -I"../shared/glew/includes" -I"../shared/freeglut/includes" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include" --keep-dir "Release" -maxrregcount=0 --machine 32 --compile -Xcompiler "/EHsc /nologo /Od /Zi /MD " -o "H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\Win32/Release/raytraceKernel.cu.obj" "H:\CIS565 GPU\GitHub\Project2-Pathtracer\src\raytraceKernel.cu" -clean
Deleting file "Release\raytraceKernel.cu.deps".
1>Done Building Project "H:\CIS565 GPU\GitHub\Project2-Pathtracer\PROJ1_WIN\565Raytracer\565Raytracer.vcxproj" (clean target(s)).

Build succeeded.

Time Elapsed 00:00:02.59
Binary file added PROJ1_WIN/565Raytracer/vc100.pdb
Binary file not shown.
70 changes: 10 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,21 @@ Fall 2012
-------------------------------------------------------------------------------
Due Friday, 10/12/2012
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
NOTE:
-------------------------------------------------------------------------------
This project requires an NVIDIA graphics card with CUDA capability! Any card after the Geforce 8xxx series will work. 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:
Implemented Features:
-------------------------------------------------------------------------------
In this project, you will extend your raytracer from Project 1 into a full CUDA based global illumination pathtracer.

For this project, you may either choose to continue working off of your codebase from Project 1, or you may choose to use the included basecode in this repository. The basecode for Project 2 is the same as the basecode for Project 1, but with some missing components you will need filled in, such as the intersection testing and camera raycasting methods.

How you choose to extend your raytracer into a pathtracer is a fairly open-ended problem; the supplied basecode is meant to serve as one possible set of guidelines for doing so, but you may choose any approach you want in your actual implementation, including completely scrapping the provided basecode in favor of your own from-scratch solution.
* Full global illumination (including soft shadows, color bleeding, etc.) by pathtracing rays through the scene.
* Properly accumulating emittance and colors to generate a final image
* Supersampled antialiasing
* Parallelization by ray instead of by pixel via string compaction (see the Physically-based shading and pathtracing lecture slides from 09/24 if you don't know what this refers to)
* Perfect specular reflection

* Depth of field
* Refraction( still working on it)
-------------------------------------------------------------------------------
CONTENTS:
BLOG
-------------------------------------------------------------------------------
The Project2 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.
* scenes/ contains an example scene description file.
* renders/ contains two example renders: the raytraced render from Project 1 (GI_no.bmp), and the same scene rendered with global illumination (GI_yes.bmp).
* PROJ1_WIN/ contains a Windows Visual Studio 2010 project and all dependencies needed for building and running on Windows 7.
* PROJ1_OSX/ contains a OSX makefile, run script, and all dependencies needed for building and running on Mac OSX 10.8.

The Windows and OSX versions of the project build and run exactly the same way as in Project0 and Project1.
http://cghuyue.blogspot.com/

-------------------------------------------------------------------------------
REQUIREMENTS:
Expand Down Expand Up @@ -71,45 +59,7 @@ Alternatively, implementing just one of the following features can satisfy the "

As yet another alternative, if you have a feature or features you really want to implement that are not on this list, let us know, and we'll probably say yes!

-------------------------------------------------------------------------------
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:

* 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.

-------------------------------------------------------------------------------
BLOG
-------------------------------------------------------------------------------
As mentioned in class, all students should have student blogs detailing progress on projects. If you already have a blog, you can use it; otherwise, please create a blog using www.blogger.com or any other tool, such as www.wordpress.org. Blog posts on your project are due on the SAME DAY as the project, and should include:

* A brief description of the project and the specific features you implemented.
* A link to your github repo if the code is open source.
* At least one screenshot of your project running.
* A 30 second or longer video of your project running. To create the video use http://www.microsoft.com/expression/products/Encoder4_Overview.aspx

-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------
* On the submission date, email your grade, on a scale of 0 to 100, to Karl, [email protected], 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, and at least one screenshot of the final rendered output of your pathtracer
* Instructions for building and running your project if they differ from the base code
* A link to your blog post detailing the project
* A list of all third-party code used
Binary file added renders/huyue_reflection (1).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 renders/huyue_screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions scenes/sampleScene.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ MATERIAL 3 //red glossy
RGB .63 .06 .04
SPECEX 0
SPECRGB 1 1 1
REFL 0
REFL 1
REFR 0
REFRIOR 2
SCATTER 0
Expand All @@ -50,8 +50,8 @@ MATERIAL 4 //white glossy
RGB 1 1 1
SPECEX 0
SPECRGB 1 1 1
REFL 0
REFR 0
REFL 1
REFR 1
REFRIOR 2
SCATTER 0
ABSCOEFF 0 0 0
Expand All @@ -74,7 +74,7 @@ MATERIAL 6 //green glossy
RGB .15 .48 .09
SPECEX 0
SPECRGB 1 1 1
REFL 0
REFL 1
REFR 0
REFRIOR 2.6
SCATTER 0
Expand Down
43 changes: 43 additions & 0 deletions src/glm/CMakeLists (2).txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
set(NAME glm)

file(GLOB ROOT_SOURCE *.cpp)
file(GLOB ROOT_INLINE *.inl)
file(GLOB ROOT_HEADER *.hpp)

file(GLOB_RECURSE CORE_SOURCE ./core/*.cpp)
file(GLOB_RECURSE CORE_INLINE ./core/*.inl)
file(GLOB_RECURSE CORE_HEADER ./core/*.hpp)

file(GLOB_RECURSE GTC_SOURCE ./gtc/*.cpp)
file(GLOB_RECURSE GTC_INLINE ./gtc/*.inl)
file(GLOB_RECURSE GTC_HEADER ./gtc/*.hpp)

file(GLOB_RECURSE GTX_SOURCE ./gtx/*.cpp)
file(GLOB_RECURSE GTX_INLINE ./gtx/*.inl)
file(GLOB_RECURSE GTX_HEADER ./gtx/*.hpp)

file(GLOB_RECURSE VIRTREV_SOURCE ./virtrev/*.cpp)
file(GLOB_RECURSE VIRTREV_INLINE ./virtrev/*.inl)
file(GLOB_RECURSE VIRTREV_HEADER ./virtrev/*.hpp)

source_group("Core Files" FILES ${CORE_SOURCE})
source_group("Core Files" FILES ${CORE_INLINE})
source_group("Core Files" FILES ${CORE_HEADER})
source_group("GTC Files" FILES ${GTC_SOURCE})
source_group("GTC Files" FILES ${GTC_INLINE})
source_group("GTC Files" FILES ${GTC_HEADER})
source_group("GTX Files" FILES ${GTX_SOURCE})
source_group("GTX Files" FILES ${GTX_INLINE})
source_group("GTX Files" FILES ${GTX_HEADER})
source_group("VIRTREV Files" FILES ${VIRTREV_SOURCE})
source_group("VIRTREV Files" FILES ${VIRTREV_INLINE})
source_group("VIRTREV Files" FILES ${VIRTREV_HEADER})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)

add_executable(${NAME}
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
${VIRTREV_SOURCE} ${VIRTREV_INLINE} ${VIRTREV_HEADER})
74 changes: 61 additions & 13 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,44 @@ __host__ __device__ bool calculateScatterAndAbsorption(ray& r, float& depth, Ab

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ glm::vec3 calculateTransmissionDirection(glm::vec3 normal, glm::vec3 incident, float incidentIOR, float transmittedIOR) {
return glm::vec3(0,0,0);
float n = incidentIOR / transmittedIOR;
float cosAngle = glm::dot(normal, -incident);
float k = 1.0f - ( n*n * (1.0 - cosAngle * cosAngle));
glm::vec3 transmission = n * incident + (n * cosAngle - sqrt(k)) * normal;

return glm::normalize(transmission);
//return glm::vec3(0,0,0);
}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ glm::vec3 calculateReflectionDirection(glm::vec3 normal, glm::vec3 incident) {
//nothing fancy here
return glm::vec3(0,0,0);
__host__ __device__ glm::vec3 calculateReflectionDirection(glm::vec3 normal, glm::vec3 incident)
{
//nothing fancy here, R=2(N.L)N+L
//return glm::vec3(0,0,0);
glm::vec3 rlect = incident - 2.0f * glm::dot(incident,normal) * normal ;
return rlect;
}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
__host__ __device__ Fresnel calculateFresnel(glm::vec3 normal, glm::vec3 incident, float incidentIOR, float transmittedIOR, glm::vec3 reflectionDirection, glm::vec3 transmissionDirection) {
Fresnel fresnel;

fresnel.reflectionCoefficient = 1;
fresnel.transmissionCoefficient = 0;
return fresnel;
//fresnel.reflectionCoefficient = 1;
//fresnel.transmissionCoefficient = 0;

float cosAngleIn = glm::dot(incident, normal);
float n1 = incidentIOR, n2 = transmittedIOR;
float tmpA = (n1*n1) / (n2*n2) * (1.0f - cosAngleIn * cosAngleIn);
float cosAngleTran = sqrt(1.0f - tmpA);

float Rs = ( (n1*cosAngleIn - n2*cosAngleTran) / ( n1*cosAngleIn + n2*cosAngleTran)) *
( (n1*cosAngleIn - n2*cosAngleTran) / ( n1*cosAngleIn + n2*cosAngleTran)) ;
float Rp = ( (n1*cosAngleTran - n2*cosAngleIn) / ( n2*cosAngleIn + n1*cosAngleTran)) *
( (n1*cosAngleTran - n2*cosAngleIn) / ( n2*cosAngleIn + n1*cosAngleTran)) ;

fresnel.reflectionCoefficient = (Rs + Rp) / 2.0f;
fresnel.transmissionCoefficient = 1 - fresnel.reflectionCoefficient;

return fresnel;
}

//LOOK: This function demonstrates cosine weighted random direction generation in a sphere!
Expand Down Expand Up @@ -89,17 +111,43 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
//TODO: IMPLEMENT THIS FUNCTION
//Now that you know how cosine weighted direction generation works, try implementing non-cosine (uniform) weighted random direction generation.
//This should be much easier than if you had to implement calculateRandomDirectionInHemisphere.
__host__ __device__ glm::vec3 getRandomDirectionInSphere(float xi1, float xi2) {
return glm::vec3(0,0,0);
__host__ __device__ glm::vec3 getRandomDirectionInSphere(float xi1, float xi2)
{//??????????what is xi1 and xi2???????????
//assume they are random numbers in [0,1];
float theta = TWO_PI * xi1;
float phi = acos( 2*xi2 - 1);

return ( glm::vec3( cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi) ) );

}

//TODO (PARTIALLY OPTIONAL): IMPLEMENT THIS FUNCTION
//returns 0 if diffuse scatter, 1 if reflected, 2 if transmitted.
__host__ __device__ int calculateBSDF(ray& r, glm::vec3 intersect, glm::vec3 normal, glm::vec3 emittedColor,
AbsorptionAndScatteringProperties& currentAbsorptionAndScattering,
glm::vec3& color, glm::vec3& unabsorbedColor, material m){

return 1;
glm::vec3& color, glm::vec3& unabsorbedColor, material m, float xi1, float xi2,int closestGeomIndex){
//Reflective material
if(m.hasReflective > 0)
{
r.continueFlag = true;
r.direction = calculateReflectionDirection(normal, r.direction);
r.origin = intersect + r.direction * 0.01f;
color = m.color;
}

//Refractive material--still working on it
else if(m.hasRefractive > 0) ;

//Diffuse material
else
{
r.continueFlag = true;
r.direction = calculateRandomDirectionInHemisphere(glm::normalize(normal), xi1, xi2);
r.origin = intersect + r.direction * 0.01f;
color = m.color;
}

return 0;
};

#endif
Expand Down
Loading