Skip to content

Commit b332204

Browse files
committed
add single kernel PT for comparison
1 parent 4e44aa6 commit b332204

File tree

9 files changed

+230
-293
lines changed

9 files changed

+230
-293
lines changed

src/common.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "common.h"
22

3+
int Settings::traceDepth = 0;
34
int Settings::toneMapping = ToneMapping::ACES;
45
bool Settings::visualizeBVH = false;
5-
bool Settings::sortMaterial = false;
6+
bool Settings::sortMaterial = false;
7+
bool Settings::singleKernel = false;
8+
9+
bool State::camChanged = true;

src/common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111
#define BVH_DEBUG_VISUALIZATION false
1212
#define BVH_DISABLE false
1313

14+
#define ENABLE_GBUFFER false
15+
1416
struct ToneMapping {
1517
enum {
1618
None = 0, Filmic = 1, ACES = 2
1719
};
1820
};
1921

2022
struct Settings {
23+
static int traceDepth;
2124
static int toneMapping;
2225
static bool visualizeBVH;
2326
static bool sortMaterial;
27+
static bool singleKernel;
28+
};
29+
30+
struct State {
31+
static bool camChanged;
2432
};

src/intersections.h

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -14,130 +14,6 @@ __host__ __device__ inline Ray makeOffsetedRay(glm::vec3 ori, glm::vec3 dir) {
1414
return { ori + dir * 1e-5f, dir };
1515
}
1616

