Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d7a63f
raytraceKernel.cu
Sep 17, 2013
32e3720
raytraceKernel.cu
Sep 17, 2013
2399504
raytraceKernel.cu
Sep 19, 2013
7635b32
raytraceKernel.cu
Sep 19, 2013
127c31c
raytraceKernel.cu
Sep 19, 2013
1f60eef
raytraceKernel.cu
Sep 19, 2013
de40f1a
intersections.h
Sep 20, 2013
c64e670
intersections.h
Sep 20, 2013
e318aff
Some results needs better
Sep 21, 2013
b52d35c
work with shadow diffusion a little bit specular
Sep 21, 2013
cb0bba1
Create README_qiong.md
GabriellaQiong Sep 21, 2013
0f7876e
Update README_qiong.md
GabriellaQiong Sep 21, 2013
9046e16
Update README_qiong.md
GabriellaQiong Sep 21, 2013
cfb2a1a
video added
Sep 21, 2013
8db6fd6
progress at noon
Sep 23, 2013
a291633
final update
Sep 23, 2013
8fdae59
Merge branch 'master' of https://github.com/GabriellaQiong/Project1-R…
Sep 23, 2013
8384d41
final update
Sep 23, 2013
6d123a6
Update README_qiong.md
GabriellaQiong Sep 23, 2013
e823765
Delete README.md
GabriellaQiong Sep 23, 2013
7762b43
Rename README_qiong.md to README.md
GabriellaQiong Sep 23, 2013
29afc49
Update README.md
GabriellaQiong Sep 23, 2013
b435962
Update README.md
GabriellaQiong Sep 23, 2013
c6ff47b
add references
GabriellaQiong Sep 23, 2013
f0cbc1a
demo
Sep 23, 2013
c34a89c
Delete ScreenCapture_9-20-2013 11.54.31 PM_20317.wmv
GabriellaQiong Sep 23, 2013
8933cd7
Merge branch 'master' of https://github.com/GabriellaQiong/Project1-R…
Sep 23, 2013
cf27509
demo
Sep 23, 2013
400ac5d
revising indent
Sep 23, 2013
189bd6a
demo_pdf
Sep 23, 2013
aa36779
Update README.md
GabriellaQiong Sep 24, 2013
78021f4
video screen shot
Sep 24, 2013
fa3f864
Update README.md
GabriellaQiong Sep 24, 2013
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 09201746snip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09202017snip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09221128snip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09222118snip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 09222119snip.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Project1_demo.pdf
Binary file not shown.
Binary file added Project1_demo.pptx
Binary file not shown.
374 changes: 66 additions & 308 deletions README.md

Large diffs are not rendered by default.

Binary file added ScreenCapture_9-22-2013 10.24.08 PM.wmv
Binary file not shown.
6 changes: 3 additions & 3 deletions scenes/sampleScene.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ EMITTANCE 0

MATERIAL 3 //red glossy
RGB .63 .06 .04
SPECEX 0
SPECEX 500
SPECRGB 1 1 1
REFL 0
REFR 0
Expand All @@ -48,7 +48,7 @@ EMITTANCE 0

MATERIAL 4 //white glossy
RGB 1 1 1
SPECEX 0
SPECEX 500
SPECRGB 1 1 1
REFL 0
REFR 0
Expand All @@ -72,7 +72,7 @@ EMITTANCE 0

MATERIAL 6 //green glossy
RGB .15 .48 .09
SPECEX 0
SPECEX 500
SPECRGB 1 1 1
REFL 0
REFR 0
Expand Down
18 changes: 11 additions & 7 deletions src/interactions.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ __host__ __device__ glm::vec3 calculateTransmissionDirection(glm::vec3 normal, g
return glm::vec3(0,0,0);
}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION -- This is Done
__host__ __device__ glm::vec3 calculateReflectionDirection(glm::vec3 normal, glm::vec3 incident) {
//nothing fancy here
return glm::vec3(0,0,0);
//nothing fancy here (simple vector addition)
return (glm::normalize(incident - 2.0f * glm::dot(incident, normal) * normal));
}

//TODO (OPTIONAL): IMPLEMENT THIS FUNCTION
Expand All @@ -60,7 +60,7 @@ __host__ __device__ Fresnel calculateFresnel(glm::vec3 normal, glm::vec3 inciden

//LOOK: This function demonstrates cosine weighted random direction generation in a sphere!
__host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 normal, float xi1, float xi2) {

// PERSONAL NOTES: the cosine weighted random direction is on the up direction normal to the hemisphere
//crucial difference between this and calculateRandomDirectionInSphere: THIS IS COSINE WEIGHTED!

float up = sqrt(xi1); // cos(theta)
Expand All @@ -83,22 +83,26 @@ __host__ __device__ glm::vec3 calculateRandomDirectionInHemisphere(glm::vec3 nor
glm::vec3 perpendicularDirection2 = glm::normalize(glm::cross(normal, perpendicularDirection1));

return ( up * normal ) + ( cos(around) * over * perpendicularDirection1 ) + ( sin(around) * over * perpendicularDirection2 );

}

//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);
// xi1, xi2 in [0, 1) the uniform weighted random direction means each direction has equal probability of being selected
// Reffering to Emmanuel Agu's slides for the difference between cosine-weighted and uniform sampling
float r = sqrt(1.0f - xi1);
float theta = xi2 * TWO_PI;
return glm::vec3(r * cos(theta), r * sin(theta), xi1);
}

