2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "background.h"
|
|
|
|
|
#include "buffers.h"
|
|
|
|
|
#include "camera.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
#include "integrator.h"
|
2011-08-28 13:55:59 +00:00
|
|
|
#include "film.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "light.h"
|
|
|
|
|
#include "scene.h"
|
|
|
|
|
#include "session.h"
|
|
|
|
|
#include "shader.h"
|
|
|
|
|
|
|
|
|
|
#include "util_color.h"
|
|
|
|
|
#include "util_foreach.h"
|
|
|
|
|
#include "util_function.h"
|
|
|
|
|
#include "util_progress.h"
|
|
|
|
|
#include "util_time.h"
|
|
|
|
|
|
|
|
|
|
#include "blender_sync.h"
|
|
|
|
|
#include "blender_session.h"
|
|
|
|
|
#include "blender_util.h"
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2012-01-09 16:58:01 +00:00
|
|
|
BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_,
|
|
|
|
|
BL::BlendData b_data_, BL::Scene b_scene_)
|
|
|
|
|
: b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_scene(b_scene_),
|
2012-09-04 13:29:07 +00:00
|
|
|
b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* offline render */
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
width = b_engine.resolution_x();
|
|
|
|
|
height = b_engine.resolution_y();
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
background = true;
|
|
|
|
|
last_redraw_time = 0.0f;
|
|
|
|
|
|
|
|
|
|
create_session();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 16:58:01 +00:00
|
|
|
BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_,
|
|
|
|
|
BL::BlendData b_data_, BL::Scene b_scene_,
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::SpaceView3D b_v3d_, BL::RegionView3D b_rv3d_, int width_, int height_)
|
2012-01-09 16:58:01 +00:00
|
|
|
: b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_scene(b_scene_),
|
2012-09-04 13:29:07 +00:00
|
|
|
b_v3d(b_v3d_), b_rv3d(b_rv3d_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* 3d view render */
|
|
|
|
|
width = width_;
|
|
|
|
|
height = height_;
|
|
|
|
|
background = false;
|
|
|
|
|
last_redraw_time = 0.0f;
|
|
|
|
|
|
|
|
|
|
create_session();
|
2011-12-21 20:51:55 +00:00
|
|
|
session->start();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlenderSession::~BlenderSession()
|
|
|
|
|
{
|
|
|
|
|
free_session();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::create_session()
|
|
|
|
|
{
|
2011-11-04 15:46:15 +00:00
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
|
2012-09-04 13:29:07 +00:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-10-30 10:12:34 +00:00
|
|
|
/* reset status/progress */
|
2012-06-09 18:56:12 +00:00
|
|
|
last_status = "";
|
|
|
|
|
last_progress = -1.0f;
|
2011-10-30 10:12:34 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* create scene */
|
2012-09-04 13:29:07 +00:00
|
|
|
scene = new Scene(scene_params, session_params.device);
|
|
|
|
|
|
|
|
|
|
/* create session */
|
|
|
|
|
session = new Session(session_params);
|
|
|
|
|
session->scene = scene;
|
|
|
|
|
session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this));
|
|
|
|
|
session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this));
|
|
|
|
|
session->set_pause(BlenderSync::get_session_pause(b_scene, background));
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
/* create sync */
|
2012-09-04 13:29:07 +00:00
|
|
|
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
|
2012-04-30 12:49:26 +00:00
|
|
|
sync->sync_data(b_v3d, b_engine.camera_override());
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
if(b_rv3d)
|
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
|
|
|
|
else
|
2012-04-13 17:42:03 +00:00
|
|
|
sync->sync_camera(b_engine.camera_override(), width, height);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* set buffer parameters */
|
2012-06-06 23:27:43 +00:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height);
|
2011-12-20 12:25:37 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::free_session()
|
|
|
|
|
{
|
|
|
|
|
delete sync;
|
|
|
|
|
delete session;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
static PassType get_pass_type(BL::RenderPass b_pass)
|
|
|
|
|
{
|
|
|
|
|
switch(b_pass.type()) {
|
|
|
|
|
case BL::RenderPass::type_COMBINED:
|
|
|
|
|
return PASS_COMBINED;
|
|
|
|
|
|
|
|
|
|
case BL::RenderPass::type_Z:
|
|
|
|
|
return PASS_DEPTH;
|
|
|
|
|
case BL::RenderPass::type_NORMAL:
|
|
|
|
|
return PASS_NORMAL;
|
|
|
|
|
case BL::RenderPass::type_OBJECT_INDEX:
|
|
|
|
|
return PASS_OBJECT_ID;
|
|
|
|
|
case BL::RenderPass::type_UV:
|
|
|
|
|
return PASS_UV;
|
2012-04-30 12:49:26 +00:00
|
|
|
case BL::RenderPass::type_VECTOR:
|
|
|
|
|
return PASS_MOTION;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
case BL::RenderPass::type_MATERIAL_INDEX:
|
|
|
|
|
return PASS_MATERIAL_ID;
|
|
|
|
|
|
|
|
|
|
case BL::RenderPass::type_DIFFUSE_DIRECT:
|
|
|
|
|
return PASS_DIFFUSE_DIRECT;
|
|
|
|
|
case BL::RenderPass::type_GLOSSY_DIRECT:
|
|
|
|
|
return PASS_GLOSSY_DIRECT;
|
|
|
|
|
case BL::RenderPass::type_TRANSMISSION_DIRECT:
|
|
|
|
|
return PASS_TRANSMISSION_DIRECT;
|
|
|
|
|
|
|
|
|
|
case BL::RenderPass::type_DIFFUSE_INDIRECT:
|
|
|
|
|
return PASS_DIFFUSE_INDIRECT;
|
|
|
|
|
case BL::RenderPass::type_GLOSSY_INDIRECT:
|
|
|
|
|
return PASS_GLOSSY_INDIRECT;
|
|
|
|
|
case BL::RenderPass::type_TRANSMISSION_INDIRECT:
|
|
|
|
|
return PASS_TRANSMISSION_INDIRECT;
|
|
|
|
|
|
|
|
|
|
case BL::RenderPass::type_DIFFUSE_COLOR:
|
|
|
|
|
return PASS_DIFFUSE_COLOR;
|
|
|
|
|
case BL::RenderPass::type_GLOSSY_COLOR:
|
|
|
|
|
return PASS_GLOSSY_COLOR;
|
|
|
|
|
case BL::RenderPass::type_TRANSMISSION_COLOR:
|
|
|
|
|
return PASS_TRANSMISSION_COLOR;
|
|
|
|
|
|
|
|
|
|
case BL::RenderPass::type_EMIT:
|
|
|
|
|
return PASS_EMISSION;
|
|
|
|
|
case BL::RenderPass::type_ENVIRONMENT:
|
|
|
|
|
return PASS_BACKGROUND;
|
2012-02-28 16:45:08 +00:00
|
|
|
case BL::RenderPass::type_AO:
|
|
|
|
|
return PASS_AO;
|
2012-03-28 10:39:21 +00:00
|
|
|
case BL::RenderPass::type_SHADOW:
|
|
|
|
|
return PASS_SHADOW;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
|
|
|
|
case BL::RenderPass::type_DIFFUSE:
|
|
|
|
|
case BL::RenderPass::type_COLOR:
|
|
|
|
|
case BL::RenderPass::type_REFRACTION:
|
|
|
|
|
case BL::RenderPass::type_SPECULAR:
|
|
|
|
|
case BL::RenderPass::type_REFLECTION:
|
|
|
|
|
case BL::RenderPass::type_MIST:
|
|
|
|
|
return PASS_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PASS_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
static BL::RenderResult begin_render_result(BL::RenderEngine b_engine, int x, int y, int w, int h, const char *layername)
|
|
|
|
|
{
|
|
|
|
|
RenderResult *rrp = RE_engine_begin_result((RenderEngine*)b_engine.ptr.data, x, y, w, h, layername);
|
|
|
|
|
PointerRNA rrptr;
|
|
|
|
|
RNA_pointer_create(NULL, &RNA_RenderResult, rrp, &rrptr);
|
|
|
|
|
return BL::RenderResult(rrptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void end_render_result(BL::RenderEngine b_engine, BL::RenderResult b_rr, bool cancel = false)
|
|
|
|
|
{
|
|
|
|
|
RE_engine_end_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data, (int)cancel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::do_write_update_render_tile(RenderTile& rtile, bool do_update_only)
|
|
|
|
|
{
|
|
|
|
|
BufferParams& params = rtile.buffers->params;
|
|
|
|
|
int x = params.full_x - session->tile_manager.params.full_x;
|
|
|
|
|
int y = params.full_y - session->tile_manager.params.full_y;
|
|
|
|
|
int w = params.width;
|
|
|
|
|
int h = params.height;
|
|
|
|
|
|
|
|
|
|
/* get render result */
|
|
|
|
|
BL::RenderResult b_rr = begin_render_result(b_engine, x, y, w, h, b_rlay_name.c_str());
|
|
|
|
|
|
|
|
|
|
/* can happen if the intersected rectangle gives 0 width or height */
|
|
|
|
|
if (b_rr.ptr.data == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BL::RenderResult::layers_iterator b_single_rlay;
|
|
|
|
|
b_rr.layers.begin(b_single_rlay);
|
|
|
|
|
BL::RenderLayer b_rlay = *b_single_rlay;
|
|
|
|
|
|
|
|
|
|
if (do_update_only) {
|
|
|
|
|
/* update only needed */
|
|
|
|
|
update_render_result(b_rr, b_rlay, rtile);
|
|
|
|
|
end_render_result(b_engine, b_rr, true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* write result */
|
|
|
|
|
write_render_result(b_rr, b_rlay, rtile);
|
|
|
|
|
end_render_result(b_engine, b_rr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::write_render_tile(RenderTile& rtile)
|
|
|
|
|
{
|
|
|
|
|
do_write_update_render_tile(rtile, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::update_render_tile(RenderTile& rtile)
|
|
|
|
|
{
|
|
|
|
|
do_write_update_render_tile(rtile, true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::render()
|
|
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
/* set callback to write out render results */
|
|
|
|
|
session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
|
|
|
|
|
session->update_render_tile_cb = function_bind(&BlenderSession::update_render_tile, this, _1);
|
|
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* get buffer parameters */
|
2012-09-04 13:29:07 +00:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2012-06-06 23:27:43 +00:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height);
|
2011-12-21 20:51:55 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* render each layer */
|
2011-12-21 20:51:55 +00:00
|
|
|
BL::RenderSettings r = b_scene.render();
|
2012-09-04 13:29:07 +00:00
|
|
|
BL::RenderSettings::layers_iterator b_iter;
|
2011-12-21 20:51:55 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
for(r.layers.begin(b_iter); b_iter != r.layers.end(); ++b_iter) {
|
|
|
|
|
b_rlay_name = b_iter->name();
|
|
|
|
|
|
|
|
|
|
/* temporary render result to find needed passes */
|
|
|
|
|
BL::RenderResult b_rr = begin_render_result(b_engine, 0, 0, 1, 1, b_rlay_name.c_str());
|
|
|
|
|
BL::RenderResult::layers_iterator b_single_rlay;
|
|
|
|
|
b_rr.layers.begin(b_single_rlay);
|
|
|
|
|
|
|
|
|
|
/* layer will be missing if it was disabled in the UI */
|
|
|
|
|
if(b_single_rlay == b_rr.layers.end()) {
|
|
|
|
|
end_render_result(b_engine, b_rr, true);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BL::RenderLayer b_rlay = *b_single_rlay;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* add passes */
|
2012-01-26 14:55:25 +00:00
|
|
|
vector<Pass> passes;
|
|
|
|
|
Pass::add(PASS_COMBINED, passes);
|
|
|
|
|
|
2012-01-26 19:07:01 +00:00
|
|
|
if(session_params.device.advanced_shading) {
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
|
/* loop over passes */
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
BL::RenderLayer::passes_iterator b_pass_iter;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
for(b_rlay.passes.begin(b_pass_iter); b_pass_iter != b_rlay.passes.end(); ++b_pass_iter) {
|
|
|
|
|
BL::RenderPass b_pass(*b_pass_iter);
|
|
|
|
|
PassType pass_type = get_pass_type(b_pass);
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
if(pass_type == PASS_MOTION && scene->integrator->motion_blur)
|
|
|
|
|
continue;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
if(pass_type != PASS_NONE)
|
2012-01-26 14:55:25 +00:00
|
|
|
Pass::add(pass_type, passes);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* free result without merging */
|
|
|
|
|
end_render_result(b_engine, b_rr, true);
|
|
|
|
|
|
2012-01-26 14:55:25 +00:00
|
|
|
buffer_params.passes = passes;
|
2012-06-20 14:24:52 +00:00
|
|
|
scene->film->tag_passes_update(scene, passes);
|
2012-01-26 14:55:25 +00:00
|
|
|
scene->film->tag_update(scene);
|
2012-05-18 14:06:53 +00:00
|
|
|
scene->integrator->tag_update(scene);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* update scene */
|
2012-09-04 13:29:07 +00:00
|
|
|
sync->sync_data(b_v3d, b_engine.camera_override(), b_rlay_name.c_str());
|
2011-12-21 20:51:55 +00:00
|
|
|
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
/* update session */
|
|
|
|
|
int samples = sync->get_layer_samples();
|
|
|
|
|
session->reset(buffer_params, (samples == 0)? session_params.samples: samples);
|
|
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* render */
|
|
|
|
|
session->start();
|
|
|
|
|
session->wait();
|
|
|
|
|
|
|
|
|
|
if(session->progress.get_cancel())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* clear callback */
|
|
|
|
|
session->write_render_tile_cb = NULL;
|
|
|
|
|
session->update_render_tile_cb = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
void BlenderSession::do_write_update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile, bool do_update_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
RenderBuffers *buffers = rtile.buffers;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
|
|
|
|
/* copy data from device */
|
|
|
|
|
if(!buffers->copy_from_device())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BufferParams& params = buffers->params;
|
2011-08-28 13:55:59 +00:00
|
|
|
float exposure = scene->film->exposure;
|
2011-05-09 09:03:08 +00:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
vector<float> pixels(params.width*params.height*4);
|
2011-05-09 09:03:08 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (!do_update_only) {
|
|
|
|
|
/* copy each pass */
|
|
|
|
|
BL::RenderLayer::passes_iterator b_iter;
|
|
|
|
|
|
|
|
|
|
for(b_rlay.passes.begin(b_iter); b_iter != b_rlay.passes.end(); ++b_iter) {
|
|
|
|
|
BL::RenderPass b_pass(*b_iter);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* find matching pass type */
|
|
|
|
|
PassType pass_type = get_pass_type(b_pass);
|
|
|
|
|
int components = b_pass.channels();
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* copy pixels */
|
|
|
|
|
if(buffers->get_pass_rect(pass_type, exposure, rtile.sample, components, &pixels[0]))
|
|
|
|
|
rna_RenderPass_rect_set(&b_pass.ptr, &pixels[0]);
|
|
|
|
|
}
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* copy combined pass */
|
2012-09-04 13:29:07 +00:00
|
|
|
if(buffers->get_pass_rect(PASS_COMBINED, exposure, rtile.sample, 4, &pixels[0]))
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
rna_RenderLayer_rect_set(&b_rlay.ptr, &pixels[0]);
|
|
|
|
|
|
|
|
|
|
/* tag result as updated */
|
|
|
|
|
RE_engine_update_result((RenderEngine*)b_engine.ptr.data, (RenderResult*)b_rr.ptr.data);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
void BlenderSession::write_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile)
|
|
|
|
|
{
|
|
|
|
|
do_write_update_render_result(b_rr, b_rlay, rtile, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::update_render_result(BL::RenderResult b_rr, BL::RenderLayer b_rlay, RenderTile& rtile)
|
|
|
|
|
{
|
|
|
|
|
do_write_update_render_result(b_rr, b_rlay, rtile, true);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::synchronize()
|
|
|
|
|
{
|
|
|
|
|
/* on session/scene parameter changes, we recreate session entirely */
|
2011-11-04 15:46:15 +00:00
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
|
2012-09-04 13:29:07 +00:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
if(session->params.modified(session_params) ||
|
2012-06-09 18:56:12 +00:00
|
|
|
scene->params.modified(scene_params))
|
|
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
free_session();
|
|
|
|
|
create_session();
|
2011-12-21 20:51:55 +00:00
|
|
|
session->start();
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
/* increase samples, but never decrease */
|
|
|
|
|
session->set_samples(session_params.samples);
|
2011-08-29 16:54:13 +00:00
|
|
|
session->set_pause(BlenderSync::get_session_pause(b_scene, background));
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* copy recalc flags, outside of mutex so we can decide to do the real
|
2012-06-09 17:22:52 +00:00
|
|
|
* synchronization at a later time to not block on running updates */
|
2011-04-27 11:58:34 +00:00
|
|
|
sync->sync_recalc();
|
|
|
|
|
|
|
|
|
|
/* try to acquire mutex. if we don't want to or can't, come back later */
|
|
|
|
|
if(!session->ready_to_reset() || !session->scene->mutex.try_lock()) {
|
|
|
|
|
tag_update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* data and camera synchronize */
|
2012-04-30 12:49:26 +00:00
|
|
|
sync->sync_data(b_v3d, b_engine.camera_override());
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
if(b_rv3d)
|
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
|
|
|
|
else
|
2012-04-13 17:42:03 +00:00
|
|
|
sync->sync_camera(b_engine.camera_override(), width, height);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
/* unlock */
|
|
|
|
|
session->scene->mutex.unlock();
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* reset if needed */
|
2011-12-20 12:25:37 +00:00
|
|
|
if(scene->need_reset()) {
|
2012-06-06 23:27:43 +00:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height);
|
2011-12-20 12:25:37 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BlenderSession::draw(int w, int h)
|
|
|
|
|
{
|
|
|
|
|
/* before drawing, we verify camera and viewport size changes, because
|
2012-06-09 17:22:52 +00:00
|
|
|
* we do not get update callbacks for those, we must detect them here */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(session->ready_to_reset()) {
|
|
|
|
|
bool reset = false;
|
|
|
|
|
|
|
|
|
|
/* try to acquire mutex. if we can't, come back later */
|
|
|
|
|
if(!session->scene->mutex.try_lock()) {
|
|
|
|
|
tag_update();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* update camera from 3d view */
|
|
|
|
|
bool need_update = scene->camera->need_update;
|
|
|
|
|
|
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, w, h);
|
|
|
|
|
|
|
|
|
|
if(scene->camera->need_update && !need_update)
|
|
|
|
|
reset = true;
|
|
|
|
|
|
|
|
|
|
session->scene->mutex.unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if dimensions changed, reset */
|
|
|
|
|
if(width != w || height != h) {
|
|
|
|
|
width = w;
|
|
|
|
|
height = h;
|
|
|
|
|
reset = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* reset if requested */
|
2011-08-28 13:55:59 +00:00
|
|
|
if(reset) {
|
2012-09-04 13:29:07 +00:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2012-06-06 23:27:43 +00:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, w, h);
|
2011-12-20 12:25:37 +00:00
|
|
|
|
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
/* update status and progress for 3d view draw */
|
|
|
|
|
update_status_progress();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
/* draw */
|
2012-06-06 23:27:43 +00:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height);
|
2011-12-20 12:25:37 +00:00
|
|
|
|
|
|
|
|
return !session->draw(buffer_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::get_status(string& status, string& substatus)
|
|
|
|
|
{
|
|
|
|
|
session->progress.get_status(status, substatus);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-22 13:17:43 +00:00
|
|
|
void BlenderSession::get_progress(float& progress, double& total_time)
|
|
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
double tile_time;
|
|
|
|
|
int tile, sample, samples_per_tile;
|
|
|
|
|
int tile_total = session->tile_manager.state.num_tiles;
|
|
|
|
|
|
|
|
|
|
session->progress.get_tile(tile, total_time, tile_time);
|
2011-08-22 13:17:43 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
sample = session->progress.get_sample();
|
|
|
|
|
samples_per_tile = session->tile_manager.state.num_samples;
|
|
|
|
|
|
|
|
|
|
progress = ((float)sample/(float)(tile_total * samples_per_tile));
|
2011-08-22 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
void BlenderSession::update_status_progress()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-02-07 17:22:47 +00:00
|
|
|
string timestatus, status, substatus;
|
2011-08-22 13:17:43 +00:00
|
|
|
float progress;
|
|
|
|
|
double total_time;
|
|
|
|
|
char time_str[128];
|
|
|
|
|
|
|
|
|
|
get_status(status, substatus);
|
|
|
|
|
get_progress(progress, total_time);
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
timestatus = b_scene.name();
|
|
|
|
|
if(b_rlay_name != "")
|
|
|
|
|
timestatus += ", " + b_rlay_name;
|
|
|
|
|
timestatus += " | ";
|
|
|
|
|
|
2012-01-09 16:57:46 +00:00
|
|
|
BLI_timestr(total_time, time_str);
|
2012-09-04 13:29:07 +00:00
|
|
|
timestatus += "Elapsed: " + string(time_str) + " | ";
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-22 13:17:43 +00:00
|
|
|
if(substatus.size() > 0)
|
|
|
|
|
status += " | " + substatus;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-10-30 10:12:34 +00:00
|
|
|
if(status != last_status) {
|
2012-02-07 17:22:47 +00:00
|
|
|
RE_engine_update_stats((RenderEngine*)b_engine.ptr.data, "", (timestatus + status).c_str());
|
2011-10-30 10:12:34 +00:00
|
|
|
last_status = status;
|
|
|
|
|
}
|
|
|
|
|
if(progress != last_progress) {
|
|
|
|
|
RE_engine_update_progress((RenderEngine*)b_engine.ptr.data, progress);
|
|
|
|
|
last_progress = progress;
|
|
|
|
|
}
|
2011-08-23 12:20:11 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
void BlenderSession::tag_update()
|
|
|
|
|
{
|
|
|
|
|
/* tell blender that we want to get another update callback */
|
|
|
|
|
engine_tag_update((RenderEngine*)b_engine.ptr.data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::tag_redraw()
|
|
|
|
|
{
|
2011-08-22 13:17:43 +00:00
|
|
|
if(background) {
|
2011-08-23 12:20:11 +00:00
|
|
|
/* update stats and progress, only for background here because
|
2012-06-09 17:22:52 +00:00
|
|
|
* in 3d view we do it in draw for thread safety reasons */
|
2011-08-23 12:20:11 +00:00
|
|
|
update_status_progress();
|
|
|
|
|
|
2011-08-22 13:17:43 +00:00
|
|
|
/* offline render, redraw if timeout passed */
|
2012-06-09 17:45:22 +00:00
|
|
|
if(time_dt() - last_redraw_time > 1.0) {
|
2011-04-27 11:58:34 +00:00
|
|
|
engine_tag_redraw((RenderEngine*)b_engine.ptr.data);
|
|
|
|
|
last_redraw_time = time_dt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* tell blender that we want to redraw */
|
|
|
|
|
engine_tag_redraw((RenderEngine*)b_engine.ptr.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::test_cancel()
|
|
|
|
|
{
|
|
|
|
|
/* test if we need to cancel rendering */
|
|
|
|
|
if(background)
|
|
|
|
|
if(RE_engine_test_break((RenderEngine*)b_engine.ptr.data))
|
|
|
|
|
session->progress.set_cancel("Cancelled");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|