diff --git a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj
index fcc853d..eb2e8ce 100755
--- a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj
+++ b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj
@@ -92,6 +92,7 @@
$(ProjectDir)$(Platform)/$(Configuration)/%(Filename)%(Extension).obj
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include;C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/common/inc;../shared/glew/includes;../shared/freeglut/includes
+ compute_20,sm_20
diff --git a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
index d7ca222..cdad5b3 100755
--- a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
+++ b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
@@ -1,7 +1,11 @@
- scene="../../scenes/sampleScene.txt"
+ scene="J:\downloads_folder_till_sept26\gundeep-Project1-Raytracer-7a21b6b\scenes\sampleScene.txt"
+ WindowsLocalDebugger
+
+
+ scene="J:\downloads_folder_till_sept26\gundeep-Project1-Raytracer-7a21b6b\scenes\sampleScene.txt"
WindowsLocalDebugger
\ No newline at end of file
diff --git a/PROJ1_WIN/565Raytracer/Debug/565Raytracer.Build.CppClean.log b/PROJ1_WIN/565Raytracer/Debug/565Raytracer.Build.CppClean.log
new file mode 100644
index 0000000..2e2f32b
--- /dev/null
+++ b/PROJ1_WIN/565Raytracer/Debug/565Raytracer.Build.CppClean.log
@@ -0,0 +1,35 @@
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\565RAYTRACER.EXE.EMBED.MANIFEST
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\565RAYTRACER.EXE.EMBED.MANIFEST.RES
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\565RAYTRACER.EXE.INTERMEDIATE.MANIFEST
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\565Raytracer_manifest.rc
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\cl.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\CL.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\CL.write.1.tlog
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\GLSLUTILITY.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\IMAGE.OBJ
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.6420.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.6420.write.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.6420-cvtres.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.6420-cvtres.write.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link.write.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link-cvtres.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\link-cvtres.write.1.tlog
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\MAIN.OBJ
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\mt.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\mt.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\mt.write.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\raytraceKernel.cu.cache
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\rc.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\rc.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\rc.write.1.tlog
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\SCENE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\STB_IMAGE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\STB_IMAGE_WRITE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\UTILITIES.OBJ
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Debug\vc100.idb
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\DEBUG\VC100.PDB
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\DEBUG\565RAYTRACER.EXE
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\DEBUG\565RAYTRACER.ILK
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\DEBUG\565RAYTRACER.PDB
diff --git a/PROJ1_WIN/565Raytracer/Release/565Raytracer.Build.CppClean.log b/PROJ1_WIN/565Raytracer/Release/565Raytracer.Build.CppClean.log
new file mode 100644
index 0000000..2ee996a
--- /dev/null
+++ b/PROJ1_WIN/565Raytracer/Release/565Raytracer.Build.CppClean.log
@@ -0,0 +1,21 @@
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\565RAYTRACER.EXE.INTERMEDIATE.MANIFEST
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\cl.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\CL.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\CL.write.1.tlog
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\GLSLUTILITY.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\IMAGE.OBJ
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\link.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\link.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\link.write.1.tlog
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\MAIN.OBJ
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\mt.command.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\mt.read.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\mt.write.1.tlog
+C:\Users\gundeep\Downloads\Project1-Raytracer\PROJ1_WIN\565Raytracer\Release\raytraceKernel.cu.cache
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\SCENE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\STB_IMAGE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\STB_IMAGE_WRITE.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\UTILITIES.OBJ
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\565RAYTRACER\RELEASE\VC100.PDB
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\RELEASE\565RAYTRACER.EXE
+C:\USERS\GUNDEEP\DOWNLOADS\PROJECT1-RAYTRACER\PROJ1_WIN\RELEASE\565RAYTRACER.PDB
diff --git a/PROJ1_WIN/readme_raytracer.pdf b/PROJ1_WIN/readme_raytracer.pdf
new file mode 100644
index 0000000..452987b
Binary files /dev/null and b/PROJ1_WIN/readme_raytracer.pdf differ
diff --git a/PROJ1_WIN/renders/Render1.PNG b/PROJ1_WIN/renders/Render1.PNG
new file mode 100644
index 0000000..41ed053
Binary files /dev/null and b/PROJ1_WIN/renders/Render1.PNG differ
diff --git a/PROJ1_WIN/renders/diffusecolor.PNG b/PROJ1_WIN/renders/diffusecolor.PNG
new file mode 100644
index 0000000..e8eeb78
Binary files /dev/null and b/PROJ1_WIN/renders/diffusecolor.PNG differ
diff --git a/PROJ1_WIN/renders/raytracer_gpu.png b/PROJ1_WIN/renders/raytracer_gpu.png
new file mode 100644
index 0000000..6f0c4d6
Binary files /dev/null and b/PROJ1_WIN/renders/raytracer_gpu.png differ
diff --git a/src/interactions.h b/src/interactions.h
index e18cfff..2c558c4 100755
--- a/src/interactions.h
+++ b/src/interactions.h
@@ -90,7 +90,19 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
//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);
+
+
+ // to locate a point on the sphere we need two things the colatitute phi and longitude theta.
+
+ // then we can create a table of Data
+
+ const float r = std::sqrt(1.0f - xi1 * xi1);
+ const float phi = 2 * xi2;
+
+ return glm::vec3(glm::cos(phi) * r, glm::sin(phi) * r, xi1);
+
+
+
}
//TODO (PARTIALLY OPTIONAL): IMPLEMENT THIS FUNCTION
diff --git a/src/intersections.h b/src/intersections.h
index 2d9dcc8..7556edc 100755
--- a/src/intersections.h
+++ b/src/intersections.h
@@ -12,6 +12,8 @@
#include "utilities.h"
#include
+using namespace glm;
+
//Some forward declarations
__host__ __device__ glm::vec3 getPointOnRay(ray r, float t);
__host__ __device__ glm::vec3 multiplyMV(cudaMat4 m, glm::vec4 v);
@@ -72,7 +74,244 @@ __host__ __device__ glm::vec3 getSignOfRay(ray r){
//Cube intersection test, return -1 if no intersection, otherwise, distance to intersection
__host__ __device__ float boxIntersectionTest(staticGeom box, ray r, glm::vec3& intersectionPoint, glm::vec3& normal){
- return -1;
+ vec4 VO= vec4 (r.direction.x,r.direction.y,r.direction.z,0);
+ vec4 PO= vec4 (r.origin.x,r.origin.y,r.origin.z,1);
+
+ VO= glm::vec4(multiplyMV(box.inverseTransform,VO),0);
+ PO= glm::vec4(multiplyMV(box.inverseTransform,PO),1);
+
+ float T1,T2,temp;
+ float tnear= -500000.000;
+ float tfar= 500000.000;
+
+
+ vec4 BI= vec4(-0.5,-0.5,-0.5,1);
+ vec4 BH= vec4(0.5,0.5,0.5,1);
+
+ // for each pair of planes
+
+ if(VO.x ==0) // the ray is parallel to x planes
+ {
+ if (PO.x BH.x)//and if ray is not between the slabs then it will not intersect the planes. Logic hai :)
+ {
+ return -1;
+
+ }
+ }
+ else // when ray is not parallel to x axis
+ // compute intersection distance between the planes.
+ {
+ T1= (BI.x- PO.x)/VO.x;
+ T2= (BH.x - PO.x)/VO.x;
+
+ if (T1>T2) // swap T1 T2
+ {
+ temp=T1;
+ T1=T2;
+ T2=temp;
+ }
+
+ if (T1>tnear)
+ {
+ tnear=T1; // we want the largest tnear
+
+ }
+ if( T2tfar) // cube missed
+ {
+ return -1;
+ }
+
+ if(tfar<0)
+ {
+ return -1; // box bheind the light
+ }
+ }
+
+
+
+ // doing y planes now
+
+ if(VO.y == 0) // the ray is parallel to y planes
+ {
+ if (PO.y BH.y)//and if ray is not between the slabs then it will not intersect the planes. Logic hai :)
+ {
+ return -1;
+
+ }
+ }
+ else // when ray is not parallel to y axis
+ // compute intersection distance between the planes.
+ {
+ T1= (BI.y- PO.y)/VO.y;
+ T2= (BH.y - PO.y)/VO.y;
+
+ if (T1>T2) // swap T1 T2
+ {
+ temp=T1;
+ T1=T2;
+ T2=temp;
+ }
+
+ if (T1>tnear)
+ {
+ tnear=T1; // we want the largest tnear
+
+ }
+ if( T2tfar) // cube missed
+ {
+ return -1;
+ }
+
+ if(tfar<0)
+ {
+ return -1; // box bheind the light
+ }
+ }
+
+
+ // FOR Z PLANES NOW -----
+
+ if(VO.z == 0) // the ray is parallel to x planes
+ {
+ if (PO.z BH.z)//and if ray is not between the slabs then it will not intersect the planes. Logic hai :)
+ {
+ return -1;
+
+ }
+ }
+ else // when ray is not parallel to x axis
+ // compute intersection distance between the planes.
+ {
+ T1= (BI.z- PO.z)/VO.z;
+ T2= (BH.z - PO.z)/VO.z;
+
+ if (T1>T2) // swap T1 T2
+ {
+ temp=T1;
+ T1=T2;
+ T2=temp;
+ }
+
+ if (T1>tnear)
+ {
+ tnear=T1; // we want the largest tnear
+
+ }
+ if(T2tfar) // cube missed
+ {
+ return -1;
+ }
+
+ if(tfar<0)
+ {
+ return -1; // box bheind the light
+ }
+ if(tnear>0)
+ {
+ if(abs(tnear)<0.0001)
+ {
+ return -1;
+ }
+ else
+ {
+ glm::vec4 POI= PO+VO*tnear;
+ if(POI.x<=0.5+EPSILON && POI.x>=0.5-EPSILON)
+ {
+ normal=glm::vec3(1,0,0);
+ }
+ if(POI.x<=-0.5+EPSILON && POI.x>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(-1,0,0);
+ }
+ if(POI.y<=0.5+EPSILON && POI.y>=0.5-EPSILON)
+ {
+ normal=glm::vec3(0,1,0);
+ }
+ if(POI.y<=-0.5+EPSILON && POI.y>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(0,-1,0);
+ }
+ if(POI.z<=0.5+EPSILON && POI.z>=0.5-EPSILON)
+ {
+ normal=glm::vec3(0,0,1);
+ }
+ if(POI.z<=-0.5+EPSILON && POI.z>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(0,0,-1);
+ }
+
+ vec4 Normal= vec4(normal, 0);
+ //cudaMat4 transposed = box.tranposeTranform);
+ normal= multiplyMV(box.tranposeTranform,Normal);
+ glm::vec3 test= normal;;
+
+ }
+ intersectionPoint = r.origin + r.direction*tnear;
+ return tnear;
+ }
+ }
+
+ if (abs(tnear) < 0.001)
+ return -1;
+ if (tnear > 0)
+ {
+ intersectionPoint = r.origin + r.direction*tnear;
+ return tnear;
+ }
+ if(abs(tfar) < 0.001)
+ return -1;
+ if (tfar > 0)
+ {
+ glm::vec4 POI= PO+VO*tfar;
+ if(POI.x<=0.5+EPSILON && POI.x>=0.5-EPSILON)
+ {
+ normal=glm::vec3(1,0,0);
+ }
+ if(POI.x<=-0.5+EPSILON && POI.x>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(-1,0,0);
+ }
+ if(POI.y<=0.5+EPSILON && POI.y>=0.5-EPSILON)
+ {
+ normal=glm::vec3(0,1,0);
+ }
+ if(POI.y<=-0.5+EPSILON && POI.y>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(0,-1,0);
+ }
+ if(POI.z<=0.5+EPSILON && POI.z>=0.5-EPSILON)
+ {
+ normal=glm::vec3(0,0,1);
+ }
+ if(POI.z<=-0.5+EPSILON && POI.z>=-0.5-EPSILON)
+ {
+ normal=glm::vec3(0,0,-1);
+ }
+
+ vec4 Normal= vec4(normal, 0);
+ //glm::mat4 transposed2= glm::mat4(box.tranposeTranform);
+ normal= multiplyMV(box.tranposeTranform,Normal);
+ glm::vec3 test=normal;
+ intersectionPoint = r.origin + r.direction*tfar;
+ return tfar;
+ }
+ return -1;
+
}
//LOOK: Here's an intersection test example from a sphere. Now you just need to figure out cube and, optionally, triangle.
diff --git a/src/raytraceKernel.cu b/src/raytraceKernel.cu
index dae7b03..4095d08 100755
--- a/src/raytraceKernel.cu
+++ b/src/raytraceKernel.cu
@@ -17,6 +17,7 @@
#include "interactions.h"
#include
+
void checkCUDAError(const char *msg) {
cudaError_t err = cudaGetLastError();
if( cudaSuccess != err) {
@@ -36,13 +37,76 @@ __host__ __device__ glm::vec3 generateRandomNumberFromThread(glm::vec2 resolutio
return glm::vec3((float) u01(rng), (float) u01(rng), (float) u01(rng));
}
+
+
+
//TODO: IMPLEMENT THIS FUNCTION
//Function that does the initial raycast from the camera
__host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time, int x, int y, glm::vec3 eye, glm::vec3 view, glm::vec3 up, glm::vec2 fov){
- ray r;
- r.origin = glm::vec3(0,0,0);
- r.direction = glm::vec3(0,0,-1);
- return r;
+
+ ray r;
+ r.origin = eye;
+
+
+ float degToRad = PI/180.0;
+
+ float radToDeg = 180.0/PI;
+
+ float H = (float)(resolution[0] / 2);
+
+ float V = (float)(resolution[1] / 2);
+
+ //printf("%f", H);
+
+ float camDistFromScreen = (float)(V / tan(fov[1] * degToRad));
+ //printf(" %f " , camDistFromScreen);
+
+ // Get the horizontal view in degrees
+
+ float fieldViewX = (float)atan((H) / camDistFromScreen);
+
+ fieldViewX *= radToDeg;
+
+ //Find the vector C (Camera Direction)
+
+ float multiplier = camDistFromScreen / sqrt(pow(view[0],2) + pow(view[1],2) + pow(view[2],2));
+
+ glm::vec3 camVector = glm::vec3(view[0] * multiplier,view[1] * multiplier, view[2] * multiplier);
+
+ glm::vec3 midpointScreen =glm::vec3(eye[0] + camVector.x, eye[1] +camVector.y, eye[2] + camVector.z) ;
+
+ // Calculate NDC values for the coordinates
+
+ float sx = (float)(1.0 * x / resolution[0]);
+
+ float sy = (float)(1.0 * y / resolution[1]);
+
+ //printf(" %f ", sx);
+
+ // Calculate the point coordinates in 3D space
+
+ glm::vec3 pointOnScreen;
+
+ pointOnScreen.x = ((2 * sx) - 1) *H;
+
+ pointOnScreen.y = ((2 * sy) - 1) *V;
+
+ pointOnScreen.z = 0;
+
+ glm::vec3 color= glm::vec3 (1,0,0);
+
+ glm::vec3 P =midpointScreen + pointOnScreen;
+
+ glm::vec3 Eye= glm::vec3(eye[0],eye[1],eye[2]);
+
+ glm::vec3 direction= (P -Eye) / sqrt( pow(P.x-Eye.x,2) + pow(P.y - Eye.y,2) + pow(P.z - Eye.z,2));
+
+ r.direction = direction;
+
+ r.origin=eye;
+
+ return r;
+
}
//Kernel that blacks out a given image buffer
@@ -60,19 +124,21 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3*
int x = (blockIdx.x * blockDim.x) + threadIdx.x;
int y = (blockIdx.y * blockDim.y) + threadIdx.y;
+
int index = x + (y * resolution.x);
+
if(x<=resolution.x && y<=resolution.y){
glm::vec3 color;
color.x = image[index].x*255.0;
- color.y = image[index].x*255.0;
- color.z = image[index].x*255.0;
+ color.y = image[index].y*255.0;
+ color.z = image[index].z*255.0;
if(color.x>255){
color.x = 255;
}
-
+
if(color.y>255){
color.y = 255;
}
@@ -82,6 +148,9 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3*
}
// Each thread writes one pixel location in the texture (textel)
+ y=resolution.y-y;
+ x=resolution.x-x;
+ index = x + (y * resolution.x);
PBOpos[index].w = 0;
PBOpos[index].x = color.x;
PBOpos[index].y = color.y;
@@ -91,17 +160,245 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3*
//TODO: IMPLEMENT THIS FUNCTION
//Core raytracer kernel
-__global__ void raytraceRay(glm::vec2 resolution, float time, cameraData cam, int rayDepth, glm::vec3* colors,
+__global__ void raytraceRay(material* mats, glm::vec2 resolution, float time, cameraData cam, int rayDepth, glm::vec3* colors,
staticGeom* geoms, int numberOfGeoms){
+ glm::vec3 light_pos=glm::vec3(0,3,10);
+ glm::vec3 light_col=glm::vec3(1.0,1.0,1.0);
+ int anti_alias_loop=0;
+
+
int x = (blockIdx.x * blockDim.x) + threadIdx.x;
int y = (blockIdx.y * blockDim.y) + threadIdx.y;
int index = x + (y * resolution.x);
- if((x<=resolution.x && y<=resolution.y)){
+ while(anti_alias_loop<=4)
+ {
+
+ anti_alias_loop++;
+ int tempX=x;
+ int tempY=y;
+
+
+ if( anti_alias_loop==4)
+ {
+
+ tempX+0.5;
+ }
+ else if( anti_alias_loop==1)
+ {
+
+ tempY+0.5;
- colors[index] = generateRandomNumberFromThread(resolution, time, x, y);
+ }
+
+ else if (anti_alias_loop==2)
+ {
+ tempX-0,5;
+ }
+
+ else if(anti_alias_loop==3);
+ {
+ tempY -0.5;
+
+ }
+
+ glm::vec3 intersectionPoint= glm::vec3(0,0,0);
+ glm::vec3 spec_color;
+
+ colors[index]=glm::vec3(0,0,0);
+
+ staticGeom* geometry=geoms;
+ //material* mat=mats;
+
+ glm::vec3 POI;
+
+ if((x<=resolution.x && y<=resolution.y))
+ {
+ ray ray_for_scene= raycastFromCameraKernel( resolution, time, tempX, tempY, cam.position, cam.view, cam.up, cam.fov);
+ int no_of_iterations=0;
+
+ while(no_of_iterations 0)
+ {
+ if(tmin<0 || sphere_intersection_test0)
+ {
+ if(tmin<0 || cube_intersection_test 0 && (tLight < 0 || tLightTemp < tLight))
+ if (tLightTemp > 0 && tLightTemp < (dist-0.01))
+ {
+ tLight = tLightTemp;
+ blocked = true;
+ //normal=lightNormal;
+ }
+ }
+
+ if (geoms[i].type == CUBE)
+ {
+ float tLightTemp = boxIntersectionTest(geoms[i], lightRay, lightIntersectPoint, lightNormal);
+ //if (tLightTemp > 0 && (tLight < 0 || tLightTemp < tLight))
+ if (tLightTemp > 0 && tLightTemp < (dist-0.01))
+ {
+ tLight = tLightTemp;
+ blocked = true;
+ //normal=lightNormal;
+ }
+ }
+ }
+
+ //if (tLight > 0 && tLight < (dist - EPSILON))
+ if (blocked)
+ {
+ // light is blocked
+ colors[index]= glm::vec3(0,0,0);
+ }
+ else
+ {
+ if(no_of_iterations==0)
+ {
+ normal= glm::normalize(normal);
+ lightRay.direction=glm::normalize(lightRay.direction);
+ glm::vec3 diffuse= abs(glm::dot(lightRay.direction,normal))*mats[mat_id].color;
+ glm::vec3 refelectedrayspec=glm::normalize(lightRay.direction -(normal+normal)*(glm::dot(lightRay.direction,normal)));
+
+ float specdot= abs(glm::dot(refelectedrayspec,glm::normalize(POI-cam.position)));
+ float specularity=0.2 * pow(specdot,mats[mat_id].specularExponent);
+ colors[index]+= diffuse*light_col + light_col*specularity; //+(specularity/3 *light_col);
+ // colors[index]= mats[mat_id].color;
+ if(mats[mat_id].hasReflective >0 )
+ {
+
+ normal=glm::normalize(normal);
+ ray_for_scene.direction=glm::normalize(ray_for_scene.direction);
+ glm::vec3 reflectedRay;
+
+ reflectedRay= ray_for_scene.direction- (normal+normal)*(glm::dot(ray_for_scene.direction,normal));
+ reflectedRay = glm::normalize(reflectedRay);
+
+ spec_color=mats[mat_id].hasReflective * mats[mat_id].specularColor;
+ spec_color=glm::clamp(spec_color,0.0,1.0);
+
+ ray_for_scene.origin=POI;
+ ray_for_scene.direction=reflectedRay;
+ }
+
+ }
+
+ else
+ {
+ normal= glm::normalize(normal);
+ lightRay.direction=glm::normalize(lightRay.direction);
+ glm::vec3 diffuse= (abs(glm::dot(lightRay.direction,normal))*mats[mat_id].color);
+ glm::vec3 refelectedrayspec=glm::normalize(lightRay.direction -(normal+normal)*(glm::dot(lightRay.direction,normal)));
+
+ float specdot= abs(glm::dot(refelectedrayspec,glm::normalize(POI-cam.position)));
+ float specularity=0.2 * pow(specdot,mats[mat_id].specularExponent);
+ colors[index]+= diffuse*light_col + light_col*specularity; //+(specularity/3 *light_col);
+
+ colors[index].x=colors[index].x/2;
+ colors[index].y=colors[index].y/2;
+ colors[index].z=colors[index].z/2;
+
+ // colors[index]= mats[mat_id].color;
+ if(mats[mat_id].hasReflective >0 )
+ {
+ normal=glm::normalize(normal);
+ ray_for_scene.direction=glm::normalize(ray_for_scene.direction);
+ glm::vec3 reflectedRay;
+
+ reflectedRay= ray_for_scene.direction- (normal+normal)*(glm::dot(ray_for_scene.direction,normal));
+ reflectedRay = glm::normalize(reflectedRay);
+
+ spec_color=mats[mat_id].hasReflective * mats[mat_id].specularColor;
+ spec_color=glm::clamp(spec_color,0.0,1.0);
+
+ ray_for_scene.origin=POI;
+ ray_for_scene.direction=reflectedRay;
+
+ }
+ }
+
+ }
+
+ }
+
+
+ }
+ }
+
}
+ colors[index]=colors[index]/1.0f;
+ colors[index]=glm::clamp(colors[index],0,1.0);
}
@@ -109,7 +406,7 @@ __global__ void raytraceRay(glm::vec2 resolution, float time, cameraData cam, in
// Wrapper for the __global__ call that sets up the kernel calls and does a ton of memory management
void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iterations, material* materials, int numberOfMaterials, geom* geoms, int numberOfGeoms){
- int traceDepth = 1; //determines how many bounces the raytracer traces
+ int traceDepth =2; //determines how many bounces the raytracer traces
// set up crucial magic
int tileSize = 8;
@@ -120,7 +417,31 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
glm::vec3* cudaimage = NULL;
cudaMalloc((void**)&cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3));
cudaMemcpy( cudaimage, renderCam->image, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyHostToDevice);
-
+
+ // send materials to GPU
+ material* material_List= new material[numberOfMaterials];
+ for (int i=0; iresolution;
@@ -146,9 +470,10 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
cam.view = renderCam->views[frame];
cam.up = renderCam->ups[frame];
cam.fov = renderCam->fov;
-
+
+
//kernel launches
- raytraceRay<<>>(renderCam->resolution, (float)iterations, cam, traceDepth, cudaimage, cudageoms, numberOfGeoms);
+ raytraceRay<<>>(cudamaterials , renderCam->resolution, (float)iterations, cam, traceDepth, cudaimage, cudageoms, numberOfGeoms);
sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage);
@@ -157,6 +482,7 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
//free up stuff, or else we'll leak memory like a madman
cudaFree( cudaimage );
+ cudaFree(cudamaterials);
cudaFree( cudageoms );
delete geomList;
diff --git a/src/scene.cpp b/src/scene.cpp
index f0384b2..162bad0 100755
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -116,6 +116,7 @@ int scene::loadObject(string objectid){
newObject.scales = new glm::vec3[frameCount];
newObject.transforms = new cudaMat4[frameCount];
newObject.inverseTransforms = new cudaMat4[frameCount];
+ newObject.tranposeTranforms= new cudaMat4[frameCount];
for(int i=0; i