2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#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"
|
2014-01-02 19:05:07 -02:00
|
|
|
#include "mesh.h"
|
|
|
|
#include "object.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "scene.h"
|
|
|
|
#include "session.h"
|
|
|
|
#include "shader.h"
|
|
|
|
|
|
|
|
#include "util_color.h"
|
|
|
|
#include "util_foreach.h"
|
|
|
|
#include "util_function.h"
|
2016-11-18 18:23:45 +01:00
|
|
|
#include "util_hash.h"
|
2015-06-17 11:56:19 +02:00
|
|
|
#include "util_logging.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_progress.h"
|
|
|
|
#include "util_time.h"
|
|
|
|
|
|
|
|
#include "blender_sync.h"
|
|
|
|
#include "blender_session.h"
|
|
|
|
#include "blender_util.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2015-02-18 21:16:52 +05:00
|
|
|
bool BlenderSession::headless = false;
|
2016-03-30 15:55:12 +02:00
|
|
|
int BlenderSession::num_resumable_chunks = 0;
|
|
|
|
int BlenderSession::current_resumable_chunk = 0;
|
2015-02-18 21:16:52 +05:00
|
|
|
|
2016-01-30 14:18:29 +01: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_render(b_engine.render()),
|
|
|
|
b_scene(b_scene),
|
|
|
|
b_v3d(PointerRNA_NULL),
|
|
|
|
b_rv3d(PointerRNA_NULL),
|
|
|
|
python_thread_state(NULL)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* offline render */
|
|
|
|
|
2013-05-16 21:53:21 +00:00
|
|
|
width = render_resolution_x(b_render);
|
|
|
|
height = render_resolution_y(b_render);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
background = true;
|
2013-04-24 20:12:12 +00:00
|
|
|
last_redraw_time = 0.0;
|
|
|
|
start_resize_time = 0.0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
BlenderSession::BlenderSession(BL::RenderEngine& b_engine,
|
|
|
|
BL::UserPreferences& b_userpref,
|
|
|
|
BL::BlendData& b_data,
|
|
|
|
BL::Scene& b_scene,
|
|
|
|
BL::SpaceView3D& b_v3d,
|
|
|
|
BL::RegionView3D& b_rv3d,
|
|
|
|
int width, int height)
|
|
|
|
: b_engine(b_engine),
|
|
|
|
b_userpref(b_userpref),
|
|
|
|
b_data(b_data),
|
|
|
|
b_render(b_scene.render()),
|
|
|
|
b_scene(b_scene),
|
|
|
|
b_v3d(b_v3d),
|
|
|
|
b_rv3d(b_rv3d),
|
|
|
|
width(width),
|
|
|
|
height(height),
|
|
|
|
python_thread_state(NULL)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* 3d view render */
|
2013-03-14 07:38:37 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
background = false;
|
2013-04-24 20:12:12 +00:00
|
|
|
last_redraw_time = 0.0;
|
|
|
|
start_resize_time = 0.0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlenderSession::~BlenderSession()
|
|
|
|
{
|
|
|
|
free_session();
|
|
|
|
}
|
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
void BlenderSession::create()
|
|
|
|
{
|
|
|
|
create_session();
|
|
|
|
|
|
|
|
if(b_v3d)
|
|
|
|
session->start();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::create_session()
|
|
|
|
{
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2014-12-25 00:53:26 +05:00
|
|
|
bool is_cpu = session_params.device.type == DEVICE_CPU;
|
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(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 = "";
|
2014-12-05 21:27:52 +05:00
|
|
|
last_error = "";
|
2012-06-09 18:56:12 +00:00
|
|
|
last_progress = -1.0f;
|
2013-04-24 20:12:12 +00:00
|
|
|
start_resize_time = 0.0;
|
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);
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* setup callbacks for builtin image support */
|
|
|
|
scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7);
|
2016-11-29 11:03:11 +01:00
|
|
|
scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4);
|
|
|
|
scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4);
|
2014-03-29 13:03:48 +01:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* 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));
|
2014-08-01 16:39:05 +06:00
|
|
|
session->set_pause(session_pause);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* create sync */
|
2014-12-25 00:53:26 +05:00
|
|
|
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress, is_cpu);
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
2013-06-09 11:57:51 +00:00
|
|
|
if(b_v3d) {
|
2014-08-01 16:39:05 +06:00
|
|
|
if(session_pause == false) {
|
|
|
|
/* full data sync */
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
2015-07-21 15:36:35 +02:00
|
|
|
sync->sync_data(b_render,
|
|
|
|
b_v3d,
|
2016-01-30 14:18:29 +01:00
|
|
|
b_camera_override,
|
2015-07-21 15:36:35 +02:00
|
|
|
width, height,
|
|
|
|
&python_thread_state,
|
|
|
|
b_rlay_name.c_str());
|
2014-08-01 16:39:05 +06:00
|
|
|
}
|
2013-06-09 11:57:51 +00:00
|
|
|
}
|
2013-06-11 14:15:46 +00:00
|
|
|
else {
|
2013-06-12 20:47:48 +00:00
|
|
|
/* for final render we will do full data sync per render layer, only
|
|
|
|
* do some basic syncing here, no objects or materials for speed */
|
|
|
|
sync->sync_render_layers(b_v3d, NULL);
|
|
|
|
sync->sync_integrator();
|
2016-03-11 12:57:02 +05:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
2013-06-11 14:15:46 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* set buffer parameters */
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
|
2011-12-20 12:25:37 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2013-01-01 16:15:13 +00:00
|
|
|
|
|
|
|
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
|
2016-03-30 15:55:12 +02:00
|
|
|
|
|
|
|
update_resumable_tile_manager(session_params.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
void BlenderSession::reset_session(BL::BlendData& b_data_, BL::Scene& b_scene_)
|
2012-11-09 08:46:53 +00:00
|
|
|
{
|
|
|
|
b_data = b_data_;
|
2013-03-14 07:38:37 +00:00
|
|
|
b_render = b_engine.render();
|
2012-11-09 08:46:53 +00:00
|
|
|
b_scene = b_scene_;
|
|
|
|
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2014-12-25 00:53:26 +05:00
|
|
|
const bool is_cpu = session_params.device.type == DEVICE_CPU;
|
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2013-05-16 21:53:21 +00:00
|
|
|
width = render_resolution_x(b_render);
|
|
|
|
height = render_resolution_y(b_render);
|
2012-11-10 08:13:13 +00:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
if(scene->params.modified(scene_params) ||
|
2013-02-14 16:48:43 +00:00
|
|
|
session->params.modified(session_params) ||
|
|
|
|
!scene_params.persistent_data)
|
2012-11-09 08:46:53 +00:00
|
|
|
{
|
|
|
|
/* if scene or session parameters changed, it's easier to simply re-create
|
|
|
|
* them rather than trying to distinguish which settings need to be updated
|
|
|
|
*/
|
|
|
|
|
|
|
|
delete session;
|
|
|
|
|
|
|
|
create_session();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
session->progress.reset();
|
|
|
|
scene->reset();
|
|
|
|
|
2013-01-08 16:56:04 +00:00
|
|
|
session->tile_manager.set_tile_order(session_params.tile_order);
|
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
/* peak memory usage should show current render peak, not peak for all renders
|
|
|
|
* made by this render session
|
|
|
|
*/
|
|
|
|
session->stats.mem_peak = session->stats.mem_used;
|
|
|
|
|
|
|
|
/* sync object should be re-created */
|
2014-12-25 00:53:26 +05:00
|
|
|
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress, is_cpu);
|
2013-06-09 11:57:51 +00:00
|
|
|
|
2013-09-16 21:20:21 +00:00
|
|
|
/* for final render we will do full data sync per render layer, only
|
|
|
|
* do some basic syncing here, no objects or materials for speed */
|
2016-03-11 12:57:02 +05:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
2013-09-16 21:20:21 +00:00
|
|
|
sync->sync_render_layers(b_v3d, NULL);
|
|
|
|
sync->sync_integrator();
|
2016-03-11 12:57:02 +05:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
2016-01-30 14:18:29 +01:00
|
|
|
|
|
|
|
BL::SpaceView3D b_null_space_view3d(PointerRNA_NULL);
|
|
|
|
BL::RegionView3D b_null_region_view3d(PointerRNA_NULL);
|
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render,
|
|
|
|
b_null_space_view3d,
|
|
|
|
b_null_region_view3d,
|
|
|
|
scene->camera,
|
|
|
|
width, height);
|
2012-11-09 08:46:53 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2013-01-01 16:15:13 +00:00
|
|
|
|
|
|
|
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
|
2013-04-24 20:12:12 +00:00
|
|
|
|
|
|
|
/* reset time */
|
|
|
|
start_resize_time = 0.0;
|
2012-11-09 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::free_session()
|
|
|
|
{
|
2012-11-09 08:46:53 +00:00
|
|
|
if(sync)
|
|
|
|
delete sync;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
delete session;
|
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static PassType get_pass_type(BL::RenderPass& b_pass)
|
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
|
|
|
{
|
|
|
|
switch(b_pass.type()) {
|
|
|
|
case BL::RenderPass::type_COMBINED:
|
|
|
|
return PASS_COMBINED;
|
|
|
|
|
|
|
|
case BL::RenderPass::type_Z:
|
|
|
|
return PASS_DEPTH;
|
2013-06-07 12:45:26 +00:00
|
|
|
case BL::RenderPass::type_MIST:
|
|
|
|
return PASS_MIST;
|
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_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;
|
2013-08-03 13:12:09 +00:00
|
|
|
case BL::RenderPass::type_SUBSURFACE_DIRECT:
|
|
|
|
return PASS_SUBSURFACE_DIRECT;
|
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_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;
|
2013-08-03 13:12:09 +00:00
|
|
|
case BL::RenderPass::type_SUBSURFACE_INDIRECT:
|
|
|
|
return PASS_SUBSURFACE_INDIRECT;
|
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_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;
|
2013-08-03 13:12:09 +00:00
|
|
|
case BL::RenderPass::type_SUBSURFACE_COLOR:
|
|
|
|
return PASS_SUBSURFACE_COLOR;
|
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_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:
|
|
|
|
return PASS_NONE;
|
2014-10-04 19:00:26 +06:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
|
|
|
case BL::RenderPass::type_DEBUG:
|
|
|
|
{
|
|
|
|
if(b_pass.debug_type() == BL::RenderPass::debug_type_BVH_TRAVERSAL_STEPS)
|
|
|
|
return PASS_BVH_TRAVERSAL_STEPS;
|
2015-06-12 00:12:03 +02:00
|
|
|
if(b_pass.debug_type() == BL::RenderPass::debug_type_BVH_TRAVERSED_INSTANCES)
|
|
|
|
return PASS_BVH_TRAVERSED_INSTANCES;
|
2015-06-11 10:42:38 +02:00
|
|
|
if(b_pass.debug_type() == BL::RenderPass::debug_type_RAY_BOUNCES)
|
|
|
|
return PASS_RAY_BOUNCES;
|
2014-10-04 19:00:26 +06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return PASS_NONE;
|
|
|
|
}
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
static ShaderEvalType get_shader_type(const string& pass_type)
|
|
|
|
{
|
|
|
|
const char *shader_type = pass_type.c_str();
|
|
|
|
|
|
|
|
/* data passes */
|
|
|
|
if(strcmp(shader_type, "NORMAL")==0)
|
|
|
|
return SHADER_EVAL_NORMAL;
|
|
|
|
else if(strcmp(shader_type, "UV")==0)
|
|
|
|
return SHADER_EVAL_UV;
|
|
|
|
else if(strcmp(shader_type, "DIFFUSE_COLOR")==0)
|
|
|
|
return SHADER_EVAL_DIFFUSE_COLOR;
|
|
|
|
else if(strcmp(shader_type, "GLOSSY_COLOR")==0)
|
|
|
|
return SHADER_EVAL_GLOSSY_COLOR;
|
|
|
|
else if(strcmp(shader_type, "TRANSMISSION_COLOR")==0)
|
|
|
|
return SHADER_EVAL_TRANSMISSION_COLOR;
|
|
|
|
else if(strcmp(shader_type, "SUBSURFACE_COLOR")==0)
|
|
|
|
return SHADER_EVAL_SUBSURFACE_COLOR;
|
|
|
|
else if(strcmp(shader_type, "EMIT")==0)
|
|
|
|
return SHADER_EVAL_EMISSION;
|
|
|
|
|
|
|
|
/* light passes */
|
|
|
|
else if(strcmp(shader_type, "AO")==0)
|
|
|
|
return SHADER_EVAL_AO;
|
|
|
|
else if(strcmp(shader_type, "COMBINED")==0)
|
|
|
|
return SHADER_EVAL_COMBINED;
|
|
|
|
else if(strcmp(shader_type, "SHADOW")==0)
|
|
|
|
return SHADER_EVAL_SHADOW;
|
2016-01-15 13:00:56 -02:00
|
|
|
else if(strcmp(shader_type, "DIFFUSE")==0)
|
|
|
|
return SHADER_EVAL_DIFFUSE;
|
|
|
|
else if(strcmp(shader_type, "GLOSSY")==0)
|
|
|
|
return SHADER_EVAL_GLOSSY;
|
|
|
|
else if(strcmp(shader_type, "TRANSMISSION")==0)
|
|
|
|
return SHADER_EVAL_TRANSMISSION;
|
|
|
|
else if(strcmp(shader_type, "SUBSURFACE")==0)
|
|
|
|
return SHADER_EVAL_SUBSURFACE;
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
/* extra */
|
|
|
|
else if(strcmp(shader_type, "ENVIRONMENT")==0)
|
|
|
|
return SHADER_EVAL_ENVIRONMENT;
|
|
|
|
|
|
|
|
else
|
|
|
|
return SHADER_EVAL_BAKE;
|
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static BL::RenderResult begin_render_result(BL::RenderEngine& b_engine,
|
|
|
|
int x, int y,
|
|
|
|
int w, int h,
|
|
|
|
const char *layername,
|
|
|
|
const char *viewname)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2015-04-06 10:40:12 -03:00
|
|
|
return b_engine.begin_result(x, y, w, h, layername, viewname);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static void end_render_result(BL::RenderEngine& b_engine,
|
|
|
|
BL::RenderResult& b_rr,
|
|
|
|
bool cancel,
|
|
|
|
bool do_merge_results)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2013-12-17 23:42:38 +06:00
|
|
|
b_engine.end_result(b_rr, (int)cancel, (int)do_merge_results);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2015-04-06 10:40:12 -03:00
|
|
|
BL::RenderResult b_rr = begin_render_result(b_engine, x, y, w, h, b_rlay_name.c_str(), b_rview_name.c_str());
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
/* can happen if the intersected rectangle gives 0 width or height */
|
2015-03-28 00:15:15 +05:00
|
|
|
if(b_rr.ptr.data == NULL) {
|
2012-09-04 13:29:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BL::RenderResult::layers_iterator b_single_rlay;
|
|
|
|
b_rr.layers.begin(b_single_rlay);
|
2013-07-29 15:32:24 +00:00
|
|
|
|
|
|
|
/* layer will be missing if it was disabled in the UI */
|
|
|
|
if(b_single_rlay == b_rr.layers.end())
|
|
|
|
return;
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
BL::RenderLayer b_rlay = *b_single_rlay;
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if(do_update_only) {
|
2012-09-04 13:29:07 +00:00
|
|
|
/* update only needed */
|
2013-01-01 16:15:13 +00:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if(rtile.sample != 0) {
|
2013-01-01 16:15:13 +00:00
|
|
|
/* sample would be zero at initial tile update, which is only needed
|
|
|
|
* to tag tile form blender side as IN PROGRESS for proper highlight
|
|
|
|
* no buffers should be sent to blender yet
|
|
|
|
*/
|
|
|
|
update_render_result(b_rr, b_rlay, rtile);
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:42:38 +06:00
|
|
|
end_render_result(b_engine, b_rr, true, true);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* write result */
|
|
|
|
write_render_result(b_rr, b_rlay, rtile);
|
2013-12-17 23:42:38 +06:00
|
|
|
end_render_result(b_engine, b_rr, false, true);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlenderSession::write_render_tile(RenderTile& rtile)
|
|
|
|
{
|
|
|
|
do_write_update_render_tile(rtile, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlenderSession::update_render_tile(RenderTile& rtile)
|
|
|
|
{
|
2013-01-28 17:37:51 +00:00
|
|
|
/* use final write for preview renders, otherwise render result wouldn't be
|
|
|
|
* be updated in blender side
|
|
|
|
* would need to be investigated a bit further, but for now shall be fine
|
|
|
|
*/
|
2015-03-28 00:15:15 +05:00
|
|
|
if(!b_engine.is_preview())
|
2013-01-28 17:37:51 +00:00
|
|
|
do_write_update_render_tile(rtile, true);
|
|
|
|
else
|
|
|
|
do_write_update_render_tile(rtile, false);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
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 */
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, 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();
|
2015-04-06 10:40:12 -03:00
|
|
|
BL::RenderSettings::layers_iterator b_layer_iter;
|
|
|
|
BL::RenderResult::views_iterator b_view_iter;
|
2011-12-21 20:51:55 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
for(r.layers.begin(b_layer_iter); b_layer_iter != r.layers.end(); ++b_layer_iter) {
|
|
|
|
b_rlay_name = b_layer_iter->name();
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* temporary render result to find needed passes and views */
|
|
|
|
BL::RenderResult b_rr = begin_render_result(b_engine, 0, 0, 1, 1, b_rlay_name.c_str(), NULL);
|
2012-09-04 13:29:07 +00:00
|
|
|
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()) {
|
2013-12-17 23:42:38 +06:00
|
|
|
end_render_result(b_engine, b_rr, true, false);
|
2012-09-04 13:29:07 +00:00
|
|
|
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 */
|
2016-05-07 20:30:16 +02:00
|
|
|
array<Pass> passes;
|
2012-01-26 14:55:25 +00:00
|
|
|
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-01-26 14:55:25 +00:00
|
|
|
buffer_params.passes = passes;
|
2015-04-06 10:40:12 -03:00
|
|
|
scene->film->pass_alpha_threshold = b_layer_iter->pass_alpha_threshold();
|
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
|
|
|
|
2016-11-18 18:23:45 +01:00
|
|
|
int view_index = 0;
|
|
|
|
for(b_rr.views.begin(b_view_iter); b_view_iter != b_rr.views.end(); ++b_view_iter, ++view_index) {
|
2015-04-06 10:40:12 -03:00
|
|
|
b_rview_name = b_view_iter->name();
|
2011-12-21 20:51:55 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* set the current view */
|
|
|
|
b_engine.active_view_set(b_rview_name.c_str());
|
2013-04-16 16:18:14 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
/* update scene */
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, b_rview_name.c_str());
|
2015-07-21 15:36:35 +02:00
|
|
|
sync->sync_data(b_render,
|
|
|
|
b_v3d,
|
2016-01-30 14:18:29 +01:00
|
|
|
b_camera_override,
|
2015-07-21 15:36:35 +02:00
|
|
|
width, height,
|
|
|
|
&python_thread_state,
|
|
|
|
b_rlay_name.c_str());
|
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
|
|
|
|
2016-11-18 18:23:45 +01:00
|
|
|
/* Make sure all views have different noise patterns. - hardcoded value just to make it random */
|
|
|
|
if(view_index != 0) {
|
|
|
|
scene->integrator->seed += hash_int_2d(scene->integrator->seed, hash_int(view_index * 0xdeadbeef));
|
|
|
|
scene->integrator->tag_update(scene);
|
|
|
|
}
|
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
/* Update number of samples per layer. */
|
2015-04-06 10:40:12 -03:00
|
|
|
int samples = sync->get_layer_samples();
|
|
|
|
bool bound_samples = sync->get_layer_bound_samples();
|
2016-03-30 15:55:12 +02:00
|
|
|
int effective_layer_samples;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
if(samples != 0 && (!bound_samples || (samples < session_params.samples)))
|
2016-03-30 15:55:12 +02:00
|
|
|
effective_layer_samples = samples;
|
2015-04-06 10:40:12 -03:00
|
|
|
else
|
2016-03-30 15:55:12 +02:00
|
|
|
effective_layer_samples = session_params.samples;
|
|
|
|
|
|
|
|
/* Update tile manager if we're doing resumable render. */
|
|
|
|
update_resumable_tile_manager(effective_layer_samples);
|
|
|
|
|
|
|
|
/* Update session itself. */
|
|
|
|
session->reset(buffer_params, effective_layer_samples);
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
/* render */
|
|
|
|
session->start();
|
|
|
|
session->wait();
|
|
|
|
|
|
|
|
if(session->progress.get_cancel())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free result without merging */
|
|
|
|
end_render_result(b_engine, b_rr, true, false);
|
2011-12-21 20:51:55 +00:00
|
|
|
|
|
|
|
if(session->progress.get_cancel())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-17 11:56:19 +02:00
|
|
|
double total_time, render_time;
|
|
|
|
session->progress.get_time(total_time, render_time);
|
|
|
|
VLOG(1) << "Total render time: " << total_time;
|
|
|
|
VLOG(1) << "Render time (without synchronization): " << render_time;
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* clear callback */
|
2015-03-30 15:06:20 +05:00
|
|
|
session->write_render_tile_cb = function_null;
|
|
|
|
session->update_render_tile_cb = function_null;
|
2012-11-09 08:46:53 +00:00
|
|
|
|
|
|
|
/* free all memory used (host and device), so we wouldn't leave render
|
|
|
|
* engine with extra memory allocated
|
|
|
|
*/
|
|
|
|
|
|
|
|
session->device_free();
|
|
|
|
|
|
|
|
delete sync;
|
|
|
|
sync = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static void populate_bake_data(BakeData *data, const
|
|
|
|
int object_id,
|
|
|
|
BL::BakePixel& pixel_array,
|
|
|
|
const int num_pixels)
|
2014-01-02 19:05:07 -02:00
|
|
|
{
|
|
|
|
BL::BakePixel bp = pixel_array;
|
|
|
|
|
|
|
|
int i;
|
2017-01-11 15:16:22 +01:00
|
|
|
for(i = 0; i < num_pixels; i++) {
|
2015-04-17 12:25:37 -03:00
|
|
|
if(bp.object_id() == object_id) {
|
|
|
|
data->set(i, bp.primitive_id(), bp.uv(), bp.du_dx(), bp.du_dy(), bp.dv_dx(), bp.dv_dy());
|
|
|
|
} else {
|
|
|
|
data->set_null(i);
|
|
|
|
}
|
2014-01-02 19:05:07 -02:00
|
|
|
bp = bp.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
static int bake_pass_filter_get(const int pass_filter)
|
|
|
|
{
|
|
|
|
int flag = BAKE_FILTER_NONE;
|
|
|
|
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_DIRECT) != 0)
|
|
|
|
flag |= BAKE_FILTER_DIRECT;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_INDIRECT) != 0)
|
|
|
|
flag |= BAKE_FILTER_INDIRECT;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_COLOR) != 0)
|
|
|
|
flag |= BAKE_FILTER_COLOR;
|
|
|
|
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_DIFFUSE) != 0)
|
|
|
|
flag |= BAKE_FILTER_DIFFUSE;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_GLOSSY) != 0)
|
|
|
|
flag |= BAKE_FILTER_GLOSSY;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_TRANSMISSION) != 0)
|
|
|
|
flag |= BAKE_FILTER_TRANSMISSION;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_SUBSURFACE) != 0)
|
|
|
|
flag |= BAKE_FILTER_SUBSURFACE;
|
|
|
|
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_EMIT) != 0)
|
|
|
|
flag |= BAKE_FILTER_EMISSION;
|
|
|
|
if((pass_filter & BL::BakeSettings::pass_filter_AO) != 0)
|
|
|
|
flag |= BAKE_FILTER_AO;
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
void BlenderSession::bake(BL::Object& b_object,
|
2016-01-15 13:00:56 -02:00
|
|
|
const string& pass_type,
|
|
|
|
const int pass_filter,
|
|
|
|
const int object_id,
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::BakePixel& pixel_array,
|
2016-01-15 13:00:56 -02:00
|
|
|
const size_t num_pixels,
|
|
|
|
const int /*depth*/,
|
|
|
|
float result[])
|
2014-01-02 19:05:07 -02:00
|
|
|
{
|
|
|
|
ShaderEvalType shader_type = get_shader_type(pass_type);
|
|
|
|
size_t object_index = OBJECT_NONE;
|
|
|
|
int tri_offset = 0;
|
|
|
|
|
2015-07-18 15:34:32 +02:00
|
|
|
/* Set baking flag in advance, so kernel loading can check if we need
|
|
|
|
* any baking capabilities.
|
|
|
|
*/
|
|
|
|
scene->bake_manager->set_baking(true);
|
|
|
|
|
2014-05-19 19:17:57 +02:00
|
|
|
/* ensure kernels are loaded before we do any scene updates */
|
|
|
|
session->load_kernels();
|
|
|
|
|
|
|
|
if(session->progress.get_cancel())
|
|
|
|
return;
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
if(shader_type == SHADER_EVAL_UV) {
|
|
|
|
/* force UV to be available */
|
|
|
|
Pass::add(PASS_UV, scene->film->passes);
|
|
|
|
}
|
|
|
|
|
2016-02-06 20:35:36 +01:00
|
|
|
int bake_pass_filter = bake_pass_filter_get(pass_filter);
|
|
|
|
bake_pass_filter = BakeManager::shader_type_to_pass_filter(shader_type, bake_pass_filter);
|
|
|
|
|
|
|
|
/* force use_light_pass to be true if we bake more than just colors */
|
2016-04-13 08:58:52 +02:00
|
|
|
if(bake_pass_filter & ~BAKE_FILTER_COLOR) {
|
2014-01-02 19:05:07 -02:00
|
|
|
Pass::add(PASS_LIGHT, scene->film->passes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create device and update scene */
|
|
|
|
scene->film->tag_update(scene);
|
|
|
|
scene->integrator->tag_update(scene);
|
|
|
|
|
|
|
|
/* update scene */
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
2015-07-21 15:36:35 +02:00
|
|
|
sync->sync_data(b_render,
|
|
|
|
b_v3d,
|
2016-01-30 14:18:29 +01:00
|
|
|
b_camera_override,
|
2015-07-21 15:36:35 +02:00
|
|
|
width, height,
|
|
|
|
&python_thread_state,
|
|
|
|
b_rlay_name.c_str());
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
/* get buffer parameters */
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
|
2014-01-02 19:05:07 -02:00
|
|
|
|
2014-07-31 20:04:57 -03:00
|
|
|
scene->bake_manager->set_shader_limit((size_t)b_engine.tile_x(), (size_t)b_engine.tile_y());
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
/* set number of samples */
|
|
|
|
session->tile_manager.set_samples(session_params.samples);
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
|
|
|
session->update_scene();
|
|
|
|
|
|
|
|
/* find object index. todo: is arbitrary - copied from mesh_displace.cpp */
|
|
|
|
for(size_t i = 0; i < scene->objects.size(); i++) {
|
|
|
|
if(strcmp(scene->objects[i]->name.c_str(), b_object.name().c_str()) == 0) {
|
|
|
|
object_index = i;
|
|
|
|
tri_offset = scene->objects[i]->mesh->tri_offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:37:17 -04:00
|
|
|
int object = object_index;
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
BakeData *bake_data = scene->bake_manager->init(object, tri_offset, num_pixels);
|
|
|
|
|
2015-04-17 12:25:37 -03:00
|
|
|
populate_bake_data(bake_data, object_id, pixel_array, num_pixels);
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
/* set number of samples */
|
|
|
|
session->tile_manager.set_samples(session_params.samples);
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
|
|
|
session->update_scene();
|
|
|
|
|
2014-07-22 18:41:01 -03:00
|
|
|
session->progress.set_update_callback(function_bind(&BlenderSession::update_bake_progress, this));
|
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
scene->bake_manager->bake(scene->device, &scene->dscene, scene, session->progress, shader_type, bake_pass_filter, bake_data, result);
|
2014-01-02 19:05:07 -02:00
|
|
|
|
|
|
|
/* free all memory used (host and device), so we wouldn't leave render
|
|
|
|
* engine with extra memory allocated
|
|
|
|
*/
|
|
|
|
|
|
|
|
session->device_free();
|
|
|
|
|
|
|
|
delete sync;
|
|
|
|
sync = NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01: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
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
/* Adjust absolute sample number to the range. */
|
|
|
|
int sample = rtile.sample;
|
|
|
|
const int range_start_sample = session->tile_manager.range_start_sample;
|
|
|
|
if(range_start_sample != -1) {
|
|
|
|
sample -= range_start_sample;
|
|
|
|
}
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if(!do_update_only) {
|
2012-09-04 13:29:07 +00:00
|
|
|
/* 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 */
|
2016-03-30 15:55:12 +02:00
|
|
|
if(!buffers->get_pass_rect(pass_type, exposure, sample, components, &pixels[0]))
|
2013-02-10 18:02:59 +00:00
|
|
|
memset(&pixels[0], 0, pixels.size()*sizeof(float));
|
|
|
|
|
|
|
|
b_pass.rect(&pixels[0]);
|
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
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
else {
|
|
|
|
/* copy combined pass */
|
2015-04-08 15:35:01 +05:00
|
|
|
BL::RenderPass b_combined_pass(b_rlay.passes.find_by_type(BL::RenderPass::type_COMBINED, b_rview_name.c_str()));
|
2016-03-30 15:55:12 +02:00
|
|
|
if(buffers->get_pass_rect(PASS_COMBINED, exposure, sample, 4, &pixels[0]))
|
2015-04-06 10:40:12 -03:00
|
|
|
b_combined_pass.rect(&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
|
|
|
|
|
|
|
/* tag result as updated */
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.update_result(b_rr);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
void BlenderSession::write_render_result(BL::RenderResult& b_rr,
|
|
|
|
BL::RenderLayer& b_rlay,
|
|
|
|
RenderTile& rtile)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
|
|
|
do_write_update_render_result(b_rr, b_rlay, rtile, false);
|
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
void BlenderSession::update_render_result(BL::RenderResult& b_rr,
|
|
|
|
BL::RenderLayer& b_rlay,
|
|
|
|
RenderTile& rtile)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
|
|
|
do_write_update_render_result(b_rr, b_rlay, rtile, true);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::synchronize()
|
|
|
|
{
|
2013-06-09 11:57:51 +00:00
|
|
|
/* only used for viewport render */
|
|
|
|
if(!b_v3d)
|
|
|
|
return;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* on session/scene parameter changes, we recreate session entirely */
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2014-12-25 00:53:26 +05:00
|
|
|
const bool is_cpu = session_params.device.type == DEVICE_CPU;
|
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(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);
|
2014-08-01 16:39:05 +06:00
|
|
|
session->set_pause(session_pause);
|
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();
|
|
|
|
|
2014-08-01 16:39:05 +06:00
|
|
|
/* don't do synchronization if on pause */
|
|
|
|
if(session_pause) {
|
|
|
|
tag_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* 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 */
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
2015-07-21 15:36:35 +02:00
|
|
|
sync->sync_data(b_render,
|
|
|
|
b_v3d,
|
2016-01-30 14:18:29 +01:00
|
|
|
b_camera_override,
|
2015-07-21 15:36:35 +02:00
|
|
|
width, height,
|
|
|
|
&python_thread_state,
|
|
|
|
b_rlay_name.c_str());
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(b_rv3d)
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
|
|
|
else
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
sync->sync_camera(b_render, b_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()) {
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
|
2011-12-20 12:25:37 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2013-04-24 20:12:12 +00:00
|
|
|
|
|
|
|
/* reset time */
|
|
|
|
start_resize_time = 0.0;
|
2011-12-20 12:25:37 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BlenderSession::draw(int w, int h)
|
|
|
|
{
|
2013-04-28 12:31:24 +00:00
|
|
|
/* pause in redraw in case update is not being called due to final render */
|
|
|
|
session->set_pause(BlenderSync::get_session_pause(b_scene, background));
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* 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;
|
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
/* if dimensions changed, reset */
|
|
|
|
if(width != w || height != h) {
|
|
|
|
if(start_resize_time == 0.0) {
|
|
|
|
/* don't react immediately to resizes to avoid flickery resizing
|
|
|
|
* of the viewport, and some window managers changing the window
|
|
|
|
* size temporarily on unminimize */
|
|
|
|
start_resize_time = time_dt();
|
|
|
|
tag_redraw();
|
|
|
|
}
|
2013-05-16 17:20:56 +00:00
|
|
|
else if(time_dt() - start_resize_time < 0.2) {
|
2013-04-24 20:12:12 +00:00
|
|
|
tag_redraw();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
width = w;
|
|
|
|
height = h;
|
|
|
|
reset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* 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 */
|
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-02-05 14:16:19 +00:00
|
|
|
if(scene->camera->need_update)
|
2011-04-27 11:58:34 +00:00
|
|
|
reset = true;
|
|
|
|
|
|
|
|
session->scene->mutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset if requested */
|
2011-08-28 13:55:59 +00:00
|
|
|
if(reset) {
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(b_scene, background);
|
2011-12-20 12:25:37 +00:00
|
|
|
|
2014-08-01 16:39:05 +06:00
|
|
|
if(session_pause == false) {
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
|
|
|
start_resize_time = 0.0;
|
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-02-15 09:15:14 +00:00
|
|
|
else {
|
|
|
|
tag_update();
|
|
|
|
}
|
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 */
|
2015-03-27 15:47:55 +05:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_v3d, b_rv3d, scene->camera, width, height);
|
2014-03-26 14:57:30 +06:00
|
|
|
DeviceDrawParams draw_params;
|
2011-12-20 12:25:37 +00:00
|
|
|
|
2014-03-26 14:57:30 +06:00
|
|
|
if(session->params.display_buffer_linear) {
|
|
|
|
draw_params.bind_display_space_shader_cb = function_bind(&BL::RenderEngine::bind_display_space_shader, &b_engine, b_scene);
|
|
|
|
draw_params.unbind_display_space_shader_cb = function_bind(&BL::RenderEngine::unbind_display_space_shader, &b_engine);
|
|
|
|
}
|
2013-08-30 23:49:38 +00:00
|
|
|
|
2014-03-26 14:57:30 +06:00
|
|
|
return !session->draw(buffer_params, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlenderSession::get_status(string& status, string& substatus)
|
|
|
|
{
|
|
|
|
session->progress.get_status(status, substatus);
|
|
|
|
}
|
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
void BlenderSession::get_progress(float& progress, double& total_time, double& render_time)
|
2011-08-22 13:17:43 +00: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
|
|
|
session->progress.get_time(total_time, render_time);
|
|
|
|
progress = session->progress.get_progress();
|
2011-08-22 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 18:41:01 -03:00
|
|
|
void BlenderSession::update_bake_progress()
|
|
|
|
{
|
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
|
|
|
float progress = session->progress.get_progress();
|
2014-07-22 18:41:01 -03:00
|
|
|
|
|
|
|
if(progress != last_progress) {
|
|
|
|
b_engine.update_progress(progress);
|
|
|
|
last_progress = progress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2013-12-07 02:22:35 +01:00
|
|
|
string scene = "";
|
2011-08-22 13:17:43 +00:00
|
|
|
float progress;
|
2015-01-14 23:06:10 +05:00
|
|
|
double total_time, remaining_time = 0, render_time;
|
2011-08-22 13:17:43 +00:00
|
|
|
char time_str[128];
|
2012-11-05 08:04:57 +00:00
|
|
|
float mem_used = (float)session->stats.mem_used / 1024.0f / 1024.0f;
|
|
|
|
float mem_peak = (float)session->stats.mem_peak / 1024.0f / 1024.0f;
|
2011-08-22 13:17:43 +00:00
|
|
|
|
|
|
|
get_status(status, substatus);
|
2015-01-14 23:06:10 +05:00
|
|
|
get_progress(progress, total_time, render_time);
|
2011-08-22 13:17:43 +00:00
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
if(progress > 0)
|
|
|
|
remaining_time = (1.0 - (double)progress) * (render_time / (double)progress);
|
2013-12-07 02:22:35 +01:00
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
if(background) {
|
2013-12-07 02:22:35 +01:00
|
|
|
scene += " | " + b_scene.name();
|
2013-06-24 22:41:24 +00:00
|
|
|
if(b_rlay_name != "")
|
2013-12-07 02:22:35 +01:00
|
|
|
scene += ", " + b_rlay_name;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
if(b_rview_name != "")
|
|
|
|
scene += ", " + b_rview_name;
|
2013-06-24 22:41:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-06-30 14:47:31 +10:00
|
|
|
BLI_timecode_string_from_time_simple(time_str, sizeof(time_str), total_time);
|
2013-12-07 02:22:35 +01:00
|
|
|
timestatus = "Time:" + string(time_str) + " | ";
|
2013-06-24 22:41:24 +00:00
|
|
|
}
|
2014-12-05 19:28:09 +05:00
|
|
|
|
|
|
|
if(remaining_time > 0) {
|
2015-06-30 14:47:31 +10:00
|
|
|
BLI_timecode_string_from_time_simple(time_str, sizeof(time_str), remaining_time);
|
2013-12-07 02:22:35 +01:00
|
|
|
timestatus += "Remaining:" + string(time_str) + " | ";
|
|
|
|
}
|
2014-12-05 19:28:09 +05:00
|
|
|
|
2014-10-08 00:09:36 +02:00
|
|
|
timestatus += string_printf("Mem:%.2fM, Peak:%.2fM", (double)mem_used, (double)mem_peak);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-06-24 22:41:24 +00:00
|
|
|
if(status.size() > 0)
|
|
|
|
status = " | " + status;
|
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) {
|
2014-02-11 16:26:08 +01:00
|
|
|
b_engine.update_stats("", (timestatus + scene + status).c_str());
|
2012-11-05 08:04:57 +00:00
|
|
|
b_engine.update_memory_stats(mem_used, mem_peak);
|
2011-10-30 10:12:34 +00:00
|
|
|
last_status = status;
|
|
|
|
}
|
|
|
|
if(progress != last_progress) {
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.update_progress(progress);
|
2011-10-30 10:12:34 +00:00
|
|
|
last_progress = progress;
|
|
|
|
}
|
2014-12-05 21:27:52 +05:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if(session->progress.get_error()) {
|
2014-12-05 21:27:52 +05:00
|
|
|
string error = session->progress.get_error_message();
|
|
|
|
if(error != last_error) {
|
|
|
|
/* TODO(sergey): Currently C++ RNA API doesn't let us to
|
|
|
|
* use mnemonic name for the variable. Would be nice to
|
|
|
|
* have this figured out.
|
|
|
|
*
|
|
|
|
* For until then, 1 << 5 means RPT_ERROR.
|
|
|
|
*/
|
|
|
|
b_engine.report(1 << 5, error.c_str());
|
2014-12-05 22:00:39 +05:00
|
|
|
b_engine.error_set(error.c_str());
|
2014-12-05 21:27:52 +05:00
|
|
|
last_error = error;
|
|
|
|
}
|
|
|
|
}
|
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 */
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_update();
|
2011-08-23 12:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_redraw();
|
2011-04-27 11:58:34 +00:00
|
|
|
last_redraw_time = time_dt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* tell blender that we want to redraw */
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_redraw();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlenderSession::test_cancel()
|
|
|
|
{
|
|
|
|
/* test if we need to cancel rendering */
|
|
|
|
if(background)
|
2012-10-22 17:34:16 +00:00
|
|
|
if(b_engine.test_break())
|
2011-04-27 11:58:34 +00:00
|
|
|
session->progress.set_cancel("Cancelled");
|
|
|
|
}
|
|
|
|
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
/* builtin image file name is actually an image datablock name with
|
|
|
|
* absolute sequence frame number concatenated via '@' character
|
|
|
|
*
|
2013-01-30 13:42:12 +00:00
|
|
|
* this function splits frame from builtin name
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
*/
|
2013-01-30 13:42:12 +00:00
|
|
|
int BlenderSession::builtin_image_frame(const string &builtin_name)
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
{
|
|
|
|
int last = builtin_name.find_last_of('@');
|
2013-01-30 13:42:12 +00:00
|
|
|
return atoi(builtin_name.substr(last + 1, builtin_name.size() - last - 1).c_str());
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
void BlenderSession::builtin_image_info(const string &builtin_name,
|
|
|
|
void *builtin_data,
|
|
|
|
bool &is_float,
|
|
|
|
int &width,
|
|
|
|
int &height,
|
|
|
|
int &depth,
|
|
|
|
int &channels)
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
{
|
2014-03-29 13:03:48 +01:00
|
|
|
/* empty image */
|
|
|
|
is_float = false;
|
2016-04-12 13:02:05 +02:00
|
|
|
width = 1;
|
|
|
|
height = 1;
|
2014-03-29 13:03:48 +01:00
|
|
|
depth = 0;
|
|
|
|
channels = 0;
|
|
|
|
|
|
|
|
if(!builtin_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* recover ID pointer */
|
2013-01-30 13:42:12 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_id_pointer_create((ID*)builtin_data, &ptr);
|
2014-03-29 13:03:48 +01:00
|
|
|
BL::ID b_id(ptr);
|
|
|
|
|
|
|
|
if(b_id.is_a(&RNA_Image)) {
|
|
|
|
/* image data */
|
|
|
|
BL::Image b_image(b_id);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
|
|
|
is_float = b_image.is_float();
|
|
|
|
width = b_image.size()[0];
|
|
|
|
height = b_image.size()[1];
|
2014-03-29 13:03:48 +01:00
|
|
|
depth = 1;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
channels = b_image.channels();
|
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
else if(b_id.is_a(&RNA_Object)) {
|
|
|
|
/* smoke volume data */
|
|
|
|
BL::Object b_ob(b_id);
|
|
|
|
BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
|
|
|
|
|
2016-04-12 13:02:05 +02:00
|
|
|
is_float = true;
|
|
|
|
depth = 1;
|
|
|
|
channels = 1;
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
if(!b_domain)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY) ||
|
2016-04-15 12:02:31 +02:00
|
|
|
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME) ||
|
|
|
|
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT))
|
2014-03-29 13:03:48 +01:00
|
|
|
channels = 1;
|
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR))
|
|
|
|
channels = 4;
|
2016-04-12 13:25:20 +02:00
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY))
|
|
|
|
channels = 3;
|
2014-03-29 13:03:48 +01:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
int3 resolution = get_int3(b_domain.domain_resolution());
|
|
|
|
int amplify = (b_domain.use_high_resolution())? b_domain.amplify() + 1: 1;
|
|
|
|
|
2016-04-15 12:02:31 +02:00
|
|
|
/* Velocity and heat data is always low-resolution. */
|
|
|
|
if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY) ||
|
|
|
|
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT))
|
|
|
|
{
|
|
|
|
amplify = 1;
|
|
|
|
}
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
width = resolution.x * amplify;
|
|
|
|
height = resolution.y * amplify;
|
|
|
|
depth = resolution.z * amplify;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2015-07-18 22:36:09 +02:00
|
|
|
else {
|
|
|
|
/* TODO(sergey): Check we're indeed in shader node tree. */
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Node, builtin_data, &ptr);
|
|
|
|
BL::Node b_node(ptr);
|
|
|
|
if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
|
|
|
|
BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
|
|
|
|
channels = 4;
|
|
|
|
width = height = depth = b_point_density_node.resolution();
|
|
|
|
is_float = true;
|
|
|
|
}
|
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
bool BlenderSession::builtin_image_pixels(const string &builtin_name,
|
|
|
|
void *builtin_data,
|
|
|
|
unsigned char *pixels,
|
|
|
|
const size_t pixels_size)
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
{
|
2016-11-29 11:03:11 +01:00
|
|
|
if(!builtin_data) {
|
2014-03-29 13:03:48 +01:00
|
|
|
return false;
|
2016-11-29 11:03:11 +01:00
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
const int frame = builtin_image_frame(builtin_name);
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_id_pointer_create((ID*)builtin_data, &ptr);
|
|
|
|
BL::Image b_image(ptr);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
const int width = b_image.size()[0];
|
|
|
|
const int height = b_image.size()[1];
|
|
|
|
const int channels = b_image.channels();
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
unsigned char *image_pixels = image_get_pixels_for_frame(b_image, frame);
|
|
|
|
const size_t num_pixels = ((size_t)width) * height;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
if(image_pixels && num_pixels * channels == pixels_size) {
|
|
|
|
memcpy(pixels, image_pixels, pixels_size * sizeof(unsigned char));
|
2014-03-29 13:03:48 +01:00
|
|
|
MEM_freeN(image_pixels);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(channels == 1) {
|
2016-11-29 11:03:11 +01:00
|
|
|
memset(pixels, 0, pixels_size * sizeof(unsigned char));
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-11-29 11:03:11 +01:00
|
|
|
const size_t num_pixels_safe = pixels_size / channels;
|
2014-03-29 13:03:48 +01:00
|
|
|
unsigned char *cp = pixels;
|
2016-11-29 11:03:11 +01:00
|
|
|
for(size_t i = 0; i < num_pixels_safe; i++, cp += channels) {
|
2014-03-29 13:03:48 +01:00
|
|
|
cp[0] = 255;
|
|
|
|
cp[1] = 0;
|
|
|
|
cp[2] = 255;
|
2016-11-29 11:03:11 +01:00
|
|
|
if(channels == 4) {
|
2014-03-29 13:03:48 +01:00
|
|
|
cp[3] = 255;
|
2016-11-29 11:03:11 +01:00
|
|
|
}
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
}
|
2016-11-29 11:03:11 +01:00
|
|
|
/* Premultiply, byte images are always straight for Blender. */
|
2014-03-29 13:03:48 +01:00
|
|
|
unsigned char *cp = pixels;
|
2015-05-12 18:33:31 +05:00
|
|
|
for(size_t i = 0; i < num_pixels; i++, cp += channels) {
|
2014-03-29 13:03:48 +01:00
|
|
|
cp[0] = (cp[0] * cp[3]) >> 8;
|
|
|
|
cp[1] = (cp[1] * cp[3]) >> 8;
|
|
|
|
cp[2] = (cp[2] * cp[3]) >> 8;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
return true;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
|
|
|
|
void *builtin_data,
|
|
|
|
float *pixels,
|
|
|
|
const size_t pixels_size)
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
{
|
2016-11-29 11:03:11 +01:00
|
|
|
if(!builtin_data) {
|
2014-03-29 13:03:48 +01:00
|
|
|
return false;
|
2016-11-29 11:03:11 +01:00
|
|
|
}
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
|
2013-01-30 13:42:12 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_id_pointer_create((ID*)builtin_data, &ptr);
|
2014-03-29 13:03:48 +01:00
|
|
|
BL::ID b_id(ptr);
|
|
|
|
|
|
|
|
if(b_id.is_a(&RNA_Image)) {
|
|
|
|
/* image data */
|
|
|
|
BL::Image b_image(b_id);
|
|
|
|
int frame = builtin_image_frame(builtin_name);
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
const int width = b_image.size()[0];
|
|
|
|
const int height = b_image.size()[1];
|
|
|
|
const int channels = b_image.channels();
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
float *image_pixels;
|
|
|
|
image_pixels = image_get_float_pixels_for_frame(b_image, frame);
|
2016-11-29 11:03:11 +01:00
|
|
|
const size_t num_pixels = ((size_t)width) * height;
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
if(image_pixels && num_pixels * channels == pixels_size) {
|
|
|
|
memcpy(pixels, image_pixels, pixels_size * sizeof(float));
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
MEM_freeN(image_pixels);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(channels == 1) {
|
2015-05-12 18:33:31 +05:00
|
|
|
memset(pixels, 0, num_pixels * sizeof(float));
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-11-29 11:03:11 +01:00
|
|
|
const size_t num_pixels_safe = pixels_size / channels;
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
float *fp = pixels;
|
2016-11-29 11:03:11 +01:00
|
|
|
for(int i = 0; i < num_pixels_safe; i++, fp += channels) {
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
fp[0] = 1.0f;
|
|
|
|
fp[1] = 0.0f;
|
|
|
|
fp[2] = 1.0f;
|
2016-11-29 11:03:11 +01:00
|
|
|
if(channels == 4) {
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
fp[3] = 1.0f;
|
2016-11-29 11:03:11 +01:00
|
|
|
}
|
Movies support for Cycles
This adds support of movie textures for Cycles rendering.
Uses the same builtin images routines as packed/generated images,
but with some extra non-rna hookups from blender_session side.
Basically, it's not so clear how to give access to video frames
via C++ RNA -- it'll require exposing ImBuf to API, doing some
threading locks and so. Ended up adding two more functions which
are actually bad level call, but don't consider it's so much bad
-- we have few bad calls already, which are actually related.
Changed a bit how builtin images names are passing to image
manager. Now it's not just an ID datablock name, but also a frame
number concatenated via '@' character, which makes itpossible to
easily know frame number to be used for movie images, without
adding extra descriptors to image manager.
Decoding of builtin name is a bit slower now, but it should be
still nothing in comparison with rendering complexity.
Also exposed image user's frame_current to python API, which
is needed to get absolute frame number of movie from node's
image user.
P.S. Generated/packed images are also using bad level call but
only does it to make things more clear here. Either all images
are using C++ RNA here or no images does. That's the most clear
for now.
2013-01-16 17:07:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
else if(b_id.is_a(&RNA_Object)) {
|
|
|
|
/* smoke volume data */
|
|
|
|
BL::Object b_ob(b_id);
|
|
|
|
BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
|
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
if(!b_domain) {
|
2014-03-29 13:03:48 +01:00
|
|
|
return false;
|
2016-11-29 11:03:11 +01:00
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
int3 resolution = get_int3(b_domain.domain_resolution());
|
|
|
|
int length, amplify = (b_domain.use_high_resolution())? b_domain.amplify() + 1: 1;
|
|
|
|
|
2016-04-15 12:02:31 +02:00
|
|
|
/* Velocity and heat data is always low-resolution. */
|
|
|
|
if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY) ||
|
|
|
|
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT))
|
|
|
|
{
|
2016-04-12 13:25:20 +02:00
|
|
|
amplify = 1;
|
|
|
|
}
|
|
|
|
|
2016-11-29 11:03:11 +01:00
|
|
|
const int width = resolution.x * amplify;
|
|
|
|
const int height = resolution.y * amplify;
|
|
|
|
const int depth = resolution.z * amplify;
|
|
|
|
const size_t num_pixels = ((size_t)width) * height * depth;
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY)) {
|
|
|
|
SmokeDomainSettings_density_grid_get_length(&b_domain.ptr, &length);
|
2015-05-12 18:33:31 +05:00
|
|
|
if(length == num_pixels) {
|
2014-03-29 13:03:48 +01:00
|
|
|
SmokeDomainSettings_density_grid_get(&b_domain.ptr, pixels);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME)) {
|
|
|
|
/* this is in range 0..1, and interpreted by the OpenGL smoke viewer
|
|
|
|
* as 1500..3000 K with the first part faded to zero density */
|
|
|
|
SmokeDomainSettings_flame_grid_get_length(&b_domain.ptr, &length);
|
2015-05-12 18:33:31 +05:00
|
|
|
if(length == num_pixels) {
|
2014-03-29 13:03:48 +01:00
|
|
|
SmokeDomainSettings_flame_grid_get(&b_domain.ptr, pixels);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR)) {
|
|
|
|
/* the RGB is "premultiplied" by density for better interpolation results */
|
|
|
|
SmokeDomainSettings_color_grid_get_length(&b_domain.ptr, &length);
|
2015-05-12 18:33:31 +05:00
|
|
|
if(length == num_pixels*4) {
|
2014-03-29 13:03:48 +01:00
|
|
|
SmokeDomainSettings_color_grid_get(&b_domain.ptr, pixels);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 13:25:20 +02:00
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) {
|
|
|
|
SmokeDomainSettings_velocity_grid_get_length(&b_domain.ptr, &length);
|
|
|
|
if(length == num_pixels*3) {
|
|
|
|
SmokeDomainSettings_velocity_grid_get(&b_domain.ptr, pixels);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-04-15 12:02:31 +02:00
|
|
|
else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT)) {
|
|
|
|
SmokeDomainSettings_heat_grid_get_length(&b_domain.ptr, &length);
|
|
|
|
if(length == num_pixels) {
|
|
|
|
SmokeDomainSettings_heat_grid_get(&b_domain.ptr, pixels);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 13:02:05 +02:00
|
|
|
else {
|
2016-04-15 11:24:59 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Cycles error: unknown volume attribute %s, skipping\n",
|
|
|
|
builtin_name.c_str());
|
2016-04-12 13:02:05 +02:00
|
|
|
pixels[0] = 0.0f;
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "Cycles error: unexpected smoke volume resolution, skipping\n");
|
|
|
|
}
|
2015-07-18 22:36:09 +02:00
|
|
|
else {
|
|
|
|
/* TODO(sergey): Check we're indeed in shader node tree. */
|
|
|
|
PointerRNA ptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Node, builtin_data, &ptr);
|
|
|
|
BL::Node b_node(ptr);
|
|
|
|
if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
|
|
|
|
BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
|
|
|
|
int length;
|
2015-10-08 12:09:28 +05:00
|
|
|
int settings = background ? 1 : 0; /* 1 - render settings, 0 - vewport settings. */
|
|
|
|
b_point_density_node.calc_point_density(b_scene, settings, &length, &pixels);
|
2015-07-18 22:36:09 +02:00
|
|
|
}
|
|
|
|
}
|
Packed and generated images support for Cycles
This commit adds support of packed and generated images
for Cycles when using SVM backend. Movies are still not
supported. This changes also doesn't touch OSL which is
much less trivial to adopt for any images which are not
saved to disk.
Implementation details:
- When adding images to Image Manager is now possible
to mark image as builtin. Builtin images will bypass
OIIO loader and will use special loading callbacks.
- Callbacks are set by Blender Session and they're
using C++ RNA interface to obtain needed data (pixels,
dimensions, is_float flag).
- Image Manager assumes file path is used as reference
to a builtin images, but in fact currently image
datablock name is used for reference. This makes it
easy to find an image in BlendData database.
- Added some extra properties to Image RNA:
* channels, which denotes actual number of channels
in ImBuf. This is needed to treat image's pixels
correct (before it wasn't possible because API
used internal number of channels for pixels which
is in fact doesn't correlate with image depth)
* is_float, which is truth if image is stored in
float buffer of ImBuf.
- Implemented string lookup for C++ RNA collections
for cases there's no manual lookup function.
OSL is not supported because it used own image loading
and filtering routines and there's seems to be no API
to feed pre-loaded pixels directly to the library.
Think we'll either need to add some API to support
such kind of feeding or consider OSL does not have
support of packed images at all.
Movies are not supported at this moment because of lack
of RNA API to load specified frame. It's not difficult
to solve, just need to consider what to best here:
* Either write some general python interface for ImBuf
and use it via C++ API, or
* Write a PY API function which will return pixels for
given frame, or
* Use bad-level BKE_* call
Anyway, small steps, further improvements later.
Reviewed by Brecht, thanks!
2013-01-12 10:59:13 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
void BlenderSession::update_resumable_tile_manager(int num_samples)
|
|
|
|
{
|
|
|
|
const int num_resumable_chunks = BlenderSession::num_resumable_chunks,
|
|
|
|
current_resumable_chunk = BlenderSession::current_resumable_chunk;
|
|
|
|
if(num_resumable_chunks == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int num_samples_per_chunk = (int)ceilf((float)num_samples / num_resumable_chunks);
|
|
|
|
int range_start_sample = num_samples_per_chunk * (current_resumable_chunk - 1);
|
|
|
|
int range_num_samples = num_samples_per_chunk;
|
|
|
|
if(range_start_sample + range_num_samples > num_samples) {
|
|
|
|
range_num_samples = num_samples - range_num_samples;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
VLOG(1) << "Samples range start is " << range_start_sample << ", "
|
|
|
|
<< "number of samples to render is " << range_num_samples;
|
|
|
|
|
|
|
|
session->tile_manager.range_start_sample = range_start_sample;
|
|
|
|
session->tile_manager.range_num_samples = range_num_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|