Call rendering function directly.
This commit is contained in:
parent
d2ce61e208
commit
3d051f6c5b
73
wtracer.cpp
73
wtracer.cpp
@ -84,15 +84,6 @@ Hittable_list setup_random_scene(const int sph_i) {
|
||||
return world;
|
||||
}
|
||||
|
||||
struct render_params {
|
||||
int image_width;
|
||||
int image_height;
|
||||
int samples_per_pixel;
|
||||
int max_depth;
|
||||
Hittable_list& world;
|
||||
Camera& cam;
|
||||
};
|
||||
|
||||
struct render_tile {
|
||||
int start_x;
|
||||
int start_y;
|
||||
@ -100,41 +91,6 @@ struct render_tile {
|
||||
int end_y;
|
||||
};
|
||||
|
||||
void split_line(const int& line_length, int& start, int& end) {
|
||||
#ifdef _OPENMP
|
||||
const int line_length_thread = static_cast<int>(line_length/omp_get_num_threads());
|
||||
start = omp_get_thread_num() * line_length_thread;
|
||||
end = std::min((omp_get_thread_num()+1) * line_length_thread, line_length);
|
||||
#else
|
||||
start = 0;
|
||||
end = line_length;
|
||||
#endif
|
||||
}
|
||||
|
||||
void render(boost::lockfree::queue<render_tile>& queue,
|
||||
std::atomic<int>& queue_counter,
|
||||
const render_params& params, std::vector<Color>& image) {
|
||||
render_tile rt;
|
||||
while (queue.pop(rt)) {
|
||||
--queue_counter;
|
||||
int qc = queue_counter;
|
||||
printf("\rTiles remaining: %4d", qc);
|
||||
std::cout << std::flush;
|
||||
for (int i = rt.start_x; i<rt.end_x; ++i) {
|
||||
for (int j = rt.start_y; j<rt.end_y; ++j) {
|
||||
Color pixel_color(0, 0, 0);
|
||||
for (int s = 0; s<params.samples_per_pixel; ++s) {
|
||||
auto u = double(j + random_double(-0.5, 0.5)) / (params.image_width - 1);
|
||||
auto v = double(i + random_double(-0.5, 0.5)) / (params.image_height - 1);
|
||||
Ray r = params.cam.get_ray(u, v);
|
||||
pixel_color += ray_color(r, params.world, params.max_depth);
|
||||
}
|
||||
image[i*params.image_width+j] = pixel_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
const auto aspect_ratio = 16.0 / 9.0;
|
||||
//const int image_width = 1920;
|
||||
@ -165,15 +121,6 @@ int main() {
|
||||
|
||||
Camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
|
||||
|
||||
render_params params = {
|
||||
image_width,
|
||||
image_height,
|
||||
samples_per_pixel,
|
||||
max_depth,
|
||||
world,
|
||||
cam,
|
||||
};
|
||||
|
||||
std::atomic<int> queue_counter;
|
||||
boost::lockfree::queue<render_tile> queue(0);
|
||||
|
||||
@ -194,7 +141,25 @@ int main() {
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
render(queue, queue_counter, params, image);
|
||||
render_tile rt;
|
||||
while (queue.pop(rt)) {
|
||||
--queue_counter;
|
||||
int qc = queue_counter;
|
||||
printf("\rTiles remaining: %4d", qc);
|
||||
std::cout << std::flush;
|
||||
for (int i = rt.start_x; i<rt.end_x; ++i) {
|
||||
for (int j = rt.start_y; j<rt.end_y; ++j) {
|
||||
Color pixel_color(0, 0, 0);
|
||||
for (int s = 0; s<samples_per_pixel; ++s) {
|
||||
auto u = double(j + random_double(-0.5, 0.5)) / (image_width - 1);
|
||||
auto v = double(i + random_double(-0.5, 0.5)) / (image_height - 1);
|
||||
Ray r = cam.get_ray(u, v);
|
||||
pixel_color += ray_color(r, world, max_depth);
|
||||
}
|
||||
image[i*image_width+j] = pixel_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "\nAssembling image.\n";
|
||||
|
Loading…
Reference in New Issue
Block a user