//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;
return 1;
};

Expand Down
145 changes: 139 additions & 6 deletions src/intersections.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ __host__ __device__ glm::vec3 getPointOnRay(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);
__host__ __device__ float boxIntersectionTest(staticGeom sphere, ray r, glm::vec3& intersectionPoint, glm::vec3& normal);
__host__ __device__ float boxIntersectionTest(staticGeom box, ray r, glm::vec3& intersectionPoint, glm::vec3& normal);
__host__ __device__ float sphereIntersectionTest(staticGeom sphere, ray r, glm::vec3& intersectionPoint, glm::vec3& normal);
__host__ __device__ glm::vec3 getRandomPointOnCube(staticGeom cube, float randomSeed);

Expand All @@ -43,7 +43,8 @@ __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);
// Add a big epsilon amount .001 forward along the shadow ray (.0001 previously) so as to avoid floating problem
return r.origin + float(t-.001)*glm::normalize(r.direction);
}

//LOOK: This is a custom function for multiplying cudaMat4 4x4 matrixes with vectors.
Expand Down Expand Up @@ -71,8 +72,126 @@ __host__ __device__ glm::vec3 getSignOfRay(ray r){
//TODO: IMPLEMENT THIS FUNCTION
//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){

// Find the inverse transformed ray in the origin centered coordinates
glm::vec3 ro = multiplyMV(box.inverseTransform, glm::vec4(r.origin, 1.0f));
glm::vec3 rd = glm::normalize(multiplyMV(box.inverseTransform, glm::vec4(r.direction, 0.0f)));
ray rt; rt.origin = ro; rt.direction = rd;

// Find the inverse direction ray avoiding -/+ 0 determination
glm::vec3 inverseDirection = getInverseDirectionOfRay(rt);
glm::vec3 signInverseDirection = getSignOfRay(rt);

// Initialize the minimum and maximum distance to intersection to compare
float tmin, tmax, minLimit, maxLimit;
minLimit = -1e7;
maxLimit = 1e7;
tmin = minLimit;
tmax = maxLimit;

// Find the bounding volumn's maximum and minimum extent t1/t0
glm::vec3 t0, t1;
t0.x = (0.5 * (2 * signInverseDirection.x - 1) - ro.x) * inverseDirection.x;
t1.x = (0.5 * (1 - 2 * signInverseDirection.x) - ro.x) * inverseDirection.x;
t0.y = (0.5 * (2 * signInverseDirection.y - 1) - ro.y) * inverseDirection.y;
t1.y = (0.5 * (1 - 2 * signInverseDirection.y) - ro.y) * inverseDirection.y;
t0.z = (0.5 * (2 * signInverseDirection.z - 1) - ro.z) * inverseDirection.z;
t1.z = (0.5 * (1 - 2 * signInverseDirection.z) - ro.z) * inverseDirection.z;

// Surface flags to point out which is the nearest and farthest surface along the intersection direction
int nearFlag, farFlag; // which can be one value in pool of {1, 2, 3}, respectively indicating two surfaces along x || y || z axis

// Compare maxima and minima to determine the intersections
if(t0.x < 0 && t1.x < 0)
return -1; // whether there is only inverse intersection

if(t0.x > 0) {
tmin = (tmin > t0.x) ? tmin : t0.x;
if(tmin == t0.x)
nearFlag = 1; // update tmin if t0.x is positive and finite and set x to be the nearest surface axis
}
if(t1.x > 0) {
tmax = (tmax < t1.x) ? tmax : t1.x;
if(tmax == t1.x)
farFlag = 1; // update tmax if t1.x is positive and finite and set x to be the nearest surface axis
}

// Then compare the current tmin and tmax with y, update
if(t0.y < 0 && t1.y < 0)
return -1;
if(tmin > t1.y || t0.y > tmax)
return -1; // whether the ray passes around the cube

if(t0.y > 0) {
tmin = (tmin > t0.y) ? tmin : t0.y;
if(tmin == t0.y)
nearFlag = 2; // update tmin if t0.y is positive and larger than tmin and set y to be the nearest surface axis
}
if(t1.y > 0) {
tmax = (tmax < t1.y) ? tmax : t1.y;
if(tmax == t1.y)
farFlag = 2; // update tmax if t1.y is positive and less than tmax and set y to be the nearest surface axis
}

// Then compare the current tmin and tmax with z, update
if(t0.z < 0 && t1.z < 0)
return -1;
if(tmin > t1.z || t0.z > tmax)
return -1;

if(t0.z > 0) {
tmin = (tmin > t0.z) ? tmin : t0.z;
if(tmin == t0.z)
nearFlag = 3; // update tmin if t0.z is positive and larger than tmin and set z to be the nearest surface axis
}
if(t1.z > 0 && t1.z < tmax) {
tmax = (tmax < t1.z) ? tmax : t1.z;
if(tmax == t1.z)
farFlag = 3; // update tmax if t1.z is positive and less than tmax and set z to be the nearest surface axis
}

glm::vec3 intersectionPointTmp, normalTmp;
// Update the normal and intersection point if the tmax or tmax are not all infinity
if(epsilonCheck(tmin, minLimit) == 0) {
intersectionPointTmp = getPointOnRay(rt, tmin);
if(nearFlag == 1) {
normalTmp = glm::vec3(-1, 0, 0);
if(signInverseDirection.x)
normalTmp.x = 1;
} else if(nearFlag == 2) {
normalTmp = glm::vec3(0, -1, 0);
if(signInverseDirection.y)
normalTmp.y = 1;
} else if(nearFlag ==3){
normalTmp = glm::vec3(0, 0, -1);
if(signInverseDirection.z)
normalTmp.z = 1;
}
} else if(epsilonCheck(tmax, maxLimit) == 0) {
intersectionPointTmp = getPointOnRay(rt, tmax);
if(farFlag == 1) {
normalTmp = glm::vec3(-1, 0, 0);
if(signInverseDirection.x)
normalTmp.x = 1;
} else if(farFlag == 2) {
normalTmp = glm::vec3(0, -1, 0);
if(signInverseDirection.y)
normalTmp.y = 1;
} else {
normalTmp = glm::vec3(0, 0, -1);
if(signInverseDirection.z)
normalTmp.z = 1;
}
} else {
return -1;
}

// Find the distance between real intersection point and transform back the normal
glm::vec3 realIntersectionPoint = multiplyMV(box.transform, glm::vec4(intersectionPointTmp, 1.0f));
intersectionPoint = realIntersectionPoint;
normal = glm::normalize(multiplyMV(box.transform, glm::vec4(normalTmp, 0.0f)));
return glm::length(r.origin - realIntersectionPoint);

return -1;
}

