Skip to content

Project 1 Submission #12

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

Open
wants to merge 5 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
2 changes: 1 addition & 1 deletion PROJ1_WIN/565Raytracer/565Raytracer.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>scene=../../scenes/sampleScene.txt</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>scene=../../scenes/shadow.txt</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release (v5.5)|Win32'">
Expand Down
347 changes: 42 additions & 305 deletions README.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions scenes/cube.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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

CAMERA
RES 800 800
FOVY 53.1301024
ITERATIONS 100
FILE test.bmp
frame 0
EYE 0.5 0.5 1
VIEW 0 0 -1
UP 0 1 0

OBJECT 0
cube
material 0
frame 0
TRANS 0.5 0.5 0
ROTAT 45 45 0
SCALE 0.2 0.2 0.2
49 changes: 49 additions & 0 deletions scenes/cube_sphere.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MATERIAL 0 //red diffuse
RGB 1 0 0
SPECEX 0
SPECRGB 1 1 1
REFL 0
REFR 0
REFRIOR 0
SCATTER 0
ABSCOEFF 0 0 0
RSCTCOEFF 0
EMITTANCE 0

MATERIAL 1 //green specular
RGB 0 1 0
SPECEX 15
SPECRGB 1 1 1
REFL 0
REFR 0
REFRIOR 0
SCATTER 0
ABSCOEFF 0 0 0
RSCTCOEFF 0
EMITTANCE 0

CAMERA
RES 800 800
FOVY 53.1301024
ITERATIONS 100
FILE test.bmp
frame 0
EYE 0.5 0.5 1
VIEW 0 0 -1
UP 0 1 0

OBJECT 0
sphere
material 1
frame 0
TRANS 0.25 0.5 0
ROTAT 0 0 0
SCALE 0.2 0.2 0.2

OBJECT 1
cube
material 0
frame 0
TRANS 0.75 0.5 0
ROTAT 45 45 0
SCALE 0.2 0.2 0.2
49 changes: 49 additions & 0 deletions scenes/shadow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
MATERIAL 0 //green diffuse
RGB 0 1 0
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 1 0 0
SPECEX 0
SPECRGB 1 1 1
REFL 0
REFR 0
REFRIOR 0
SCATTER 0
ABSCOEFF 0 0 0
RSCTCOEFF 0
EMITTANCE 0

CAMERA
RES 800 800
FOVY 53.1301024
ITERATIONS 50
FILE test.bmp
frame 0
EYE 0.5 0.5 1
VIEW 0 0 -1
UP 0 1 0

OBJECT 0
sphere
material 0
frame 0
TRANS 0.5 0.4 -0.5
ROTAT 0 0 0
SCALE 0.2 0.2 0.2

OBJECT 1
cube
material 1
frame 0
TRANS 0.5 0 -0.5
ROTAT 0 0 0
SCALE 1 0.05 1
29 changes: 29 additions & 0 deletions scenes/sphere.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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

CAMERA
RES 800 800
FOVY 53.1301024
ITERATIONS 100
FILE test.bmp
frame 0
EYE 0.5 0.5 1
VIEW 0 0 -1
UP 0 1 0

OBJECT 0
sphere
material 0
frame 0
TRANS 0.5 0.5 0
ROTAT 0 0 0
SCALE 0.1 0.1 0.1
Binary file added screenshots/1.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 screenshots/2.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 screenshots/3.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 screenshots/4.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 screenshots/5.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 screenshots/6.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 screenshots/7.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 screenshots/8.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 screenshots/9.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 screenshots/Thumbs.db
Binary file not shown.
109 changes: 101 additions & 8 deletions src/intersections.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "cudaMat4.h"
#include "glm/glm.hpp"
#include "utilities.h"
#include "float.h"
#include <thrust/random.h>
#include <stdlib.h>

//Some forward declarations
__host__ __device__ glm::vec3 getPointOnRay(ray r, float t);
Expand Down Expand Up @@ -68,11 +70,81 @@ __host__ __device__ glm::vec3 getSignOfRay(ray r){
return glm::vec3((int)(inv_direction.x < 0), (int)(inv_direction.y < 0), (int)(inv_direction.z < 0));
}

