Skip to content

Commit

Permalink
Pass lightRay as a copy instead of reference
Browse files Browse the repository at this point in the history
It just gets dereferenced right away anyway.
  • Loading branch information
vkoskiv committed Nov 3, 2023
1 parent 65d90a6 commit 32162ee
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/renderer/pathtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ static inline struct hitRecord getClosestIsect(struct lightRay *incidentRay, con
return isect;
}

struct color path_trace(const struct lightRay *incidentRay, const struct world *scene, int max_bounces, sampler *sampler) {
struct color path_trace(struct lightRay incident, const struct world *scene, int max_bounces, sampler *sampler) {
struct color path_weight = g_white_color;
struct color path_radiance = g_black_color; // Final path contribution "color"
struct lightRay currentRay = *incidentRay;
struct lightRay currentRay = incident;

for (int bounce = 0; bounce <= max_bounces; ++bounce) {
const struct hitRecord isect = getClosestIsect(&currentRay, scene, sampler);
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/pathtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@

struct world;

/// Iterative path tracer.
/// @param incidentRay View ray to be casted into the scene
/// @param scene Scene to cast the ray into
/// @param maxDepth Maximum depth of path
/// @param rng A random number generator. One per execution thread.
struct color path_trace(const struct lightRay *incidentRay, const struct world *scene, int max_bounces, sampler *sampler);
struct color path_trace(struct lightRay incident, const struct world *scene, int max_bounces, sampler *sampler);
6 changes: 2 additions & 4 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ void *renderThreadInteractive(void *arg) {
initSampler(sampler, SAMPLING_STRATEGY, r->state.finishedPasses, r->prefs.sampleCount, pixIdx);

struct color output = textureGetPixel(r->state.renderBuffer, x, y, false);
struct lightRay incidentRay = cam_get_ray(cam, x, y, sampler);
struct color sample = path_trace(&incidentRay, r->scene, r->prefs.bounces, sampler);
struct color sample = path_trace(cam_get_ray(cam, x, y, sampler), r->scene, r->prefs.bounces, sampler);

nan_clamp(&sample, &output);

Expand Down Expand Up @@ -303,8 +302,7 @@ void *renderThread(void *arg) {
initSampler(sampler, SAMPLING_STRATEGY, threadState->completedSamples - 1, r->prefs.sampleCount, pixIdx);

struct color output = textureGetPixel(r->state.renderBuffer, x, y, false);
struct lightRay incidentRay = cam_get_ray(cam, x, y, sampler);
struct color sample = path_trace(&incidentRay, r->scene, r->prefs.bounces, sampler);
struct color sample = path_trace(cam_get_ray(cam, x, y, sampler), r->scene, r->prefs.bounces, sampler);

// Clamp out fireflies - This is probably not a good way to do that.
nan_clamp(&sample, &output);
Expand Down
3 changes: 1 addition & 2 deletions src/utils/protocol/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ static void *workerThread(void *arg) {
initSampler(sampler, SAMPLING_STRATEGY, thread->completedSamples - 1, r->prefs.sampleCount, pixIdx);

struct color output = textureGetPixel(r->state.renderBuffer, x, y, false);
struct lightRay incidentRay = cam_get_ray(cam, x, y, sampler);
struct color sample = path_trace(&incidentRay, r->scene, r->prefs.bounces, sampler);
struct color sample = path_trace(cam_get_ray(cam, x, y, sampler), r->scene, r->prefs.bounces, sampler);

nan_clamp(&sample, &output);

Expand Down

0 comments on commit 32162ee

Please sign in to comment.