//LOOK: Here's an intersection test example from a sphere. Now you just need to figure out cube and, optionally, triangle.
Expand Down Expand Up @@ -101,9 +220,9 @@ __host__ __device__ float sphereIntersectionTest(staticGeom sphere, ray r, glm::
if (t1 < 0 && t2 < 0) {
return -1;
} else if (t1 > 0 && t2 > 0) {
t = min(t1, t2);
t = glm::min(t1, t2); // min
} else {
t = max(t1, t2);
t = glm::max(t1, t2); // max
}

glm::vec3 realIntersectionPoint = multiplyMV(sphere.transform, glm::vec4(getPointOnRay(rt, t), 1.0));
Expand Down Expand Up @@ -176,8 +295,22 @@ __host__ __device__ glm::vec3 getRandomPointOnCube(staticGeom cube, float random
//TODO: IMPLEMENT THIS FUNCTION
//Generates a random point on a given sphere
__host__ __device__ glm::vec3 getRandomPointOnSphere(staticGeom sphere, float randomSeed){

// Generate random number
thrust::default_random_engine rng(hash(randomSeed));
thrust::uniform_real_distribution<float> u01(0,TWO_PI);
thrust::uniform_real_distribution<float> u02(0,PI);

// Two independent variable expressing the point
float theta, phi;
theta = (float)u01(rng);
phi = (float)u02(rng);

// Transform back to the real sphere coordinates
glm::vec3 point(cos(theta) * sin(phi), sin(theta) * sin(phi), cos(phi));
glm::vec3 randPoint = multiplyMV(sphere.transform, glm::vec4(point,1.0f));

return glm::vec3(0,0,0);
return randPoint;
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void runCuda(){
gammaSettings gamma;
gamma.applyGamma = true;
gamma.gamma = 1.0/2.2;
gamma.divisor = renderCam->iterations;
gamma.divisor = 1;//renderCam->iterations;
outputImage.setGammaSettings(gamma);
string filename = renderCam->imageName;
string s;
Expand Down Expand Up @@ -201,7 +201,7 @@ void runCuda(){
void display(){
runCuda();

string title = "565Raytracer | " + utilityCore::convertIntToString(iterations) + " Iterations";
string title = "565Raytracer | Qiong Wang " + utilityCore::convertIntToString(iterations) + " Iterations";
glutSetWindowTitle(title.c_str());

glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo);
Expand Down
Loading