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 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SCENE_H__
|
|
|
|
#define __SCENE_H__
|
|
|
|
|
2018-01-19 09:59:58 +00:00
|
|
|
#include "bvh/bvh_params.h"
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "render/image.h"
|
|
|
|
#include "render/shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "device/device_memory.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_param.h"
|
|
|
|
#include "util/util_string.h"
|
|
|
|
#include "util/util_system.h"
|
|
|
|
#include "util/util_texture.h"
|
|
|
|
#include "util/util_thread.h"
|
|
|
|
#include "util/util_types.h"
|
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
class AttributeRequestSet;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Background;
|
|
|
|
class Camera;
|
|
|
|
class Device;
|
2012-09-04 13:29:07 +00:00
|
|
|
class DeviceInfo;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Film;
|
|
|
|
class Integrator;
|
|
|
|
class Light;
|
|
|
|
class LightManager;
|
2013-04-01 20:26:43 +00:00
|
|
|
class LookupTables;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Mesh;
|
|
|
|
class MeshManager;
|
|
|
|
class Object;
|
|
|
|
class ObjectManager;
|
2012-08-31 17:27:08 +00:00
|
|
|
class ParticleSystemManager;
|
|
|
|
class ParticleSystem;
|
2012-12-28 14:21:30 +00:00
|
|
|
class CurveSystemManager;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Shader;
|
|
|
|
class ShaderManager;
|
|
|
|
class Progress;
|
2014-01-02 21:05:07 +00:00
|
|
|
class BakeManager;
|
|
|
|
class BakeData;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* Scene Device Data */
|
|
|
|
|
|
|
|
class DeviceScene {
|
|
|
|
public:
|
|
|
|
/* BVH */
|
2017-10-20 02:32:29 +00:00
|
|
|
device_vector<int4> bvh_nodes;
|
|
|
|
device_vector<int4> bvh_leaf_nodes;
|
|
|
|
device_vector<int> object_node;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
device_vector<uint> prim_tri_index;
|
|
|
|
device_vector<float4> prim_tri_verts;
|
2017-10-20 02:32:29 +00:00
|
|
|
device_vector<int> prim_type;
|
2011-09-01 15:53:36 +00:00
|
|
|
device_vector<uint> prim_visibility;
|
2017-10-20 02:32:29 +00:00
|
|
|
device_vector<int> prim_index;
|
|
|
|
device_vector<int> prim_object;
|
2017-02-15 09:56:54 +00:00
|
|
|
device_vector<float2> prim_time;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* mesh */
|
2014-09-24 11:34:28 +00:00
|
|
|
device_vector<uint> tri_shader;
|
2011-04-27 11:58:34 +00:00
|
|
|
device_vector<float4> tri_vnormal;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
device_vector<uint4> tri_vindex;
|
2016-07-16 23:42:28 +00:00
|
|
|
device_vector<uint> tri_patch;
|
|
|
|
device_vector<float2> tri_patch_uv;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-03 12:09:09 +00:00
|
|
|
device_vector<float4> curves;
|
2013-01-03 12:08:54 +00:00
|
|
|
device_vector<float4> curve_keys;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
device_vector<uint> patches;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* objects */
|
2018-03-07 21:19:56 +00:00
|
|
|
device_vector<KernelObject> objects;
|
2018-03-09 23:37:07 +00:00
|
|
|
device_vector<Transform> object_motion_pass;
|
2018-03-08 03:04:52 +00:00
|
|
|
device_vector<DecomposedTransform> object_motion;
|
2018-03-09 23:37:07 +00:00
|
|
|
device_vector<uint> object_flag;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-03-10 00:36:09 +00:00
|
|
|
/* cameras */
|
|
|
|
device_vector<DecomposedTransform> camera_motion;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* attributes */
|
|
|
|
device_vector<uint4> attributes_map;
|
|
|
|
device_vector<float> attributes_float;
|
|
|
|
device_vector<float4> attributes_float3;
|
2014-06-13 21:40:39 +00:00
|
|
|
device_vector<uchar4> attributes_uchar4;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* lights */
|
2018-03-07 23:15:41 +00:00
|
|
|
device_vector<KernelLightDistribution> light_distribution;
|
|
|
|
device_vector<KernelLight> lights;
|
2012-01-20 17:49:17 +00:00
|
|
|
device_vector<float2> light_background_marginal_cdf;
|
|
|
|
device_vector<float2> light_background_conditional_cdf;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-06-08 16:17:57 +00:00
|
|
|
/* particles */
|
2018-03-07 23:35:24 +00:00
|
|
|
device_vector<KernelParticle> particles;
|
2012-06-08 16:17:57 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* shaders */
|
2017-10-20 02:32:29 +00:00
|
|
|
device_vector<int4> svm_nodes;
|
2018-03-07 23:35:24 +00:00
|
|
|
device_vector<KernelShader> shaders;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-04-01 20:26:43 +00:00
|
|
|
/* lookup tables */
|
|
|
|
device_vector<float> lookup_table;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* integrator */
|
|
|
|
device_vector<uint> sobol_directions;
|
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* ies lights */
|
|
|
|
device_vector<float> ies_lights;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
KernelData data;
|
2017-10-20 21:31:13 +00:00
|
|
|
|
|
|
|
DeviceScene(Device *device);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Scene Parameters */
|
|
|
|
|
|
|
|
class SceneParams {
|
|
|
|
public:
|
2018-01-19 09:59:58 +00:00
|
|
|
/* Type of BVH, in terms whether it is supported dynamic updates of meshes
|
|
|
|
* or whether modifying geometry requires full BVH rebuild.
|
|
|
|
*/
|
2016-02-10 14:09:45 +00:00
|
|
|
enum BVHType {
|
2018-01-19 09:59:58 +00:00
|
|
|
/* BVH supports dynamic updates of geometry.
|
|
|
|
*
|
|
|
|
* Faster for updating BVH tree when doing modifications in viewport,
|
|
|
|
* but slower for rendering.
|
|
|
|
*/
|
2016-02-10 14:09:45 +00:00
|
|
|
BVH_DYNAMIC = 0,
|
2018-01-19 09:59:58 +00:00
|
|
|
/* BVH tree is calculated for specific scene, updates in geometry
|
|
|
|
* requires full tree rebuild.
|
|
|
|
*
|
|
|
|
* Slower to update BVH tree when modifying objects in viewport, also
|
|
|
|
* slower to build final BVH tree but gives best possible render speed.
|
|
|
|
*/
|
2016-02-10 14:09:45 +00:00
|
|
|
BVH_STATIC = 1,
|
|
|
|
|
|
|
|
BVH_NUM_TYPES,
|
2018-01-19 09:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ShadingSystem shadingsystem;
|
|
|
|
|
|
|
|
/* Requested BVH layout.
|
|
|
|
*
|
|
|
|
* If it's not supported by the device, the widest one from supported ones
|
|
|
|
* will be used, but BVH wider than this one will never be used.
|
|
|
|
*/
|
|
|
|
BVHLayout bvh_layout;
|
|
|
|
|
|
|
|
BVHType bvh_type;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool use_bvh_spatial_split;
|
2016-07-07 16:04:16 +00:00
|
|
|
bool use_bvh_unaligned_nodes;
|
2017-01-17 14:13:01 +00:00
|
|
|
int num_bvh_time_steps;
|
2018-01-19 09:59:58 +00:00
|
|
|
|
2013-02-14 16:48:43 +00:00
|
|
|
bool persistent_data;
|
2016-11-17 11:13:22 +00:00
|
|
|
int texture_limit;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
SceneParams()
|
|
|
|
{
|
2014-05-19 10:49:36 +00:00
|
|
|
shadingsystem = SHADINGSYSTEM_SVM;
|
2018-01-19 09:59:58 +00:00
|
|
|
bvh_layout = BVH_LAYOUT_BVH2;
|
2011-04-27 11:58:34 +00:00
|
|
|
bvh_type = BVH_DYNAMIC;
|
|
|
|
use_bvh_spatial_split = false;
|
2016-07-07 16:04:16 +00:00
|
|
|
use_bvh_unaligned_nodes = true;
|
2017-01-17 14:13:01 +00:00
|
|
|
num_bvh_time_steps = 0;
|
2013-09-03 22:39:21 +00:00
|
|
|
persistent_data = false;
|
2016-11-17 11:13:22 +00:00
|
|
|
texture_limit = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool modified(const SceneParams& params)
|
|
|
|
{ return !(shadingsystem == params.shadingsystem
|
2018-01-19 09:59:58 +00:00
|
|
|
&& bvh_layout == params.bvh_layout
|
2011-04-27 11:58:34 +00:00
|
|
|
&& bvh_type == params.bvh_type
|
|
|
|
&& use_bvh_spatial_split == params.use_bvh_spatial_split
|
2016-07-07 16:04:16 +00:00
|
|
|
&& use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes
|
2017-01-17 14:13:01 +00:00
|
|
|
&& num_bvh_time_steps == params.num_bvh_time_steps
|
2016-11-17 11:13:22 +00:00
|
|
|
&& persistent_data == params.persistent_data
|
|
|
|
&& texture_limit == params.texture_limit); }
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Scene */
|
|
|
|
|
|
|
|
class Scene {
|
|
|
|
public:
|
|
|
|
/* data */
|
|
|
|
Camera *camera;
|
2018-01-11 23:50:34 +00:00
|
|
|
Camera *dicing_camera;
|
2013-04-01 20:26:43 +00:00
|
|
|
LookupTables *lookup_tables;
|
2011-04-27 11:58:34 +00:00
|
|
|
Film *film;
|
|
|
|
Background *background;
|
|
|
|
Integrator *integrator;
|
|
|
|
|
|
|
|
/* data lists */
|
|
|
|
vector<Object*> objects;
|
|
|
|
vector<Mesh*> meshes;
|
|
|
|
vector<Shader*> shaders;
|
|
|
|
vector<Light*> lights;
|
2012-08-31 17:27:08 +00:00
|
|
|
vector<ParticleSystem*> particle_systems;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* data managers */
|
|
|
|
ImageManager *image_manager;
|
|
|
|
LightManager *light_manager;
|
|
|
|
ShaderManager *shader_manager;
|
|
|
|
MeshManager *mesh_manager;
|
|
|
|
ObjectManager *object_manager;
|
2012-08-31 17:27:08 +00:00
|
|
|
ParticleSystemManager *particle_system_manager;
|
2012-12-28 14:21:30 +00:00
|
|
|
CurveSystemManager *curve_system_manager;
|
2014-01-02 21:05:07 +00:00
|
|
|
BakeManager *bake_manager;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* default shaders */
|
2016-05-14 12:50:03 +00:00
|
|
|
Shader *default_surface;
|
|
|
|
Shader *default_light;
|
|
|
|
Shader *default_background;
|
|
|
|
Shader *default_empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* device */
|
|
|
|
Device *device;
|
|
|
|
DeviceScene dscene;
|
|
|
|
|
|
|
|
/* parameters */
|
|
|
|
SceneParams params;
|
|
|
|
|
|
|
|
/* mutex must be locked manually by callers */
|
|
|
|
thread_mutex mutex;
|
|
|
|
|
2017-10-20 03:08:26 +00:00
|
|
|
Scene(const SceneParams& params, Device *device);
|
2011-04-27 11:58:34 +00:00
|
|
|
~Scene();
|
|
|
|
|
|
|
|
void device_update(Device *device, Progress& progress);
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool need_global_attribute(AttributeStandard std);
|
|
|
|
void need_global_attributes(AttributeRequestSet& attributes);
|
|
|
|
|
|
|
|
enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
|
2018-01-12 18:56:52 +00:00
|
|
|
MotionType need_motion();
|
2016-07-16 16:56:59 +00:00
|
|
|
float motion_shutter_time();
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool need_update();
|
|
|
|
bool need_reset();
|
2012-11-09 08:46:53 +00:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
void device_free();
|
|
|
|
|
|
|
|
protected:
|
2016-04-22 08:55:26 +00:00
|
|
|
/* Check if some heavy data worth logging was updated.
|
|
|
|
* Mainly used to suppress extra annoying logging.
|
|
|
|
*/
|
|
|
|
bool need_data_update();
|
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void free_memory(bool final);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
#endif /* __SCENE_H__ */
|