17-
// CHECKITOUT
18-
/**
19-
* Compute a point at parameter value `t` on ray `r`.
20-
* Falls slightly short so that it doesn't intersect the object it's hitting.
21-
*/
22-
__host__ __device__ static glm::vec3 getPointOnRay(Ray r, float dist) {
23-
return r.origin + (dist - .0001f) * glm::normalize(r.direction);
24-
}
25-
26-
/**
27-
* Multiplies a mat4 and a vec4 and returns a vec3 clipped from the vec4.
28-
*/
29-
__host__ __device__ static glm::vec3 multiplyMV(glm::mat4 m, glm::vec4 v) {
30-
return glm::vec3(m * v);
31-
}
32-
33-
// CHECKITOUT
34-
/**
35-
* Test intersection between a ray and a transformed cube. Untransformed,
36-
* the cube ranges from -0.5 to 0.5 in each axis and is centered at the origin.
37-
*
38-
* @param intersectionPoint Output parameter for point of intersection.
39-
* @param normal Output parameter for surface normal.
40-
* @param outside Output param for whether the ray came from outside.
41-
* @return Ray parameter `t` value. -1 if no intersection.
42-
*/
43-
__host__ __device__ static float boxIntersectionTest(Geom box, Ray r,
44-
glm::vec3 &intersectionPoint, glm::vec3 &normal, bool &outside) {
45-
Ray q;
46-
q.origin = multiplyMV(box.inverseTransform, glm::vec4(r.origin , 1.0f));
47-
q.direction = glm::normalize(multiplyMV(box.inverseTransform, glm::vec4(r.direction, 0.0f)));
48-
49-
float tmin = -1e38f;
50-
float tmax = 1e38f;
51-
glm::vec3 tmin_n;
52-
glm::vec3 tmax_n;
53-
for (int xyz = 0; xyz < 3; ++xyz) {
54-
float qdxyz = q.direction[xyz];
55-
/*if (glm::abs(qdxyz) > 0.00001f)*/ {
56-
float t1 = (-0.5f - q.origin[xyz]) / qdxyz;
57-
float t2 = (+0.5f - q.origin[xyz]) / qdxyz;
58-
float ta = glm::min(t1, t2);
59-
float tb = glm::max(t1, t2);
60-
glm::vec3 n;
61-
n[xyz] = t2 < t1 ? +1 : -1;
62-
if (ta > 0 && ta > tmin) {
63-
tmin = ta;
64-
tmin_n = n;
65-
}
66-
if (tb < tmax) {
67-
tmax = tb;
68-
tmax_n = n;
69-
}
70-
}
71-
}
72-
73-
if (tmax >= tmin && tmax > 0) {
74-
outside = true;
75-
if (tmin <= 0) {
76-
tmin = tmax;
77-
tmin_n = tmax_n;
78-
outside = false;
79-
}
80-
intersectionPoint = multiplyMV(box.transform, glm::vec4(getPointOnRay(q, tmin), 1.0f));
81-
normal = glm::normalize(multiplyMV(box.invTranspose, glm::vec4(tmin_n, 0.0f)));
82-
return glm::length(r.origin - intersectionPoint);
83-
}
84-
return -1;
85-
}
86-
87-
// CHECKITOUT
88-
/**
89-
* Test intersection between a ray and a transformed sphere. Untransformed,
90-
* the sphere always has radius 0.5 and is centered at the origin.
91-
*
92-
* @param intersectionPoint Output parameter for point of intersection.
93-
* @param normal Output parameter for surface normal.
94-
* @param outside Output param for whether the ray came from outside.
95-
* @return Ray parameter `t` value. -1 if no intersection.
96-
*/
97-
__host__ __device__ static float sphereIntersectionTest(Geom sphere, Ray r,
98-
glm::vec3 &intersectionPoint, glm::vec3 &normal, bool &outside) {
99-
float radius = .5;
100-
101-
glm::vec3 ro = multiplyMV(sphere.inverseTransform, glm::vec4(r.origin, 1.0f));
102-
glm::vec3 rd = glm::normalize(multiplyMV(sphere.inverseTransform, glm::vec4(r.direction, 0.0f)));
103-
104-
Ray rt;
105-
rt.origin = ro;
106-
rt.direction = rd;
107-
108-
float vDotDirection = glm::dot(rt.origin, rt.direction);
109-
float radicand = vDotDirection * vDotDirection - (glm::dot(rt.origin, rt.origin) - powf(radius, 2));
110-
if (radicand < 0) {
111-
return -1;
112-
}
113-
114-
float squareRoot = sqrt(radicand);
115-
float firstTerm = -vDotDirection;
116-
float t1 = firstTerm + squareRoot;
117-
float t2 = firstTerm - squareRoot;
118-
119-
float dist = 0;
120-
if (t1 < 0 && t2 < 0) {
121-
return -1;
122-
} else if (t1 > 0 && t2 > 0) {
123-
dist = std::min(t1, t2);
124-
outside = true;
125-
} else {
126-
dist = std::max(t1, t2);
127-
outside = false;
128-
}
129-
130-
glm::vec3 objspaceIntersection = getPointOnRay(rt, dist);
131-
132-
intersectionPoint = multiplyMV(sphere.transform, glm::vec4(objspaceIntersection, 1.f));
133-
normal = glm::normalize(multiplyMV(sphere.invTranspose, glm::vec4(objspaceIntersection, 0.f)));
134-
if (!outside) {
135-
normal = -normal;
136-
}
137-
138-
return glm::length(r.origin - intersectionPoint);
139-
}
140-
14117
__host__ __device__ static bool intersectTriangle(Ray ray, glm::vec3 v0, glm::vec3 v1, glm::vec3 v2,
14218
glm::vec2& bary, float& dist
14319
) {

src/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static bool middleMousePressed = false;
1313
static double lastX;
1414
static double lastY;
1515

16-
static bool camChanged = true;
1716
static float dtheta = 0, dphi = 0;
1817
static glm::vec3 cammove;
1918

@@ -185,7 +184,7 @@ void saveImage() {
185184
}
186185

187186
void runCuda() {
188-
if (camChanged) {
187+
if (State::camChanged) {
189188
iteration = 0;
190189
Camera& cam = renderState->camera;
191190
cameraPosition.x = zoom * sin(phi) * sin(theta);
@@ -201,7 +200,7 @@ void runCuda() {
201200

202201
cameraPosition += cam.lookAt;
203202
cam.position = cameraPosition;
204-
camChanged = false;
203+
State::camChanged = false;
205204
}
206205

207206
// Map OpenGL buffer object for writing from CUDA on a single GPU
@@ -246,7 +245,7 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
246245
Settings::toneMapping = (Settings::toneMapping + 1) % 3;
247246
break;
248247
case GLFW_KEY_SPACE:
249-
camChanged = true;
248+
State::camChanged = true;
250249
renderState = &scene->state;
251250
Camera& cam = renderState->camera;
252251
cam.lookAt = ogLookAt;
@@ -272,12 +271,12 @@ void mousePositionCallback(GLFWwindow* window, double xpos, double ypos) {
272271
phi -= (xpos - lastX) / width;
273272
theta -= (ypos - lastY) / height;
274273
theta = std::fmax(0.001f, std::fmin(theta, Pi));
275-
camChanged = true;
274+
State::camChanged = true;
276275
}
277276
else if (rightMousePressed) {
278277
zoom += (ypos - lastY) / height;
279278
zoom = std::fmax(0.1f, zoom);
280-
camChanged = true;
279+
State::camChanged = true;
281280
}
282281
else if (middleMousePressed) {
283282
renderState = &scene->state;
@@ -291,7 +290,7 @@ void mousePositionCallback(GLFWwindow* window, double xpos, double ypos) {
291290

292291
cam.lookAt -= (float)(xpos - lastX) * right * 0.01f;
293292
cam.lookAt += (float)(ypos - lastY) * forward * 0.01f;
294-
camChanged = true;
293+
State::camChanged = true;
295294
}
296295
lastX = xpos;
297296
lastY = ypos;

0 commit comments

Comments
 (0)