2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "device/device.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/camera.h"
|
|
|
|
|
#include "scene/integrator.h"
|
|
|
|
|
#include "scene/scene.h"
|
|
|
|
|
#include "session/buffers.h"
|
|
|
|
|
#include "session/session.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/args.h"
|
|
|
|
|
#include "util/foreach.h"
|
|
|
|
|
#include "util/function.h"
|
|
|
|
|
#include "util/image.h"
|
|
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/path.h"
|
|
|
|
|
#include "util/progress.h"
|
|
|
|
|
#include "util/string.h"
|
|
|
|
|
#include "util/time.h"
|
|
|
|
|
#include "util/transform.h"
|
|
|
|
|
#include "util/unique_ptr.h"
|
|
|
|
|
#include "util/version.h"
|
2013-08-30 17:34:27 +00:00
|
|
|
|
2022-04-17 07:01:13 +02:00
|
|
|
#ifdef WITH_USD
|
|
|
|
|
# include "hydra/file_reader.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-30 16:51:03 +02:00
|
|
|
#include "app/cycles_xml.h"
|
|
|
|
|
#include "app/oiio_output_driver.h"
|
|
|
|
|
|
2013-08-30 17:34:27 +00:00
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
2021-09-17 15:15:14 +02:00
|
|
|
# include "opengl/display_driver.h"
|
|
|
|
|
# include "opengl/window.h"
|
2013-08-30 17:34:27 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
struct Options {
|
|
|
|
|
Session *session;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
string filepath;
|
|
|
|
|
int width, height;
|
|
|
|
|
SceneParams scene_params;
|
|
|
|
|
SessionParams session_params;
|
2014-02-14 21:40:51 +01:00
|
|
|
bool quiet;
|
|
|
|
|
bool show_help, interactive, pause;
|
2021-09-24 03:52:25 +02:00
|
|
|
string output_filepath;
|
2021-09-30 16:51:03 +02:00
|
|
|
string output_pass;
|
2011-04-27 11:58:34 +00:00
|
|
|
} options;
|
|
|
|
|
|
|
|
|
|
static void session_print(const string &str)
|
|
|
|
|
{
|
|
|
|
|
/* print with carriage return to overwrite previous */
|
|
|
|
|
printf("\r%s", str.c_str());
|
|
|
|
|
|
|
|
|
|
/* add spaces to overwrite longer previous print */
|
|
|
|
|
static int maxlen = 0;
|
|
|
|
|
int len = str.size();
|
|
|
|
|
maxlen = max(len, maxlen);
|
|
|
|
|
|
|
|
|
|
for (int i = len; i < maxlen; i++)
|
|
|
|
|
printf(" ");
|
|
|
|
|
|
|
|
|
|
/* flush because we don't write an end of line */
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void session_print_status()
|
|
|
|
|
{
|
|
|
|
|
string status, substatus;
|
|
|
|
|
|
|
|
|
|
/* get status */
|
2022-01-05 20:03:16 +01:00
|
|
|
double progress = options.session->progress.get_progress();
|
2011-04-27 11:58:34 +00:00
|
|
|
options.session->progress.get_status(status, substatus);
|
|
|
|
|
|
|
|
|
|
if (substatus != "")
|
|
|
|
|
status += ": " + substatus;
|
|
|
|
|
|
|
|
|
|
/* print status */
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
status = string_printf("Progress %05.2f %s", (double)progress * 100, status.c_str());
|
2011-04-27 11:58:34 +00:00
|
|
|
session_print(status);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:51:43 +00:00
|
|
|
static BufferParams &session_buffer_params()
|
2011-12-20 12:25:37 +00:00
|
|
|
{
|
2011-12-21 20:51:43 +00:00
|
|
|
static BufferParams buffer_params;
|
2011-12-20 12:25:37 +00:00
|
|
|
buffer_params.width = options.width;
|
|
|
|
|
buffer_params.height = options.height;
|
|
|
|
|
buffer_params.full_width = options.width;
|
|
|
|
|
buffer_params.full_height = options.height;
|
|
|
|
|
|
|
|
|
|
return buffer_params;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 18:40:31 +01:00
|
|
|
static void scene_init()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
options.scene = options.session->scene;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-17 07:01:13 +02:00
|
|
|
/* Read XML or USD */
|
|
|
|
|
#ifdef WITH_USD
|
|
|
|
|
if (!string_endswith(string_to_lower(options.filepath), ".xml")) {
|
|
|
|
|
HD_CYCLES_NS::HdCyclesFileReader::read(options.session, options.filepath.c_str());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
xml_read_file(options.scene, options.filepath.c_str());
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 18:40:31 +01:00
|
|
|
/* Camera width/height override? */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (!(options.width == 0 || options.height == 0)) {
|
2021-01-18 07:43:42 +01:00
|
|
|
options.scene->camera->set_full_width(options.width);
|
|
|
|
|
options.scene->camera->set_full_height(options.height);
|
2014-02-14 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2021-01-18 07:43:42 +01:00
|
|
|
options.width = options.scene->camera->get_full_width();
|
|
|
|
|
options.height = options.scene->camera->get_full_height();
|
2011-12-25 13:34:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 18:40:31 +01:00
|
|
|
/* Calculate Viewplane */
|
|
|
|
|
options.scene->camera->compute_auto_viewplane();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 05:08:26 +02:00
|
|
|
static void session_init()
|
|
|
|
|
{
|
2021-09-30 16:51:03 +02:00
|
|
|
options.output_pass = "combined";
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
options.session = new Session(options.session_params, options.scene_params);
|
2017-10-20 05:08:26 +02:00
|
|
|
|
2021-09-17 15:15:14 +02:00
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
|
|
|
|
if (!options.session_params.background) {
|
|
|
|
|
options.session->set_display_driver(make_unique<OpenGLDisplayDriver>(
|
|
|
|
|
window_opengl_context_enable, window_opengl_context_disable));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-04-04 14:16:00 +02:00
|
|
|
|
|
|
|
|
if (!options.output_filepath.empty()) {
|
2021-09-30 16:51:03 +02:00
|
|
|
options.session->set_output_driver(make_unique<OIIOOutputDriver>(
|
|
|
|
|
options.output_filepath, options.output_pass, session_print));
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-20 05:08:26 +02:00
|
|
|
if (options.session_params.background && !options.quiet)
|
|
|
|
|
options.session->progress.set_update_callback(function_bind(&session_print_status));
|
|
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
|
|
|
|
else
|
2021-09-17 15:15:14 +02:00
|
|
|
options.session->progress.set_update_callback(function_bind(&window_redraw));
|
2017-10-20 05:08:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* load scene */
|
|
|
|
|
scene_init();
|
2017-10-31 12:46:38 +01:00
|
|
|
|
2021-09-30 16:51:03 +02:00
|
|
|
/* add pass for output. */
|
|
|
|
|
Pass *pass = options.scene->create_node<Pass>();
|
|
|
|
|
pass->set_name(ustring(options.output_pass.c_str()));
|
|
|
|
|
pass->set_type(PASS_COMBINED);
|
|
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2017-10-31 12:46:38 +01:00
|
|
|
options.session->start();
|
2017-10-20 05:08:26 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static void session_exit()
|
|
|
|
|
{
|
|
|
|
|
if (options.session) {
|
|
|
|
|
delete options.session;
|
|
|
|
|
options.session = NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (options.session_params.background && !options.quiet) {
|
|
|
|
|
session_print("Finished Rendering.");
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-30 17:34:27 +00:00
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
2011-04-27 11:58:34 +00:00
|
|
|
static void display_info(Progress &progress)
|
|
|
|
|
{
|
|
|
|
|
static double latency = 0.0;
|
|
|
|
|
static double last = 0;
|
|
|
|
|
double elapsed = time_dt();
|
2014-02-14 13:40:29 +01:00
|
|
|
string str, interactive;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
latency = (elapsed - last);
|
|
|
|
|
last = elapsed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
double total_time, sample_time;
|
2011-04-27 11:58:34 +00:00
|
|
|
string status, substatus;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
progress.get_time(total_time, sample_time);
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.get_status(status, substatus);
|
2022-01-05 20:03:16 +01:00
|
|
|
double progress_val = progress.get_progress();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (substatus != "")
|
|
|
|
|
status += ": " + substatus;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 13:40:29 +01:00
|
|
|
interactive = options.interactive ? "On" : "Off";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-04 03:49:56 +10:00
|
|
|
str = string_printf(
|
|
|
|
|
"%s"
|
|
|
|
|
" Time: %.2f"
|
|
|
|
|
" Latency: %.4f"
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
" Progress: %05.2f"
|
2014-05-04 03:49:56 +10:00
|
|
|
" Average: %.4f"
|
|
|
|
|
" Interactive: %s",
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
status.c_str(),
|
|
|
|
|
total_time,
|
|
|
|
|
latency,
|
|
|
|
|
(double)progress_val * 100,
|
|
|
|
|
sample_time,
|
|
|
|
|
interactive.c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-17 15:15:14 +02:00
|
|
|
window_display_info(str.c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-24 12:57:19 +01:00
|
|
|
if (options.show_help)
|
2021-09-17 15:15:14 +02:00
|
|
|
window_display_help();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void display()
|
|
|
|
|
{
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->draw();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
display_info(options.session->progress);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 01:15:07 +01:00
|
|
|
static void motion(int x, int y, int button)
|
|
|
|
|
{
|
2014-02-14 13:40:29 +01:00
|
|
|
if (options.interactive) {
|
2021-01-18 07:43:42 +01:00
|
|
|
Transform matrix = options.session->scene->camera->get_matrix();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 13:40:29 +01:00
|
|
|
/* Translate */
|
|
|
|
|
if (button == 0) {
|
2014-02-14 13:56:23 +01:00
|
|
|
float3 translate = make_float3(x * 0.01f, -(y * 0.01f), 0.0f);
|
2014-02-14 13:40:29 +01:00
|
|
|
matrix = matrix * transform_translate(translate);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 13:40:29 +01:00
|
|
|
/* Rotate */
|
|
|
|
|
else if (button == 2) {
|
2014-05-05 02:19:08 +10:00
|
|
|
float4 r1 = make_float4((float)x * 0.1f, 0.0f, 1.0f, 0.0f);
|
2014-05-04 03:15:20 +10:00
|
|
|
matrix = matrix * transform_rotate(DEG2RADF(r1.x), make_float3(r1.y, r1.z, r1.w));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-04 03:15:20 +10:00
|
|
|
float4 r2 = make_float4(y * 0.1f, 1.0f, 0.0f, 0.0f);
|
|
|
|
|
matrix = matrix * transform_rotate(DEG2RADF(r2.x), make_float3(r2.y, r2.z, r2.w));
|
2014-02-14 13:40:29 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 13:40:29 +01:00
|
|
|
/* Update and Reset */
|
2021-01-18 07:43:42 +01:00
|
|
|
options.session->scene->camera->set_matrix(matrix);
|
|
|
|
|
options.session->scene->camera->need_flags_update = true;
|
2014-02-14 13:40:29 +01:00
|
|
|
options.session->scene->camera->need_device_update = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2014-02-14 01:15:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static void resize(int width, int height)
|
|
|
|
|
{
|
2012-06-09 18:56:12 +00:00
|
|
|
options.width = width;
|
|
|
|
|
options.height = height;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 18:40:31 +01:00
|
|
|
if (options.session) {
|
|
|
|
|
/* Update camera */
|
2021-01-18 07:43:42 +01:00
|
|
|
options.session->scene->camera->set_full_width(options.width);
|
|
|
|
|
options.session->scene->camera->set_full_height(options.height);
|
2014-02-14 18:40:31 +01:00
|
|
|
options.session->scene->camera->compute_auto_viewplane();
|
2021-01-18 07:43:42 +01:00
|
|
|
options.session->scene->camera->need_flags_update = true;
|
2014-02-14 18:40:31 +01:00
|
|
|
options.session->scene->camera->need_device_update = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2014-02-14 18:40:31 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-21 16:40:34 +00:00
|
|
|
static void keyboard(unsigned char key)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Toggle help */
|
|
|
|
|
if (key == 'h')
|
2014-01-24 12:57:19 +01:00
|
|
|
options.show_help = !(options.show_help);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Reset */
|
|
|
|
|
else if (key == 'r')
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Cancel */
|
2011-04-27 11:58:34 +00:00
|
|
|
else if (key == 27) // escape
|
2013-10-26 01:06:19 +00:00
|
|
|
options.session->progress.set_cancel("Canceled");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Pause */
|
|
|
|
|
else if (key == 'p') {
|
|
|
|
|
options.pause = !options.pause;
|
|
|
|
|
options.session->set_pause(options.pause);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Interactive Mode */
|
|
|
|
|
else if (key == 'i')
|
|
|
|
|
options.interactive = !(options.interactive);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-19 12:47:38 +02:00
|
|
|
/* Navigation */
|
2014-02-14 21:40:51 +01:00
|
|
|
else if (options.interactive && (key == 'w' || key == 'a' || key == 's' || key == 'd')) {
|
2021-01-18 07:43:42 +01:00
|
|
|
Transform matrix = options.session->scene->camera->get_matrix();
|
2014-02-14 21:40:51 +01:00
|
|
|
float3 translate;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
if (key == 'w')
|
|
|
|
|
translate = make_float3(0.0f, 0.0f, 0.1f);
|
|
|
|
|
else if (key == 's')
|
|
|
|
|
translate = make_float3(0.0f, 0.0f, -0.1f);
|
|
|
|
|
else if (key == 'a')
|
|
|
|
|
translate = make_float3(-0.1f, 0.0f, 0.0f);
|
|
|
|
|
else if (key == 'd')
|
|
|
|
|
translate = make_float3(0.1f, 0.0f, 0.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
matrix = matrix * transform_translate(translate);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-14 21:40:51 +01:00
|
|
|
/* Update and Reset */
|
2021-01-18 07:43:42 +01:00
|
|
|
options.session->scene->camera->set_matrix(matrix);
|
|
|
|
|
options.session->scene->camera->need_flags_update = true;
|
2014-02-14 21:40:51 +01:00
|
|
|
options.session->scene->camera->need_device_update = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2014-02-14 21:40:51 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-19 12:47:38 +02:00
|
|
|
/* Set Max Bounces */
|
|
|
|
|
else if (options.interactive && (key == '0' || key == '1' || key == '2' || key == '3')) {
|
|
|
|
|
int bounce;
|
|
|
|
|
switch (key) {
|
|
|
|
|
case '0':
|
|
|
|
|
bounce = 0;
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
bounce = 1;
|
|
|
|
|
break;
|
|
|
|
|
case '2':
|
|
|
|
|
bounce = 2;
|
|
|
|
|
break;
|
|
|
|
|
case '3':
|
|
|
|
|
bounce = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bounce = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-18 07:43:42 +01:00
|
|
|
options.session->scene->integrator->set_max_bounce(bounce);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session->reset(options.session_params, session_buffer_params());
|
2015-05-19 12:47:38 +02:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-08-30 17:34:27 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
static int files_parse(int argc, const char *argv[])
|
|
|
|
|
{
|
|
|
|
|
if (argc > 0)
|
|
|
|
|
options.filepath = argv[0];
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void options_parse(int argc, const char **argv)
|
|
|
|
|
{
|
2021-09-24 03:52:25 +02:00
|
|
|
options.width = 1024;
|
|
|
|
|
options.height = 512;
|
2011-04-28 13:47:27 +00:00
|
|
|
options.filepath = "";
|
2011-04-27 11:58:34 +00:00
|
|
|
options.session = NULL;
|
|
|
|
|
options.quiet = false;
|
2021-09-24 03:52:25 +02:00
|
|
|
options.session_params.use_auto_tile = false;
|
|
|
|
|
options.session_params.tile_size = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
/* device names */
|
|
|
|
|
string device_names = "";
|
2016-11-12 15:41:42 +01:00
|
|
|
string devicename = "CPU";
|
2012-01-04 18:06:32 +00:00
|
|
|
bool list = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
/* List devices for which support is compiled in. */
|
|
|
|
|
vector<DeviceType> types = Device::available_types();
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (DeviceType type, types) {
|
2012-01-04 18:06:32 +00:00
|
|
|
if (device_names != "")
|
|
|
|
|
device_names += ", ";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
device_names += Device::string_from_type(type);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* shading system */
|
|
|
|
|
string ssname = "svm";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* parse options */
|
|
|
|
|
ArgParse ap;
|
2022-04-29 18:00:38 +02:00
|
|
|
bool help = false, profile = false, debug = false, version = false;
|
2014-11-16 01:12:19 +05:00
|
|
|
int verbosity = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-27 02:37:48 +00:00
|
|
|
ap.options("Usage: cycles [options] file.xml",
|
2011-04-27 11:58:34 +00:00
|
|
|
"%*",
|
|
|
|
|
files_parse,
|
|
|
|
|
"",
|
2012-01-04 18:06:32 +00:00
|
|
|
"--device %s",
|
|
|
|
|
&devicename,
|
|
|
|
|
("Devices to use: " + device_names).c_str(),
|
2014-01-25 13:25:26 +01:00
|
|
|
#ifdef WITH_OSL
|
2011-04-27 11:58:34 +00:00
|
|
|
"--shadingsys %s",
|
|
|
|
|
&ssname,
|
|
|
|
|
"Shading system to use: svm, osl",
|
2014-01-25 13:25:26 +01:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
"--background",
|
|
|
|
|
&options.session_params.background,
|
|
|
|
|
"Render in background, without user interface",
|
|
|
|
|
"--quiet",
|
|
|
|
|
&options.quiet,
|
|
|
|
|
"In background mode, don't print progress messages",
|
2011-09-16 13:14:02 +00:00
|
|
|
"--samples %d",
|
|
|
|
|
&options.session_params.samples,
|
|
|
|
|
"Number of samples to render",
|
2018-03-15 22:07:37 +01:00
|
|
|
"--output %s",
|
2021-09-24 03:52:25 +02:00
|
|
|
&options.output_filepath,
|
2018-03-15 22:07:37 +01:00
|
|
|
"File path to write output image",
|
2011-08-24 10:44:04 +00:00
|
|
|
"--threads %d",
|
|
|
|
|
&options.session_params.threads,
|
|
|
|
|
"CPU Rendering Threads",
|
2011-12-25 13:34:18 +00:00
|
|
|
"--width %d",
|
|
|
|
|
&options.width,
|
|
|
|
|
"Window width in pixel",
|
|
|
|
|
"--height %d",
|
|
|
|
|
&options.height,
|
|
|
|
|
"Window height in pixel",
|
2021-09-24 03:52:25 +02:00
|
|
|
"--tile-size %d",
|
|
|
|
|
&options.session_params.tile_size,
|
|
|
|
|
"Tile size in pixels",
|
2012-01-04 18:06:32 +00:00
|
|
|
"--list-devices",
|
|
|
|
|
&list,
|
|
|
|
|
"List information about all available devices",
|
2022-04-29 18:00:38 +02:00
|
|
|
"--profile",
|
|
|
|
|
&profile,
|
|
|
|
|
"Enable profile logging",
|
2014-11-16 01:12:19 +05:00
|
|
|
#ifdef WITH_CYCLES_LOGGING
|
|
|
|
|
"--debug",
|
|
|
|
|
&debug,
|
|
|
|
|
"Enable debug logging",
|
|
|
|
|
"--verbose %d",
|
|
|
|
|
&verbosity,
|
|
|
|
|
"Set verbosity of the logger",
|
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
"--help",
|
|
|
|
|
&help,
|
|
|
|
|
"Print help message",
|
2016-03-31 01:13:13 +02:00
|
|
|
"--version",
|
|
|
|
|
&version,
|
|
|
|
|
"Print version number",
|
2011-04-27 11:58:34 +00:00
|
|
|
NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (ap.parse(argc, argv) < 0) {
|
2012-08-09 23:00:57 +00:00
|
|
|
fprintf(stderr, "%s\n", ap.geterror().c_str());
|
2011-04-27 11:58:34 +00:00
|
|
|
ap.usage();
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (debug) {
|
2014-11-16 01:12:19 +05:00
|
|
|
util_logging_start();
|
|
|
|
|
util_logging_verbosity_set(verbosity);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 01:12:19 +05:00
|
|
|
if (list) {
|
2019-01-29 16:39:30 +01:00
|
|
|
vector<DeviceInfo> devices = Device::available_devices();
|
2012-01-04 18:06:32 +00:00
|
|
|
printf("Devices:\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
foreach (DeviceInfo &info, devices) {
|
2015-05-20 17:10:24 +02:00
|
|
|
printf(" %-10s%s%s\n",
|
|
|
|
|
Device::string_from_type(info.type).c_str(),
|
2012-01-04 18:06:32 +00:00
|
|
|
info.description.c_str(),
|
|
|
|
|
(info.display_device) ? " (display)" : "");
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
2016-03-31 01:13:13 +02:00
|
|
|
else if (version) {
|
2016-03-31 09:44:09 +02:00
|
|
|
printf("%s\n", CYCLES_VERSION_STRING);
|
2016-03-31 01:13:13 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
else if (help || options.filepath == "") {
|
|
|
|
|
ap.usage();
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-29 18:00:38 +02:00
|
|
|
options.session_params.use_profiling = profile;
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (ssname == "osl")
|
2014-05-19 19:17:40 +02:00
|
|
|
options.scene_params.shadingsystem = SHADINGSYSTEM_OSL;
|
2011-04-27 11:58:34 +00:00
|
|
|
else if (ssname == "svm")
|
2014-05-19 19:17:40 +02:00
|
|
|
options.scene_params.shadingsystem = SHADINGSYSTEM_SVM;
|
2014-02-14 13:40:29 +01:00
|
|
|
|
2014-04-17 23:16:12 +02:00
|
|
|
#ifndef WITH_CYCLES_STANDALONE_GUI
|
2013-08-30 17:34:27 +00:00
|
|
|
options.session_params.background = true;
|
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-09-24 03:52:25 +02:00
|
|
|
if (options.session_params.tile_size > 0) {
|
|
|
|
|
options.session_params.use_auto_tile = true;
|
|
|
|
|
}
|
2014-04-17 23:16:12 +02:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
/* find matching device */
|
|
|
|
|
DeviceType device_type = Device::type_from_string(devicename.c_str());
|
2019-01-29 16:39:30 +01:00
|
|
|
vector<DeviceInfo> devices = Device::available_devices(DEVICE_MASK(device_type));
|
2012-01-04 18:06:32 +00:00
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
bool device_available = false;
|
|
|
|
|
if (!devices.empty()) {
|
|
|
|
|
options.session_params.device = devices.front();
|
|
|
|
|
device_available = true;
|
2012-01-04 18:06:32 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-01-04 18:06:32 +00:00
|
|
|
/* handle invalid configurations */
|
|
|
|
|
if (options.session_params.device.type == DEVICE_NONE || !device_available) {
|
2011-04-27 11:58:34 +00:00
|
|
|
fprintf(stderr, "Unknown device: %s\n", devicename.c_str());
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
|
else if (!(ssname == "osl" || ssname == "svm")) {
|
|
|
|
|
fprintf(stderr, "Unknown shading system: %s\n", ssname.c_str());
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2014-05-19 19:17:40 +02:00
|
|
|
else if (options.scene_params.shadingsystem == SHADINGSYSTEM_OSL &&
|
|
|
|
|
options.session_params.device.type != DEVICE_CPU) {
|
2011-04-27 11:58:34 +00:00
|
|
|
fprintf(stderr, "OSL shading system only works with CPU device\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
2014-01-25 18:57:02 +01:00
|
|
|
#endif
|
2011-09-16 13:14:02 +00:00
|
|
|
else if (options.session_params.samples < 0) {
|
|
|
|
|
fprintf(stderr, "Invalid number of samples: %d\n", options.session_params.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
else if (options.filepath == "") {
|
|
|
|
|
fprintf(stderr, "No file path specified\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
using namespace ccl;
|
|
|
|
|
|
|
|
|
|
int main(int argc, const char **argv)
|
|
|
|
|
{
|
2014-11-16 01:12:19 +05:00
|
|
|
util_logging_init(argv[0]);
|
2012-11-09 21:44:31 +00:00
|
|
|
path_init();
|
2011-04-27 11:58:34 +00:00
|
|
|
options_parse(argc, argv);
|
2014-02-14 13:40:29 +01:00
|
|
|
|
2013-08-30 17:34:27 +00:00
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
2011-04-27 11:58:34 +00:00
|
|
|
if (options.session_params.background) {
|
2013-08-30 17:34:27 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
session_init();
|
|
|
|
|
options.session->wait();
|
|
|
|
|
session_exit();
|
2013-08-30 17:34:27 +00:00
|
|
|
#ifdef WITH_CYCLES_STANDALONE_GUI
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
string title = "Cycles: " + path_filename(options.filepath);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* init/exit are callback so they run while GL is initialized */
|
2021-09-17 15:15:14 +02:00
|
|
|
window_main_loop(title.c_str(),
|
|
|
|
|
options.width,
|
|
|
|
|
options.height,
|
|
|
|
|
session_init,
|
|
|
|
|
session_exit,
|
|
|
|
|
resize,
|
|
|
|
|
display,
|
|
|
|
|
keyboard,
|
|
|
|
|
motion);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-08-30 17:34:27 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|