//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){
// HW 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)
{
// Convert ray from World to object coordinate system (unit cube centered at 0,0,0)
ray rt;
rt.origin = multiplyMV(box.inverseTransform, glm::vec4(r.origin,1.0f));
rt.direction = glm::normalize(multiplyMV(box.inverseTransform, glm::vec4(r.direction,0.0f)));

return -1;
// Compute ray-box intersection distance.
// Implementation from http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm

float t; // Distance from ray origin to intersection point in object's coods
float t_far = FLT_MAX;
float t_near = -t_far;

float origin[] = {rt.origin.x, rt.origin.y, rt.origin.z};
float direction[] = {rt.direction.x, rt.direction.y, rt.direction.z};
for (int i=0; i<3; ++i)
{
// Compute the intersection distance of the planes
float t1 = (-0.5f - origin[i]) / direction[i];
float t2 = (0.5f - origin[i]) / direction[i];

// Swap t1 and t2 such that t1 < t2
if (t1 > t2)
{
float temp = t2;
t2 = t1;
t1 = temp;
}

if (t1 > t_near) t_near = t1;
if (t2 < t_far) t_far = t2;
if (t_near > t_far || t_far < 0.0f) return -1.0f;
}

t = ((t_near < 0.0f) ? t_far : t_near);

// Compute normal (in object coordinate system)
glm::vec3 hit_point(rt.origin + rt.direction * t);
float EPS = 0.0001f; // EPSILON in utilities.h results in noise (too small)
if (abs(hit_point.x - 0.5f) < EPS)
{
normal = glm::vec3(1.0f, 0.0f, 0.0f);
}
else if (abs(hit_point.x + 0.5f) < EPS)
{
normal = glm::vec3(-1.0f, 0.0f, 0.0f);
}
else if (abs(hit_point.y - 0.5f) < EPS)
{
normal = glm::vec3(0.0f, 1.0f, 0.0f);
}
else if (abs(hit_point.y + 0.5f) < EPS)
{
normal = glm::vec3(0.0f, -1.0f, 0.0f);
}
else if (abs(hit_point.z - 0.5f) < EPS)
{
normal = glm::vec3(0.0f, 0.0f, 1.0f);
}
else
{
normal = glm::vec3(0.0f, 0.0f, -1.0f);
}

// Convert back to world coordinate system
glm::vec3 realIntersectionPoint = multiplyMV(box.transform, glm::vec4(getPointOnRay(rt, t), 1.0f));
glm::vec3 realNormal = multiplyMV(box.transform, glm::vec4(normal, 1.0f));

intersectionPoint = realIntersectionPoint;
normal = glm::normalize(realNormal);

return glm::length(r.origin - realIntersectionPoint);
}

//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 @@ -173,11 +245,32 @@ __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){
// HW TODO: IMPLEMENT THIS FUNCTION
// Generates a random point on a given sphere
__host__ __device__ glm::vec3 getRandomPointOnSphere(staticGeom sphere, float randomSeed)
{
thrust::default_random_engine rng(hash(randomSeed));
thrust::uniform_real_distribution<float> u01(0.0f, 1.0f);

// Sphere point picking:
// http://mathworld.wolfram.com/SpherePointPicking.html

float u = (float) u01(rng);
float v = (float) u01(rng);

float theta = TWO_PI * u;
float phi = acos( 2.0f * v - 1.0f );

// Convert from spherical to Cartesian coordinates.
float r = 0.5f; // Radius
float x = r * sin(phi) * cos(theta);
float y = r * sin(phi) * sin(theta);
float z = r * cos(phi);

return glm::vec3(0,0,0);
// Convert to World coordinate system.
glm::vec3 randPoint = multiplyMV(sphere.transform, glm::vec4(x, y, z, 1.0f));

return randPoint;
}

#endif
Expand Down
Loading