Skip to content

Commit 635037d

Browse files
author
Luc Forget
committed
Address review comments
1 parent b92d9c2 commit 635037d

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ This creates the executable.
9191

9292
Now you can run the path tracer with:
9393
```sh
94-
time RT_SYCL/sycl-rt >! result.ppm
94+
time ./sycl-rt 800 480 50 100
9595
```
96-
This results in the image ``result.ppm`` produced by the path tracer.
96+
This results in the image ``out.png`` produced by the path tracer.
97+
98+
Parameters to the executable are
99+
100+
+ The output image width (here 800)
101+
+ The output image height (here 480)
102+
+ The maximum bouncing depth of the ray (here 50)
103+
+ The number of samples per pixel (here 100)
97104

98105

99106
## Bibliography

include/rtweekend.hpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ inline real_t degrees_to_radians(real_t degrees) {
3838
return degrees * pi / 180.0f;
3939
}
4040

41-
uint32_t toseed(vec const& val) {
42-
uint32_t x, y, z;
43-
std::memcpy(&x, &val.x(), sizeof(uint32_t));
44-
std::memcpy(&y, &val.y(), sizeof(uint32_t));
45-
std::memcpy(&z, &val.z(), sizeof(uint32_t));
46-
return x * x * y * y * z * z;
47-
}
41+
/**
42+
@brief hash two vector using coordinates low bits
4843
44+
@param val1 first vector
45+
@param val2 second vector
46+
@return uint32_t
47+
*/
4948
uint32_t toseed(vec const& val1, vec const& val2) {
5049
uint32_t x1, y1, z1, x2, y2, z2;
5150
std::memcpy(&x1, &val1.x(), sizeof(uint32_t));
@@ -55,12 +54,12 @@ uint32_t toseed(vec const& val1, vec const& val2) {
5554
std::memcpy(&y2, &val2.y(), sizeof(uint32_t));
5655
std::memcpy(&z2, &val2.z(), sizeof(uint32_t));
5756
uint32_t shifted1 = x1 << 26;
58-
uint32_t shifted2 = (x2 & 63) << 21;
57+
uint32_t shifted2 = (x2 & 31) << 21;
5958
uint32_t shifted3 = (y1 & 63) << 15;
60-
uint32_t shifted4 = (y2 & 63) << 10;
61-
uint32_t shifted5 = (z1 & 63) << 5;
62-
uint32_t shifted6 = (z2 & 63);
63-
return shifted1 ^ shifted2 ^ shifted3 ^ shifted4 ^ shifted5 ^ shifted6;
59+
uint32_t shifted4 = (y2 & 31) << 10;
60+
uint32_t shifted5 = (z1 & 31) << 5;
61+
uint32_t shifted6 = (z2 & 31);
62+
return shifted1 | shifted2 | shifted3 | shifted4 | shifted5 | shifted6;
6463
}
6564

6665
class LocalPseudoRNG {

src/main.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include "sycl.hpp"
2+
#include "xorshift.hpp"
23
#include <algorithm>
34
#include <chrono>
45
#include <cstdint>
56
#include <ctime>
67
#include <iostream>
78
#include <iterator>
89
#include <math.h>
10+
#include <string>
911
#include <thread>
1012
#include <vector>
1113

@@ -59,8 +61,9 @@ void save_image_png(int width, int height, sycl::buffer<color, 2>& fb) {
5961
}
6062

6163
int main(int argc, char* argv[]) {
62-
if (argc != 5) {
63-
std::cerr << "Usage: sycl-rt OUT_WIDTH OUT_HEIGHT DEPTH SAMPLES"
64+
if (argc < 5 || argc > 7) {
65+
std::cerr << "Usage: sycl-rt OUT_WIDTH OUT_HEIGHT DEPTH SAMPLES "
66+
"[SPHERE_INC [RAND_SEED]]"
6467
<< std::endl;
6568
return -1;
6669
}
@@ -69,6 +72,14 @@ int main(int argc, char* argv[]) {
6972
auto height = std::stoi({ argv[2] });
7073
auto depth = std::stoi({ argv[3] });
7174
auto samples = std::stoi({ argv[4] });
75+
int sphere_inc = 1;
76+
if (argc >= 6)
77+
sphere_inc = std::stoi({ argv[5] });
78+
79+
auto rand_seed = xorshift<>::initial_state;
80+
81+
if (argc >= 7)
82+
rand_seed = std::stoi({ argv[6] });
7283

7384
/// Graphical objects
7485
std::vector<hittable_t> hittables;
@@ -80,10 +91,10 @@ int main(int argc, char* argv[]) {
8091
hittables.emplace_back(sphere(point { 0, -1000, 0 }, 1000, m));
8192
t = checker_texture(color { 0.9f, 0.9f, 0.9f }, color { 0.4f, 0.2f, 0.1f });
8293

83-
LocalPseudoRNG rng{static_cast<uint32_t>(std::time(nullptr))};
94+
LocalPseudoRNG rng{rand_seed};
8495

85-
for (int a = -11; a < 11; a++) {
86-
for (int b = -11; b < 11; b++) {
96+
for (int a = -11; a < 11; a += sphere_inc) {
97+
for (int b = -11; b < 11; b += sphere_inc) {
8798
auto choose_mat = rng.real();
8899
// Spheres are placed at a point randomly displaced from a,b
89100
point center(a + 0.9f * rng.real(), 0.2f, b + 0.9f * rng.real());

0 commit comments

Comments
 (0)