diff --git a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj
index fcc853d..75def98 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
@@ -117,6 +118,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..872ccbe 100755
--- a/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
+++ b/PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
@@ -4,4 +4,8 @@
scene="../../scenes/sampleScene.txt"
WindowsLocalDebugger
+
+ scene="C:\Users\gundeep\Downloads\Project2-Pathtracer\scenes\sampleScene.txt"
+ WindowsLocalDebugger
+
\ No newline at end of file
diff --git a/PROJ1_WIN/565Raytracer/vc100.pdb b/PROJ1_WIN/565Raytracer/vc100.pdb
new file mode 100644
index 0000000..74f396e
Binary files /dev/null and b/PROJ1_WIN/565Raytracer/vc100.pdb differ
diff --git a/PROJ1_WIN/Gundeep Singh_pathtracer.pdf b/PROJ1_WIN/Gundeep Singh_pathtracer.pdf
new file mode 100644
index 0000000..407a9f9
Binary files /dev/null and b/PROJ1_WIN/Gundeep Singh_pathtracer.pdf differ
diff --git a/PROJ1_WIN/Release/565Raytracer1.exe b/PROJ1_WIN/Release/565Raytracer1.exe
new file mode 100644
index 0000000..d2ca79e
Binary files /dev/null and b/PROJ1_WIN/Release/565Raytracer1.exe differ
diff --git a/PROJ1_WIN/Release/FInal_image.PNG b/PROJ1_WIN/Release/FInal_image.PNG
new file mode 100644
index 0000000..26eb1c2
Binary files /dev/null and b/PROJ1_WIN/Release/FInal_image.PNG differ
diff --git a/PROJ1_WIN/Release/sampleScene.txt b/PROJ1_WIN/Release/sampleScene.txt
new file mode 100644
index 0000000..2c196e2
--- /dev/null
+++ b/PROJ1_WIN/Release/sampleScene.txt
@@ -0,0 +1,230 @@
+MATERIAL 0 //white diffuse
+RGB 1 1 1
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 1 //red diffuse
+RGB .63 .06 .04
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 2 //green diffuse
+RGB .15 .48 .09
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 3 //red glossy
+RGB .63 .06 .04
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 2
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 4 //white glossy
+RGB 1 1 1
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 2
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 5 //glass
+RGB 0 0 0
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 1
+REFRIOR 2.2
+SCATTER 0
+ABSCOEFF .02 5.1 5.7
+RSCTCOEFF 13
+EMITTANCE 0
+
+MATERIAL 6 //green glossy
+RGB .15 .48 .09
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 2.6
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 7 //light
+RGB 1 1 1
+SPECEX 0
+SPECRGB 0 0 0
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 1
+
+MATERIAL 8 //light
+RGB 1 1 1
+SPECEX 0
+SPECRGB 0 0 0
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 15
+
+CAMERA
+RES 800 800
+FOVY 25
+ITERATIONS 5000
+FILE renders/sampleScene.bmp
+APERTURE 5.6
+frame 0
+EYE 0 4.5 12
+VIEW 0 0 -1
+UP 0 1 0
+frame 1
+EYE 0 4.5 12
+VIEW 0 0 -1
+UP 0 1 0
+
+OBJECT 0
+cube
+material 0
+frame 0
+TRANS 0 0 0
+ROTAT 0 0 90
+SCALE .01 10 10
+frame 1
+TRANS 0 0 0
+ROTAT 0 0 90
+SCALE .01 10 10
+
+OBJECT 1
+cube
+material 0
+frame 0
+TRANS 0 5 -5
+ROTAT 0 90 0
+SCALE .01 10 10
+frame 1
+TRANS 0 5 -5
+ROTAT 0 90 0
+SCALE .01 10 10
+
+OBJECT 2
+cube
+material 0
+frame 0
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .01 10 10
+frame 1
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .01 10 10
+
+OBJECT 3
+cube
+material 1
+frame 0
+TRANS -5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+frame 1
+TRANS -5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+
+OBJECT 4
+cube
+material 2
+frame 0
+TRANS 5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+frame 1
+TRANS 5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+
+OBJECT 5
+sphere
+material 4
+frame 0
+TRANS 0 2 0
+ROTAT 0 180 0
+SCALE 3 3 3
+frame 1
+TRANS 0 2 0
+ROTAT 0 180 0
+SCALE 3 3 3
+
+OBJECT 6
+sphere
+material 3
+frame 0
+TRANS 2 5 2
+ROTAT 0 180 0
+SCALE 2.5 2.5 2.5
+frame 1
+TRANS 2 5 2
+ROTAT 0 180 0
+SCALE 2.5 2.5 2.5
+
+OBJECT 7
+sphere
+material 2
+frame 0
+TRANS -2 5 -2
+ROTAT 0 180 0
+SCALE 3 3 3
+frame 1
+TRANS -2 5 -2
+ROTAT 0 180 0
+SCALE 3 3 3
+
+OBJECT 8
+cube
+material 8
+frame 0
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .3 8 8
+frame 1
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .3 8 8
\ No newline at end of file
diff --git a/PROJ1_WIN/Release/shaders/passthroughFS.glsl b/PROJ1_WIN/Release/shaders/passthroughFS.glsl
new file mode 100644
index 0000000..9f6d7c5
--- /dev/null
+++ b/PROJ1_WIN/Release/shaders/passthroughFS.glsl
@@ -0,0 +1,8 @@
+varying vec2 v_Texcoords;
+
+uniform sampler2D u_image;
+
+void main(void)
+{
+ gl_FragColor = texture2D(u_image, v_Texcoords);
+}
diff --git a/PROJ1_WIN/Release/shaders/passthroughVS.glsl b/PROJ1_WIN/Release/shaders/passthroughVS.glsl
new file mode 100644
index 0000000..55db651
--- /dev/null
+++ b/PROJ1_WIN/Release/shaders/passthroughVS.glsl
@@ -0,0 +1,9 @@
+attribute vec4 Position;
+attribute vec2 Texcoords;
+varying vec2 v_Texcoords;
+
+void main(void)
+{
+ v_Texcoords = Texcoords;
+ gl_Position = Position;
+}
\ No newline at end of file
diff --git a/PROJ1_WIN/ipch/565raytracer-a3a36c37/565raytracer-19509b53.ipch b/PROJ1_WIN/ipch/565raytracer-a3a36c37/565raytracer-19509b53.ipch
new file mode 100644
index 0000000..5897306
Binary files /dev/null and b/PROJ1_WIN/ipch/565raytracer-a3a36c37/565raytracer-19509b53.ipch differ
diff --git a/scenes/565Raytracer.exe b/scenes/565Raytracer.exe
new file mode 100644
index 0000000..b9f26a2
Binary files /dev/null and b/scenes/565Raytracer.exe differ
diff --git a/scenes/sampleScene.txt b/scenes/sampleScene.txt
index 936135b..df8f764 100755
--- a/scenes/sampleScene.txt
+++ b/scenes/sampleScene.txt
@@ -1,229 +1,242 @@
-MATERIAL 0 //white diffuse
-RGB 1 1 1
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 0
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 1 //red diffuse
-RGB .63 .06 .04
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 0
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 2 //green diffuse
-RGB .15 .48 .09
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 0
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 3 //red glossy
-RGB .63 .06 .04
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 2
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 4 //white glossy
-RGB 1 1 1
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 2
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 5 //glass
-RGB 0 0 0
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 1
-REFRIOR 2.2
-SCATTER 0
-ABSCOEFF .02 5.1 5.7
-RSCTCOEFF 13
-EMITTANCE 0
-
-MATERIAL 6 //green glossy
-RGB .15 .48 .09
-SPECEX 0
-SPECRGB 1 1 1
-REFL 0
-REFR 0
-REFRIOR 2.6
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 0
-
-MATERIAL 7 //light
-RGB 1 1 1
-SPECEX 0
-SPECRGB 0 0 0
-REFL 0
-REFR 0
-REFRIOR 0
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 1
-
-MATERIAL 8 //light
-RGB 1 1 1
-SPECEX 0
-SPECRGB 0 0 0
-REFL 0
-REFR 0
-REFRIOR 0
-SCATTER 0
-ABSCOEFF 0 0 0
-RSCTCOEFF 0
-EMITTANCE 15
-
-CAMERA
-RES 800 800
-FOVY 25
-ITERATIONS 5000
-FILE renders/sampleScene.bmp
-frame 0
-EYE 0 4.5 12
-VIEW 0 0 -1
-UP 0 1 0
-frame 1
-EYE 0 4.5 12
-VIEW 0 0 -1
-UP 0 1 0
-
-OBJECT 0
-cube
-material 0
-frame 0
-TRANS 0 0 0
-ROTAT 0 0 90
-SCALE .01 10 10
-frame 1
-TRANS 0 0 0
-ROTAT 0 0 90
-SCALE .01 10 10
-
-OBJECT 1
-cube
-material 0
-frame 0
-TRANS 0 5 -5
-ROTAT 0 90 0
-SCALE .01 10 10
-frame 1
-TRANS 0 5 -5
-ROTAT 0 90 0
-SCALE .01 10 10
-
-OBJECT 2
-cube
-material 0
-frame 0
-TRANS 0 10 0
-ROTAT 0 0 90
-SCALE .01 10 10
-frame 1
-TRANS 0 10 0
-ROTAT 0 0 90
-SCALE .01 10 10
-
-OBJECT 3
-cube
-material 1
-frame 0
-TRANS -5 5 0
-ROTAT 0 0 0
-SCALE .01 10 10
-frame 1
-TRANS -5 5 0
-ROTAT 0 0 0
-SCALE .01 10 10
-
-OBJECT 4
-cube
-material 2
-frame 0
-TRANS 5 5 0
-ROTAT 0 0 0
-SCALE .01 10 10
-frame 1
-TRANS 5 5 0
-ROTAT 0 0 0
-SCALE .01 10 10
-
-OBJECT 5
-sphere
-material 4
-frame 0
-TRANS 0 2 0
-ROTAT 0 180 0
-SCALE 3 3 3
-frame 1
-TRANS 0 2 0
-ROTAT 0 180 0
-SCALE 3 3 3
-
-OBJECT 6
-sphere
-material 3
-frame 0
-TRANS 2 5 2
-ROTAT 0 180 0
-SCALE 2.5 2.5 2.5
-frame 1
-TRANS 2 5 2
-ROTAT 0 180 0
-SCALE 2.5 2.5 2.5
-
-OBJECT 7
-sphere
-material 6
-frame 0
-TRANS -2 5 -2
-ROTAT 0 180 0
-SCALE 3 3 3
-frame 1
-TRANS -2 5 -2
-ROTAT 0 180 0
-SCALE 3 3 3
-
-OBJECT 8
-cube
-material 8
-frame 0
-TRANS 0 10 0
-ROTAT 0 0 90
-SCALE .3 3 3
-frame 1
-TRANS 0 10 0
-ROTAT 0 0 90
-SCALE .3 3 3
\ No newline at end of file
+MATERIAL 0 //white diffuse
+RGB 1 1 1
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 1 //red diffuse
+RGB .9 .7 .4
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 2 //green diffuse
+RGB .03 .46 .86
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 3 //red glossy
+RGB .63 .9 .04
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 2
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 4 //white glossy
+RGB .45 .44 .34
+SPECEX 0
+SPECRGB 1 1 1
+REFL 1
+REFR 0
+REFRIOR 2
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 5 //glass
+RGB 0 0 0
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 1
+REFRIOR 1.3
+SCATTER 0
+ABSCOEFF .02 5.1 5.7
+RSCTCOEFF 13
+EMITTANCE 0
+
+MATERIAL 6 //green glossy
+RGB .15 .48 .09
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 2.6
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+MATERIAL 7 //light
+RGB 1 1 1
+SPECEX 0
+SPECRGB 0 0 0
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 1
+
+MATERIAL 8 //light
+RGB 1 1 1
+SPECEX 0
+SPECRGB 0 0 0
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 8
+
+MATERIAL 9 //purple diffuse
+RGB 0.05 0.81 0.62
+SPECEX 0
+SPECRGB 1 1 1
+REFL 0
+REFR 0
+REFRIOR 0
+SCATTER 0
+ABSCOEFF 0 0 0
+RSCTCOEFF 0
+EMITTANCE 0
+
+CAMERA
+RES 1000 1000
+FOVY 25
+ITERATIONS 20000
+FILE renders/sampleScene.bmp
+frame 0
+EYE 0 4.5 12
+VIEW 0 0 -1
+UP 0 1 0
+frame 1
+EYE 0 4.5 12
+VIEW 0 0 -1
+UP 0 1 0
+
+OBJECT 0
+cube
+material 0
+frame 0
+TRANS 0 0 0
+ROTAT 0 0 90
+SCALE .01 10 10
+frame 1
+TRANS 0 0 0
+ROTAT 0 0 90
+SCALE .01 10 10
+
+OBJECT 1
+cube
+material 9
+frame 0
+TRANS 0 5 -5
+ROTAT 0 90 0
+SCALE .01 10 10
+frame 1
+TRANS 0 5 -5
+ROTAT 0 90 0
+SCALE .01 10 10
+
+OBJECT 2
+cube
+material 0
+frame 0
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .01 10 10
+frame 1
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .01 10 10
+
+OBJECT 3
+cube
+material 1
+frame 0
+TRANS -5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+frame 1
+TRANS -5 5 0
+ROTAT 0 0 0
+SCALE .01 10 10
+
+OBJECT 4
+cube
+material 2
+frame 0
+TRANS 5 5 -2
+ROTAT 0 0 0
+SCALE .01 10 10
+frame 1
+TRANS 5 5 -2
+ROTAT 0 0 0
+SCALE .01 10 10
+
+OBJECT 5
+sphere
+material 5
+frame 0
+TRANS 3.5 1.5 -2.0
+ROTAT 0 180 0
+SCALE 2 2 2
+frame 1
+TRANS 0 2 -1
+ROTAT 0 180 0
+SCALE 3 3 3
+
+OBJECT 6
+sphere
+material 3
+frame 0
+TRANS 0 4 -1.25
+ROTAT 0 180 0
+SCALE 2.5 2.5 2.5
+frame 1
+TRANS 2 4 -8
+ROTAT 0 180 0
+SCALE 1.5 1.5 1.5
+
+OBJECT 7
+sphere
+material 4
+frame 0
+TRANS -2.5 5 2
+ROTAT 0 180 0
+SCALE 2 2 2
+frame 1
+TRANS -2 5 -2
+ROTAT 0 180 0
+SCALE 3 3 3
+
+OBJECT 8
+cube
+material 8
+frame 0
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .3 4 4
+frame 1
+TRANS 0 10 0
+ROTAT 0 0 90
+SCALE .3 4 4
+
diff --git a/src/interactions.h b/src/interactions.h
index e18cfff..7c9ca54 100755
--- a/src/interactions.h
+++ b/src/interactions.h
@@ -8,6 +8,8 @@
#include "intersections.h"
+
+
struct Fresnel {
float reflectionCoefficient;
float transmissionCoefficient;
@@ -63,8 +65,8 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
//crucial difference between this and calculateRandomDirectionInSphere: THIS IS COSINE WEIGHTED!
- float up = sqrt(xi1); // cos(theta)
- float over = sqrt(1 - up * up); // sin(theta)
+ float up = (sqrt(xi1)); // cos(theta)
+ float over = sqrt(1 - up * up); // sin(theta)
float around = xi2 * TWO_PI;
//Find a direction that is not the normal based off of whether or not the normal's components are all equal to sqrt(1/3) or whether or not at least one component is less than sqrt(1/3). Learned this trick from Peter Kutz.
@@ -79,10 +81,10 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
}
//Use not-normal direction to generate two perpendicular directions
- glm::vec3 perpendicularDirection1 = glm::normalize(glm::cross(normal, directionNotNormal));
- glm::vec3 perpendicularDirection2 = glm::normalize(glm::cross(normal, perpendicularDirection1));
+ glm::vec3 perpendicularDirection1 = (glm::cross(normal, directionNotNormal));
+ glm::vec3 perpendicularDirection2 = (glm::cross(normal, perpendicularDirection1));
- return ( up * normal ) + ( cos(around) * over * perpendicularDirection1 ) + ( sin(around) * over * perpendicularDirection2 );
+ return glm::normalize( ( up * normal ) + ( cos(around) * over * perpendicularDirection1 ) + ( sin(around) * over * perpendicularDirection2 ));
}
@@ -90,16 +92,51 @@ __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);
+
+
+
+ float up = xi1 * 2 - 1; // cos(theta)
+ float over = sqrt(1 - up * up); // sin(theta)
+ float around = xi2 * TWO_PI;
+
+ return glm::vec3( up, cos(around) * over, sin(around) * over );
+
+
}
//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;
+//__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){
+
+__host__ __device__ int calculateBSDF(ray& r, glm::vec3 intersect, glm::vec3 normal, glm::vec3& color, material m,glm::vec3 random_direction,float bounces,
+ glm::vec2 resolution, int index)
+{
+
+
+ glm::vec3 temp_color;
+ //glm::vec3 random_direction;
+ if(m.hasReflective==0 && m.hasRefractive==0)
+ {
+
+ r.direction=(random_direction);
+ //r.direction=random_direction;
+
+ r.origin=intersect;
+ if (bounces==1)
+ {
+ temp_color=m.color;
+
+ }
+ else
+ {
+ temp_color*=m.color;
+ }
+ color=temp_color;
+ }
+ return 1;
+
};
#endif
diff --git a/src/intersections.h b/src/intersections.h
index 714e918..c5805df 100755
--- a/src/intersections.h
+++ b/src/intersections.h
@@ -1,4 +1,4 @@
-// CIS565 CUDA Raytracer: A parallel raytracer for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania
+// CIS565 CUDA Raytracer: A parallel raytracer for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania
// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania
// This file includes code from:
// Yining Karl Li's TAKUA Render, a massively parallel pathtracing renderer: http://www.yiningkarlli.com
@@ -12,8 +12,11 @@
#include "utilities.h"
#include
+using namespace glm;
+
//Some forward declarations
__host__ __device__ glm::vec3 getPointOnRay(ray r, float t);
+__host__ __device__ glm::vec3 getPointOnRayUnnormalized(ray r, float t);
__host__ __device__ glm::vec3 multiplyMV(cudaMat4 m, glm::vec4 v);
__host__ __device__ glm::vec3 getSignOfRay(ray r);
__host__ __device__ glm::vec3 getInverseDirectionOfRay(ray r);
@@ -44,7 +47,12 @@ __host__ __device__ bool epsilonCheck(float a, float b){
//Self explanatory
__host__ __device__ glm::vec3 getPointOnRay(ray r, float t){
- return r.origin + float(t-.0001)*glm::normalize(r.direction);
+ return r.origin + float(t)*(r.direction);
+}
+
+
+__host__ __device__ glm::vec3 getPointOnRayUnnormalized(ray r, float t){
+ return r.origin + float(t)*(r.direction);
}
//LOOK: This is a custom function for multiplying cudaMat4 4x4 matrixes with vectors.
@@ -76,91 +84,311 @@ __host__ __device__ float boxIntersectionTest(staticGeom box, ray r, glm::vec3&
//Cube intersection test, return -1 if no intersection, otherwise, distance to intersection
__host__ __device__ float boxIntersectionTest(glm::vec3 boxMin, glm::vec3 boxMax, staticGeom box, ray r, glm::vec3& intersectionPoint, glm::vec3& normal){
- glm::vec3 currentNormal = glm::vec3(0,0,0);
+glm::vec3 P0 = multiplyMV(box.inverseTransform, glm::vec4(r.origin, 1.0f));
- ray ro = r;
+glm::vec3 V0 = multiplyMV(box.inverseTransform, glm::vec4(r.direction, 0.0f));
- glm::vec3 iP0 = multiplyMV(box.inverseTransform,glm::vec4(r.origin, 1.0f));
- glm::vec3 iP1 = multiplyMV(box.inverseTransform,glm::vec4(r.origin+r.direction, 1.0f));
- glm::vec3 iV0 = iP1 - iP0;
+ray rt;
- r.origin = iP0;
- r.direction = glm::normalize(iV0);
+rt.origin = P0;
- float tmin, tmax, tymin, tymax, tzmin, tzmax;
+rt.direction = V0;
- glm::vec3 rsign = getSignOfRay(r);
- glm::vec3 rInverseDirection = getInverseDirectionOfRay(r);
+float xmin = -0.5, xmax = 0.5;
- if((int)rsign.x==0){
- tmin = (boxMin.x - r.origin.x) * rInverseDirection.x;
- tmax = (boxMax.x - r.origin.x) * rInverseDirection.x;
- }else{
- tmin = (boxMax.x - r.origin.x) * rInverseDirection.x;
- tmax = (boxMin.x - r.origin.x) * rInverseDirection.x;
- }
+float ymin = -0.5, ymax = 0.5;
- if((int)rsign.y==0){
- tymin = (boxMin.y - r.origin.y) * rInverseDirection.y;
- tymax = (boxMax.y - r.origin.y) * rInverseDirection.y;
- }else{
- tymin = (boxMax.y - r.origin.y) * rInverseDirection.y;
- tymax = (boxMin.y - r.origin.y) * rInverseDirection.y;
- }
+float zmin = -0.5, zmax = 0.5;
- if ( (tmin > tymax) || (tymin > tmax) ){
- return -1;
- }
- if (tymin > tmin){
- tmin = tymin;
- }
- if (tymax < tmax){
- tmax = tymax;
- }
+float tFar = 999999; //std::numeric_limits::max();
- if((int)rsign.z==0){
- tzmin = (boxMin.z - r.origin.z) * rInverseDirection.z;
- tzmax = (boxMax.z - r.origin.z) * rInverseDirection.z;
- }else{
- tzmin = (boxMax.z - r.origin.z) * rInverseDirection.z;
- tzmax = (boxMin.z - r.origin.z) * rInverseDirection.z;
- }
+float tNear = -999999;//std::numeric_limits::min();
- if ( (tmin > tzmax) || (tzmin > tmax) ){
- return -1;
- }
- if (tzmin > tmin){
- tmin = tzmin;
- }
- if (tzmax < tmax){
- tmax = tzmax;
- }
- if(tmin<0){
- return -1;
- }
+float t1, t2;
- glm::vec3 osintersect = r.origin + tmin*r.direction;
-
- if(abs(osintersect.x-abs(boxMax.x))<.001){
- currentNormal = glm::vec3(1,0,0);
- }else if(abs(osintersect.y-abs(boxMax.y))<.001){
- currentNormal = glm::vec3(0,1,0);
- }else if(abs(osintersect.z-abs(boxMax.z))<.001){
- currentNormal = glm::vec3(0,0,1);
- }else if(abs(osintersect.x+abs(boxMin.x))<.001){
- currentNormal = glm::vec3(-1,0,0);
- }else if(abs(osintersect.y+abs(boxMin.y))<.001){
- currentNormal = glm::vec3(0,-1,0);
- }else if(abs(osintersect.z+abs(boxMin.z))<.001){
- currentNormal = glm::vec3(0,0,-1);
- }
+// For the X planes
+
+if (rt.direction.x == 0)
+
+{
+
+// Ray is || to x-axis
+
+// The light point should be in between the xmin and xmax bounds. Else it doesn't intersect
+
+if (rt.origin.x < xmin || rt.origin.x > xmax)
+
+{
+
+return -1;
+
+}
+
+}
+
+else
+
+{
+
+// T1 = (Xl - Xo) / Xd
+
+t1 = (xmin - rt.origin.x)/rt.direction.x;
+
+// T2 = (Xh - Xo) / Xd
+
+t2 = (xmax - rt.origin.x)/rt.direction.x;
+
+// If T1 > T2 swap (T1, T2) /* since T1 intersection with near plane */
+
+if (t1 > t2)
+
+{
+
+//swap t1 and t2
+
+double temp = t1;
+
+t1 = t2;
+
+t2 = temp;
+
+}
+
+// If T1 > Tnear set Tnear =T1 /* want largest Tnear */
+
+if (t1 > tNear)
+
+tNear = t1;
+
+// If T2 < Tfar set Tfar="T2" /* want smallest Tfar */
+
+if (t2 < tFar)
+
+tFar = t2;
+
+// If Tnear > Tfar box is missed so return false
+
+if (tNear > tFar)
+
+return -1;
+
+// If Tfar < 0 box is behind ray return false end
+
+if (tFar < 0)
+
+return -1;
+
+}
+
+// For the Y planes
+
+if (rt.direction.y == 0)
+
+{
+
+// Ray is || to y-axis
+
+// The light point should be in between the ymin and ymax bounds. Else it doesn't intersect
+
+if (rt.origin.y < ymin || rt.origin.y > ymax)
+
+{
+
+return -1;
+
+}
+
+}
+
+else
+
+{
+
+// T1 = (Yl - Yo) / Yd
+
+t1 = (ymin - rt.origin.y)/rt.direction.y;
+
+// T2 = (Yh - Yo) / Yd
+
+t2 = (ymax - rt.origin.y)/rt.direction.y;
+
+// If T1 > T2 swap (T1, T2) /* since T1 intersection with near plane */
+
+if (t1 > t2)
+
+{
+
+//swap t1 and t2
+
+double temp = t1;
+
+t1 = t2;
+
+t2 = temp;
+
+}
+
+// If T1 > Tnear set Tnear =T1 /* want largest Tnear */
+
+if (t1 > tNear)
+
+tNear = t1;
+
+// If T2 < Tfar set Tfar="T2" /* want smallest Tfar */
+
+if (t2 < tFar)
+
+tFar = t2;
+
+// If Tnear > Tfar box is missed so return false
+
+if (tNear > tFar)
+
+return -1;
+
+// If Tfar < 0 box is behind ray return false end
+
+if (tFar < 0)
+
+return -1;
+
+}
+
+// For the Z planes
+
+if (rt.direction.z == 0)
+
+{
+
+// Ray is || to z-axis
+
+// The light point should be in between the zmin and zmax bounds. Else it doesn't intersect
+
+if (rt.origin.z < zmin || rt.origin.z > zmax)
+
+{
+
+return -1;
+
+}
+
+}
+
+else
+
+{
+
+// T1 = (Zl - Zo) / Zd
+
+t1 = (zmin - rt.origin.z)/rt.direction.z;
+
+// T2 = (Zh - Zo) / Zd
+
+t2 = (zmax - rt.origin.z)/rt.direction.z;
+
+// If T1 > T2 swap (T1, T2) /* since T1 intersection with near plane */
+
+if (t1 > t2)
+
+{
+
+//swap t1 and t2
+
+double temp = t1;
+
+t1 = t2;
+
+t2 = temp;
+
+}
+
+// If T1 > Tnear set Tnear =T1 /* want largest Tnear */
+
+if (t1 > tNear)
+
+tNear = t1;
+
+// If T2 < Tfar set Tfar="T2" /* want smallest Tfar */
+
+if (t2 < tFar)
+
+tFar = t2;
+
+// If Tnear > Tfar box is missed so return false
+
+if (tNear > tFar)
+
+return -1;
+
+// If Tfar < 0 box is behind ray return false end
+
+if (tFar < 0)
+
+return -1;
+
+}
+
+// Box survived all above tests, return with intersection point Tnear and exit point Tfar.
+
+double t;
+
+if (abs(tNear) < 1e-3)
+
+{
+
+if (abs(tFar) < 1e-3) // on the surface
+
+return -1;
+
+t = tFar;
+
+}
+
+else
+
+{
+
+t = tNear;
+
+}
+
+glm::vec3 p = getPointOnRayUnnormalized(rt, t);
+
+glm::vec4 surNormalTemp = glm::vec4(0.0,0.0,0.0,0.0);
+
+if (p.x <= xmin+(1e-3) && p.x >= xmin-(1e-3))
+
+surNormalTemp.x = -1;
+
+if (p.y <= ymin+(1e-3) && p.y >= ymin-(1e-3))
+
+surNormalTemp.y = -1;
+
+if (p.z <= zmin+(1e-3) && p.z >= zmin-(1e-3))
+
+surNormalTemp.z = -1;
+
+if (p.x <= xmax+(1e-3) && p.x >= xmax-(1e-3))
+
+surNormalTemp.x = 1;
+
+if (p.y <= ymax+(1e-3) && p.y >= ymax-(1e-3))
+
+surNormalTemp.y = 1;
+
+if (p.z <= zmax+(1e-3) && p.z >= zmax-(1e-3))
+
+surNormalTemp.z = 1;
+
+normal = multiplyMV(box.tranposeTranform, surNormalTemp);
- intersectionPoint = multiplyMV(box.transform, glm::vec4(osintersect, 1.0));
+normal = glm::normalize(normal);
+intersectionPoint = getPointOnRay(r, t);
+//intersectionPoint = multiplyMV(box.transform, glm::vec4(getPointOnRay(rt, t), 1.0));
- normal = multiplyMV(box.transform, glm::vec4(currentNormal,0.0));
- return glm::length(intersectionPoint-ro.origin);
+return t;
}
//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 d473c89..5358d59 100755
--- a/src/raytraceKernel.cu
+++ b/src/raytraceKernel.cu
@@ -5,6 +5,7 @@
// Peter Kutz and Yining Karl Li's GPU Pathtracer: http://gpupathtracer.blogspot.com/
// Yining Karl Li's TAKUA Render, a massively parallel pathtracing renderer: http://www.yiningkarlli.com
+#include
#include
#include
#include
@@ -17,6 +18,16 @@
#include
#include "glm/glm.hpp"
+
+ struct isNegative
+ {
+ __host__ __device__
+ bool operator()(const ray & x)
+ {
+ return !x.useful;
+ }
+ };
+
void checkCUDAError(const char *msg) {
cudaError_t err = cudaGetLastError();
if( cudaSuccess != err) {
@@ -35,17 +46,33 @@ __host__ __device__ glm::vec3 generateRandomNumberFromThread(glm::vec2 resolutio
return glm::vec3((float) u01(rng), (float) u01(rng), (float) u01(rng));
}
+__host__ __device__ glm::vec3 generateRandomNumberFromThread2(glm::vec2 resolution, float time, int x, int y){
+ int index = x + (y * resolution.x);
+
+ thrust::default_random_engine rng(hash(index*time));
+ thrust::uniform_real_distribution u01(-0.5,0.5);
+
+ return glm::vec3((float) u01(rng), (float) u01(rng), (float) u01(rng));
+}
//Kernel that does the initial raycast from the camera and caches the result. "First bounce cache, second bounce thrash!"
-__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){
+
+//host and device mean compile one version on the CPU and one version on CPU
+__global__ void raycastFromCameraKernel(glm::vec2 resolution, float time, glm::vec3 eye, glm::vec3 view, glm::vec3 up, glm::vec2 fov, ray* ray_bundle, glm::vec3* temp){
+ float x = (blockIdx.x * blockDim.x) + threadIdx.x;
+ float y = (blockIdx.y * blockDim.y) + threadIdx.y;
+
int index = x + (y * resolution.x);
+
+ glm::vec3 rand=generateRandomNumberFromThread2(resolution,time,x,y);
- thrust::default_random_engine rng(hash(index*time));
- thrust::uniform_real_distribution u01(0,1);
-
+ x=x+rand.x;
+ y=y+rand.y;
+
+
//standard camera raycast stuff
- glm::vec3 E = eye;
+ glm::vec3 E1 = eye;
glm::vec3 C = view;
glm::vec3 U = up;
float fovx = fov.x;
@@ -55,7 +82,7 @@ __host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time
glm::vec3 A = glm::cross(C, U);
glm::vec3 B = glm::cross(A, C);
- glm::vec3 M = E+C;
+ glm::vec3 M = E1+C;
glm::vec3 H = (A*float(CD*tan(fovx*(PI/180))))/float(glm::length(A));
glm::vec3 V = (B*float(CD*tan(-fovy*(PI/180))))/float(glm::length(B));
@@ -63,15 +90,41 @@ __host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time
float sy = (y)/(resolution.y-1);
glm::vec3 P = M + (((2*sx)-1)*H) + (((2*sy)-1)*V);
- glm::vec3 PmE = P-E;
- glm::vec3 R = E + (float(200)*(PmE))/float(glm::length(PmE));
+ glm::vec3 PmE = P-E1;
+ glm::vec3 R = E1 + (float(200)*(PmE))/float(glm::length(PmE));
glm::vec3 direction = glm::normalize(R);
//major performance cliff at this point, TODO: find out why!
+ bool dof=true;
+ //if (dof)
+
+ glm::vec3 focuspoint= glm::vec3(0,0,0);
+ glm::vec3 unitvec1= glm::normalize(focuspoint-eye);
+ glm::vec3 unitvec2= glm::normalize(direction);
+ float z_dist= focuspoint.z- eye.z;
+
+ // using similar triangles
+
+ float y_dist = ((z_dist)/(unitvec2.z))*unitvec2.y;
+ float x_dist= unitvec2.x *((z_dist)/(unitvec2.z));
+
+ glm::vec3 rand1=generateRandomNumberFromThread2(resolution,time*11,x,y);
+ glm::vec3 new_eye= glm::vec3(eye.x+(rand1.x)*2,eye.y+(rand1.y)*2,eye.z);
+
+ glm::vec3 new_direction=glm::normalize(eye+glm::vec3(x_dist,y_dist,z_dist) - new_eye);
ray r;
- r.origin = eye;
- r.direction = direction;
- return r;
+ r.origin = new_eye;
+ r.direction = new_direction;
+
+
+ ray_bundle[index].direction=new_direction;
+ ray_bundle[index].origin=new_eye;
+ ray_bundle[index].index_ray=index;
+ ray_bundle[index].useful = true;
+
+ // Reset temp
+ temp[index]= glm::vec3(1.0f,1.0f,1.0f);
+ //printf("\nraypacket index %f",ray_bundle->index_ray ); // also to check if we did all the 640000 rays
}
//Kernel that blacks out a given image buffer
@@ -85,19 +138,27 @@ __global__ void clearImage(glm::vec2 resolution, glm::vec3* image){
}
//Kernel that writes the image to the OpenGL PBO directly.
-__global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3* image){
+
+// global means launched by CPU
+__global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3* image, float time, ray* raybundle){
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;
+ glm::vec3 color;
+ glm::vec3 addingcolor;
+
+ color.x = image[index].x*255.0;
color.y = image[index].y*255.0;
color.z = image[index].z*255.0;
+ // color+=color;
+
if(color.x>255){
color.x = 255;
}
@@ -118,62 +179,230 @@ __global__ void sendImageToPBO(uchar4* PBOpos, glm::vec2 resolution, glm::vec3*
}
}
+//__global__ void dof(raypacket)
+
//TODO: IMPLEMENT THIS FUNCTION
//Core raytracer kernel
__global__ void raytraceRay(glm::vec2 resolution, float time, cameraData cam, int rayDepth, glm::vec3* colors,
- staticGeom* geoms, int numberOfGeoms, material* materials, int numberOfMaterials){
+ staticGeom* geoms, int numberOfGeoms, material* materials, int numberOfMaterials,
+ glm::vec3* renderimage, ray* raybundle, int bounces, glm::vec3* temp)
+{
int x = (blockIdx.x * blockDim.x) + threadIdx.x;
int y = (blockIdx.y * blockDim.y) + threadIdx.y;
int index = x + (y * resolution.x);
+
+ if (raybundle[index].useful)
+ {
+ glm::vec3 old_color= glm::vec3(0,0,0);
+ old_color=renderimage[raybundle[index].index_ray] * (time-1);
+ //glm::clamp(old_color,0.0f,1.0f);
+
+ //colors[raybundle[index].index_ray]=renderimage[raybundle[index].index_ray];
- ray r = raycastFromCameraKernel(resolution, time, x, y, cam.position, cam.view, cam.up, cam.fov);
-
- if((x<=resolution.x && y<=resolution.y)){
-
- float MAX_DEPTH = 100000000000000000;
- float depth = MAX_DEPTH;
-
- for(int i=0; i-EPSILON){
- MAX_DEPTH = depth;
- colors[index] = materials[geoms[i].materialid].color;
- }
- }
+ if((x<=resolution.x && y<=resolution.y))
+ {
+ float depth = 0;
+ glm::vec3 normal;
+
+ glm::vec3 random_direction;
+ int Object_number;
+ float tmin=-1;
+ Object_number=0;
+ glm::vec3 POI;
+ //printf("\n%f index", raybundle[index].index_ray);
+ for(int i=0; i-EPSILON)
+ {
+ if (tmin<=EPSILON || depth-EPSILON)
+ {
+ if (tmin<=EPSILON || depth0 )
+ {
+ // //glm::vec3 old_color=colors[index]*(time-1);
+ colors[raybundle[index].index_ray]=(old_color+( temp[raybundle[index].index_ray]*materials[geoms[Object_number].materialid].color*materials[geoms[Object_number].materialid].emittance))/time; //old_color+
+ //glm::clamp(colors[raybundle[index].index_ray],0.0f,1.0f);
+ raybundle[index].useful=false;
+ return;
+ }
+ else if (materials[geoms[Object_number].materialid].hasReflective>0)
+ {
+ normal=glm::normalize(normal);
+ raybundle[index].direction=glm::normalize(raybundle[index].direction);
+ glm::vec3 reflectedRay;
+ reflectedRay= raybundle[index].direction- (normal +normal)*(glm::dot(raybundle[index].direction,normal));
+ reflectedRay = glm::normalize(reflectedRay);
+ raybundle[index].origin=POI;
+ raybundle[index].direction=reflectedRay;
+ }
+ else if(materials[geoms[Object_number].materialid].hasRefractive>0)
+ {
+ float n1=1;
+ float n2=(materials[geoms[Object_number].materialid].indexOfRefraction);
+ glm::vec3 incident=raybundle[index].direction;
+
+ float magnitugeAxB=glm::length(glm::cross(normal,incident));
+ float magA=glm::length(normal);
+ float magB=glm::length(raybundle[index].direction);
+ float sin0i=glm::sin((magnitugeAxB)/(magA*magB));
+ // printf("%f",sin0i);
+
+ float sin0r= ((n1)/(n2)) *sin0i;
+
+ float cos0i= glm::sqrt(1-sin0i*sin0i);
+ float cos0r= glm::sqrt(1-sin0r*sin0r);
+
+ glm::vec3 refracted= ((n1)/(n2))*incident + (((n1)/(n2))*cos0i-cos0r)*normal;
+
+ ray refractedray;
+ refractedray.origin=POI;
+ refractedray.direction= refracted;
+
+ for(int i=0; i-EPSILON)
+ {
+ if (tmin<=EPSILON || depth-EPSILON)
+ {
+ if (tmin<=EPSILON || depthresolution.x*(int)renderCam->resolution.y;
// set up crucial magic
int tileSize = 8;
dim3 threadsPerBlock(tileSize, tileSize);
dim3 fullBlocksPerGrid((int)ceil(float(renderCam->resolution.x)/float(tileSize)), (int)ceil(float(renderCam->resolution.y)/float(tileSize)));
+
//send image to GPU
+
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);
+
+ glm::vec3* renderimage=NULL;
+ cudaMalloc((void**)&renderimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3));
+ cudaMemcpy(renderimage,renderCam->image, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyHostToDevice);
+
+ glm::vec3* temp_color=NULL;
+ cudaMalloc((void**)&temp_color,(int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3));
//package geometry and materials and sent to GPU
staticGeom* geomList = new staticGeom[numberOfGeoms];
@@ -186,6 +415,7 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
newStaticGeom.scale = geoms[i].scales[frame];
newStaticGeom.transform = geoms[i].transforms[frame];
newStaticGeom.inverseTransform = geoms[i].inverseTransforms[frame];
+ newStaticGeom.tranposeTranform=geoms[i].tranposeTranforms[frame];
geomList[i] = newStaticGeom;
}
@@ -193,6 +423,12 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
cudaMalloc((void**)&cudageoms, numberOfGeoms*sizeof(staticGeom));
cudaMemcpy( cudageoms, geomList, numberOfGeoms*sizeof(staticGeom), cudaMemcpyHostToDevice);
+
+ ray* raypacket=NULL;
+ cudaMalloc((void**)&raypacket,(int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(ray));
+ //cudaMemcpy(ray_packet, raypacket,640000*sizeof(ray),cudaMemcpyDevicetoDevice;
+
+
material* cudamaterials = NULL;
cudaMalloc((void**)&cudamaterials, numberOfMaterials*sizeof(material));
cudaMemcpy( cudamaterials, materials, numberOfMaterials*sizeof(material), cudaMemcpyHostToDevice);
@@ -204,20 +440,41 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
cam.view = renderCam->views[frame];
cam.up = renderCam->ups[frame];
cam.fov = renderCam->fov;
+ //cam.image=renderCam->image;
+
+ //kernel call for camera rays
+
+ raycastFromCameraKernel<<>>( renderCam->resolution, (float)iterations, cam.position, cam.view, cam.up, cam.fov, raypacket, temp_color);
- //kernel launches
- raytraceRay<<>>(renderCam->resolution, (float)iterations, cam, traceDepth, cudaimage, cudageoms, numberOfGeoms, cudamaterials,
- numberOfMaterials);
+ //kernel launches
+ while(bounces<10)
+ {
+ bounces++;
+ dim3 fullBlockPerGridSC((int)ceil(float(renderCam->resolution.x)/float(tileSize)), ((int)activerays)/(float(tileSize)*(int)ceil(float(renderCam->resolution.x))));
+
+ raytraceRay<<>>(renderCam->resolution, (float)iterations, cam, traceDepth, cudaimage, cudageoms, numberOfGeoms, cudamaterials,
+ numberOfMaterials,renderimage, raypacket,bounces,temp_color);
+ thrust::device_ptr devicePointer(raypacket);
+ thrust::device_ptr newEnd=thrust::remove_if(devicePointer,devicePointer+activerays, isNegative());
+ activerays= newEnd.get() - devicePointer.get();
+
+ }
+
- sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage);
+ sendImageToPBO<<>>(PBOpos, renderCam->resolution, cudaimage,(float)iterations,raypacket);
//retrieve image from GPU
cudaMemcpy( renderCam->image, cudaimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyDeviceToHost);
+ //cudaMemcpy( renderCam->image, renderimage, (int)renderCam->resolution.x*(int)renderCam->resolution.y*sizeof(glm::vec3), cudaMemcpyDeviceToHost);
+
//free up stuff, or else we'll leak memory like a madman
- cudaFree( cudaimage );
- cudaFree( cudageoms );
- cudaFree( cudamaterials );
+ cudaFree(raypacket);
+ cudaFree(cudaimage);
+ cudaFree(cudageoms);
+ cudaFree(cudamaterials);
+ cudaFree(renderimage);
+ cudaFree(temp_color);
delete [] geomList;
// make certain the kernel has completed
@@ -225,3 +482,6 @@ void cudaRaytraceCore(uchar4* PBOpos, camera* renderCam, int frame, int iteratio
checkCUDAError("Kernel failed!");
}
+//thrust::device_ptr devicePointer(activePixels);
+ // thrust::device_ptr newEnd = thrust::remove_if(devicePointer, devicePointer + numActivePixels, isNegative());
+ // numActivePixels = newEnd.get() - activePixels;
\ No newline at end of file
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
#include "cudaMat4.h"
-const float PI =3.1415926535897932384626422832795028841971;
-const float TWO_PI =6.2831853071795864769252867665590057683943;
-const float SQRT_OF_ONE_THIRD =0.5773502691896257645091487805019574556476;
-const float E =2.7182818284590452353602874713526624977572;
-const float EPSILON =.000000001;
-const float ZERO_ABSORPTION_EPSILON =0.00001;
-const float RAY_BIAS_AMOUNT =0.0002;
+#define PI 3.1415926535897932384626422832795028841971
+#define TWO_PI 6.2831853071795864769252867665590057683943
+#define SQRT_OF_ONE_THIRD 0.5773502691896257645091487805019574556476
+#define E 2.7182818284590452353602874713526624977572
+#define EPSILON .001
+#define ZERO_ABSORPTION_EPSILON 0.00001
+#define RAY_BIAS_AMOUNT 0.0002
namespace utilityCore {
extern float clamp(float f, float min, float max);