Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/object.cpp
| Show All 18 Lines | |||||
| #include "render/camera.h" | #include "render/camera.h" | ||||
| #include "render/curves.h" | #include "render/curves.h" | ||||
| #include "render/hair.h" | #include "render/hair.h" | ||||
| #include "render/integrator.h" | #include "render/integrator.h" | ||||
| #include "render/light.h" | #include "render/light.h" | ||||
| #include "render/mesh.h" | #include "render/mesh.h" | ||||
| #include "render/particles.h" | #include "render/particles.h" | ||||
| #include "render/scene.h" | #include "render/scene.h" | ||||
| #include "render/volume.h" | |||||
| #include "util/util_foreach.h" | #include "util/util_foreach.h" | ||||
| #include "util/util_logging.h" | #include "util/util_logging.h" | ||||
| #include "util/util_map.h" | #include "util/util_map.h" | ||||
| #include "util/util_murmurhash.h" | #include "util/util_murmurhash.h" | ||||
| #include "util/util_progress.h" | #include "util/util_progress.h" | ||||
| #include "util/util_set.h" | #include "util/util_set.h" | ||||
| #include "util/util_task.h" | #include "util/util_task.h" | ||||
| ▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | uint Object::visibility_for_tracing() const | ||||
| else { | else { | ||||
| trace_visibility &= ~PATH_RAY_SHADOW_CATCHER; | trace_visibility &= ~PATH_RAY_SHADOW_CATCHER; | ||||
| } | } | ||||
| return trace_visibility; | return trace_visibility; | ||||
| } | } | ||||
| float Object::compute_volume_step_size() const | float Object::compute_volume_step_size() const | ||||
| { | { | ||||
| if (geometry->type != Geometry::MESH) { | if (geometry->type != Geometry::MESH && geometry->type != Geometry::VOLUME) { | ||||
| return FLT_MAX; | return FLT_MAX; | ||||
| } | } | ||||
| Mesh *mesh = static_cast<Mesh *>(geometry); | Mesh *mesh = static_cast<Mesh *>(geometry); | ||||
| if (!mesh->has_volume) { | if (!mesh->has_volume) { | ||||
| return FLT_MAX; | return FLT_MAX; | ||||
| } | } | ||||
| Show All 12 Lines | float Object::compute_volume_step_size() const | ||||
| if (step_rate == FLT_MAX) { | if (step_rate == FLT_MAX) { | ||||
| return FLT_MAX; | return FLT_MAX; | ||||
| } | } | ||||
| /* Compute step size from voxel grids. */ | /* Compute step size from voxel grids. */ | ||||
| float step_size = FLT_MAX; | float step_size = FLT_MAX; | ||||
| foreach (Attribute &attr, mesh->attributes.attributes) { | if (geometry->type == Geometry::VOLUME) { | ||||
| Volume *volume = static_cast<Volume *>(geometry); | |||||
| foreach (Attribute &attr, volume->attributes.attributes) { | |||||
| if (attr.element == ATTR_ELEMENT_VOXEL) { | if (attr.element == ATTR_ELEMENT_VOXEL) { | ||||
| ImageHandle &handle = attr.data_voxel(); | ImageHandle &handle = attr.data_voxel(); | ||||
| const ImageMetaData &metadata = handle.metadata(); | const ImageMetaData &metadata = handle.metadata(); | ||||
| if (metadata.width == 0 || metadata.height == 0 || metadata.depth == 0) { | if (metadata.width == 0 || metadata.height == 0 || metadata.depth == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* User specified step size. */ | /* User specified step size. */ | ||||
| float voxel_step_size = mesh->volume_step_size; | float voxel_step_size = volume->step_size; | ||||
| if (voxel_step_size == 0.0f) { | if (voxel_step_size == 0.0f) { | ||||
| /* Auto detect step size. */ | /* Auto detect step size. */ | ||||
| float3 size = make_float3( | float3 size = make_float3( | ||||
| 1.0f / metadata.width, 1.0f / metadata.height, 1.0f / metadata.depth); | 1.0f / metadata.width, 1.0f / metadata.height, 1.0f / metadata.depth); | ||||
| /* Step size is transformed from voxel to world space. */ | /* Step size is transformed from voxel to world space. */ | ||||
| Transform voxel_tfm = tfm; | Transform voxel_tfm = tfm; | ||||
| if (metadata.use_transform_3d) { | if (metadata.use_transform_3d) { | ||||
| voxel_tfm = tfm * transform_inverse(metadata.transform_3d); | voxel_tfm = tfm * transform_inverse(metadata.transform_3d); | ||||
| } | } | ||||
| voxel_step_size = min3(fabs(transform_direction(&voxel_tfm, size))); | voxel_step_size = min3(fabs(transform_direction(&voxel_tfm, size))); | ||||
| } | } | ||||
| else if (mesh->volume_object_space) { | else if (volume->object_space) { | ||||
| /* User specified step size in object space. */ | /* User specified step size in object space. */ | ||||
| float3 size = make_float3(voxel_step_size, voxel_step_size, voxel_step_size); | float3 size = make_float3(voxel_step_size, voxel_step_size, voxel_step_size); | ||||
| voxel_step_size = min3(fabs(transform_direction(&tfm, size))); | voxel_step_size = min3(fabs(transform_direction(&tfm, size))); | ||||
| } | } | ||||
| if (voxel_step_size > 0.0f) { | if (voxel_step_size > 0.0f) { | ||||
| step_size = fminf(voxel_step_size, step_size); | step_size = fminf(voxel_step_size, step_size); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| if (step_size == FLT_MAX) { | if (step_size == FLT_MAX) { | ||||
| /* Fall back to 1/10th of bounds for procedural volumes. */ | /* Fall back to 1/10th of bounds for procedural volumes. */ | ||||
| step_size = 0.1f * average(bounds.size()); | step_size = 0.1f * average(bounds.size()); | ||||
| } | } | ||||
| step_size *= step_rate; | step_size *= step_rate; | ||||
| Show All 16 Lines | |||||
| ObjectManager::~ObjectManager() | ObjectManager::~ObjectManager() | ||||
| { | { | ||||
| } | } | ||||
| static float object_surface_area(UpdateObjectTransformState *state, | static float object_surface_area(UpdateObjectTransformState *state, | ||||
| const Transform &tfm, | const Transform &tfm, | ||||
| Geometry *geom) | Geometry *geom) | ||||
| { | { | ||||
| if (geom->type != Geometry::MESH) { | if (geom->type != Geometry::MESH && geom->type != Geometry::VOLUME) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| if (mesh->has_volume) { | if (mesh->has_volume || geom->type == Geometry::VOLUME) { | ||||
| /* Volume density automatically adjust to object scale. */ | /* Volume density automatically adjust to object scale. */ | ||||
| if (mesh->volume_object_space) { | if (geom->type == Geometry::VOLUME && static_cast<Volume *>(geom)->object_space) { | ||||
| const float3 unit = normalize(make_float3(1.0f, 1.0f, 1.0f)); | const float3 unit = normalize(make_float3(1.0f, 1.0f, 1.0f)); | ||||
| return 1.0f / len(transform_direction(&tfm, unit)); | return 1.0f / len(transform_direction(&tfm, unit)); | ||||
| } | } | ||||
| else { | else { | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | void ObjectManager::device_update_object_transform(UpdateObjectTransformState *state, Object *ob) | ||||
| kobject.dupli_generated[1] = ob->dupli_generated[1]; | kobject.dupli_generated[1] = ob->dupli_generated[1]; | ||||
| kobject.dupli_generated[2] = ob->dupli_generated[2]; | kobject.dupli_generated[2] = ob->dupli_generated[2]; | ||||
| kobject.numkeys = (geom->type == Geometry::HAIR) ? static_cast<Hair *>(geom)->curve_keys.size() : | kobject.numkeys = (geom->type == Geometry::HAIR) ? static_cast<Hair *>(geom)->curve_keys.size() : | ||||
| 0; | 0; | ||||
| kobject.dupli_uv[0] = ob->dupli_uv[0]; | kobject.dupli_uv[0] = ob->dupli_uv[0]; | ||||
| kobject.dupli_uv[1] = ob->dupli_uv[1]; | kobject.dupli_uv[1] = ob->dupli_uv[1]; | ||||
| int totalsteps = geom->motion_steps; | int totalsteps = geom->motion_steps; | ||||
| kobject.numsteps = (totalsteps - 1) / 2; | kobject.numsteps = (totalsteps - 1) / 2; | ||||
| kobject.numverts = (geom->type == Geometry::MESH) ? static_cast<Mesh *>(geom)->verts.size() : 0; | kobject.numverts = (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) ? | ||||
| static_cast<Mesh *>(geom)->verts.size() : | |||||
| 0; | |||||
| kobject.patch_map_offset = 0; | kobject.patch_map_offset = 0; | ||||
| kobject.attribute_map_offset = 0; | kobject.attribute_map_offset = 0; | ||||
| uint32_t hash_name = util_murmur_hash3(ob->name.c_str(), ob->name.length(), 0); | uint32_t hash_name = util_murmur_hash3(ob->name.c_str(), ob->name.length(), 0); | ||||
| uint32_t hash_asset = util_murmur_hash3(ob->asset_name.c_str(), ob->asset_name.length(), 0); | uint32_t hash_asset = util_murmur_hash3(ob->asset_name.c_str(), ob->asset_name.length(), 0); | ||||
| kobject.cryptomatte_object = util_hash_to_float(hash_name); | kobject.cryptomatte_object = util_hash_to_float(hash_name); | ||||
| kobject.cryptomatte_asset = util_hash_to_float(hash_asset); | kobject.cryptomatte_asset = util_hash_to_float(hash_asset); | ||||
| kobject.shadow_terminator_offset = 1.0f / (1.0f - 0.5f * ob->shadow_terminator_offset); | kobject.shadow_terminator_offset = 1.0f / (1.0f - 0.5f * ob->shadow_terminator_offset); | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | foreach (Object *object, scene->objects) { | ||||
| * it'll use uninitialized transform_applied flag. | * it'll use uninitialized transform_applied flag. | ||||
| * | * | ||||
| * Could be solved by moving reference counter to Geometry. | * Could be solved by moving reference counter to Geometry. | ||||
| */ | */ | ||||
| Geometry *geom = object->geometry; | Geometry *geom = object->geometry; | ||||
| bool apply = (geometry_users[geom] == 1) && !geom->has_surface_bssrdf && | bool apply = (geometry_users[geom] == 1) && !geom->has_surface_bssrdf && | ||||
| !geom->has_true_displacement(); | !geom->has_true_displacement(); | ||||
| if (geom->type == Geometry::MESH) { | if (geom->type == Geometry::MESH || geom->type == Geometry::VOLUME) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| apply = apply && mesh->subdivision_type == Mesh::SUBDIVISION_NONE; | apply = apply && mesh->subdivision_type == Mesh::SUBDIVISION_NONE; | ||||
| } | } | ||||
| else if (geom->type == Geometry::HAIR) { | else if (geom->type == Geometry::HAIR) { | ||||
| /* Can't apply non-uniform scale to curves, this can't be represented by | /* Can't apply non-uniform scale to curves, this can't be represented by | ||||
| * control points and radius alone. */ | * control points and radius alone. */ | ||||
| float scale; | float scale; | ||||
| apply = apply && transform_uniform_scale(object->tfm, scale); | apply = apply && transform_uniform_scale(object->tfm, scale); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines | |||||