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
|
|
|
*/
|
|
|
|
|
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 20:39:14 +02:00
|
|
|
#include "bvh/bvh.h"
|
|
|
|
#include "bvh/bvh_build.h"
|
|
|
|
|
|
|
|
#include "device/device.h"
|
2020-02-02 12:04:19 +01: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 20:39:14 +02:00
|
|
|
#include "render/graph.h"
|
2020-02-02 12:04:19 +01:00
|
|
|
#include "render/hair.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 20:39:14 +02:00
|
|
|
#include "render/mesh.h"
|
|
|
|
#include "render/object.h"
|
|
|
|
#include "render/scene.h"
|
|
|
|
|
|
|
|
#include "subd/subd_patch_table.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "subd/subd_split.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 20:39:14 +02:00
|
|
|
|
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_progress.h"
|
|
|
|
#include "util/util_set.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* Triangle */
|
|
|
|
|
|
|
|
void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox &bounds) const
|
|
|
|
{
|
|
|
|
bounds.grow(verts[v[0]]);
|
|
|
|
bounds.grow(verts[v[1]]);
|
|
|
|
bounds.grow(verts[v[2]]);
|
|
|
|
}
|
|
|
|
|
2017-01-16 19:56:40 +01:00
|
|
|
void Mesh::Triangle::motion_verts(const float3 *verts,
|
|
|
|
const float3 *vert_steps,
|
|
|
|
size_t num_verts,
|
|
|
|
size_t num_steps,
|
|
|
|
float time,
|
|
|
|
float3 r_verts[3]) const
|
|
|
|
{
|
|
|
|
/* Figure out which steps we need to fetch and their interpolation factor. */
|
|
|
|
const size_t max_step = num_steps - 1;
|
|
|
|
const size_t step = min((int)(time * max_step), max_step - 1);
|
|
|
|
const float t = time * max_step - step;
|
|
|
|
/* Fetch vertex coordinates. */
|
|
|
|
float3 curr_verts[3];
|
|
|
|
float3 next_verts[3];
|
2017-01-16 20:08:19 +01:00
|
|
|
verts_for_step(verts, vert_steps, num_verts, num_steps, step, curr_verts);
|
|
|
|
verts_for_step(verts, vert_steps, num_verts, num_steps, step + 1, next_verts);
|
2017-01-16 19:56:40 +01:00
|
|
|
/* Interpolate between steps. */
|
|
|
|
r_verts[0] = (1.0f - t) * curr_verts[0] + t * next_verts[0];
|
|
|
|
r_verts[1] = (1.0f - t) * curr_verts[1] + t * next_verts[1];
|
|
|
|
r_verts[2] = (1.0f - t) * curr_verts[2] + t * next_verts[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::Triangle::verts_for_step(const float3 *verts,
|
|
|
|
const float3 *vert_steps,
|
|
|
|
size_t num_verts,
|
|
|
|
size_t num_steps,
|
|
|
|
size_t step,
|
|
|
|
float3 r_verts[3]) const
|
|
|
|
{
|
|
|
|
const size_t center_step = ((num_steps - 1) / 2);
|
|
|
|
if (step == center_step) {
|
|
|
|
/* Center step: regular vertex location. */
|
|
|
|
r_verts[0] = verts[v[0]];
|
|
|
|
r_verts[1] = verts[v[1]];
|
|
|
|
r_verts[2] = verts[v[2]];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Center step not stored in the attribute array array. */
|
|
|
|
if (step > center_step) {
|
|
|
|
step--;
|
|
|
|
}
|
|
|
|
size_t offset = step * num_verts;
|
|
|
|
r_verts[0] = vert_steps[offset + v[0]];
|
|
|
|
r_verts[1] = vert_steps[offset + v[1]];
|
|
|
|
r_verts[2] = vert_steps[offset + v[2]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 13:12:06 +05:00
|
|
|
float3 Mesh::Triangle::compute_normal(const float3 *verts) const
|
|
|
|
{
|
|
|
|
const float3 &v0 = verts[v[0]];
|
|
|
|
const float3 &v1 = verts[v[1]];
|
|
|
|
const float3 &v2 = verts[v[2]];
|
|
|
|
const float3 norm = cross(v1 - v0, v2 - v0);
|
|
|
|
const float normlen = len(norm);
|
|
|
|
if (normlen == 0.0f) {
|
|
|
|
return make_float3(1.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
return norm / normlen;
|
|
|
|
}
|
|
|
|
|
2017-10-18 12:19:53 +02:00
|
|
|
bool Mesh::Triangle::valid(const float3 *verts) const
|
|
|
|
{
|
|
|
|
return isfinite3_safe(verts[v[0]]) && isfinite3_safe(verts[v[1]]) && isfinite3_safe(verts[v[2]]);
|
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
/* SubdFace */
|
|
|
|
|
|
|
|
float3 Mesh::SubdFace::normal(const Mesh *mesh) const
|
|
|
|
{
|
|
|
|
float3 v0 = mesh->verts[mesh->subd_face_corners[start_corner + 0]];
|
|
|
|
float3 v1 = mesh->verts[mesh->subd_face_corners[start_corner + 1]];
|
|
|
|
float3 v2 = mesh->verts[mesh->subd_face_corners[start_corner + 2]];
|
|
|
|
|
|
|
|
return safe_normalize(cross(v1 - v0, v2 - v0));
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Mesh */
|
|
|
|
|
2016-05-07 21:44:17 +02:00
|
|
|
NODE_DEFINE(Mesh)
|
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
NodeType *type = NodeType::add("mesh", create, NodeType::NONE, Geometry::node_base_type);
|
2016-05-07 21:44:17 +02:00
|
|
|
|
|
|
|
SOCKET_INT_ARRAY(triangles, "Triangles", array<int>());
|
|
|
|
SOCKET_POINT_ARRAY(verts, "Vertices", array<float3>());
|
|
|
|
SOCKET_INT_ARRAY(shader, "Shader", array<int>());
|
|
|
|
SOCKET_BOOLEAN_ARRAY(smooth, "Smooth", array<bool>());
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
Mesh::Mesh(const NodeType *node_type_, Type geom_type_)
|
|
|
|
: Geometry(node_type_, geom_type_), subd_attributes(this, ATTR_PRIM_SUBD)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
vert_offset = 0;
|
2012-02-28 16:45:01 +00:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
patch_offset = 0;
|
|
|
|
face_offset = 0;
|
|
|
|
corner_offset = 0;
|
|
|
|
|
|
|
|
num_subd_verts = 0;
|
|
|
|
|
|
|
|
num_ngons = 0;
|
2016-07-16 19:56:45 -04:00
|
|
|
|
|
|
|
subdivision_type = SUBDIVISION_NONE;
|
2016-08-14 12:41:45 -04:00
|
|
|
subd_params = NULL;
|
2016-07-16 22:57:06 -04:00
|
|
|
|
|
|
|
patch_table = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 15:46:50 +02:00
|
|
|
Mesh::Mesh() : Mesh(node_type, Geometry::MESH)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
Mesh::~Mesh()
|
|
|
|
{
|
2016-07-16 22:57:06 -04:00
|
|
|
delete patch_table;
|
2016-08-14 12:41:45 -04:00
|
|
|
delete subd_params;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
void Mesh::resize_mesh(int numverts, int numtris)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
verts.resize(numverts);
|
2016-05-08 00:09:08 +02:00
|
|
|
triangles.resize(numtris * 3);
|
2011-04-27 11:58:34 +00:00
|
|
|
shader.resize(numtris);
|
|
|
|
smooth.resize(numtris);
|
2016-04-11 23:46:00 +02:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (subd_faces.size()) {
|
2016-07-16 19:42:28 -04:00
|
|
|
triangle_patch.resize(numtris);
|
|
|
|
vert_patch_uv.resize(numverts);
|
|
|
|
}
|
2016-04-11 23:46:00 +02:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
attributes.resize();
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
void Mesh::reserve_mesh(int numverts, int numtris)
|
|
|
|
{
|
|
|
|
/* reserve space to add verts and triangles later */
|
|
|
|
verts.reserve(numverts);
|
|
|
|
triangles.reserve(numtris * 3);
|
|
|
|
shader.reserve(numtris);
|
|
|
|
smooth.reserve(numtris);
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (subd_faces.size()) {
|
2016-07-16 19:42:28 -04:00
|
|
|
triangle_patch.reserve(numtris);
|
|
|
|
vert_patch_uv.reserve(numverts);
|
|
|
|
}
|
2016-05-08 00:09:08 +02:00
|
|
|
|
|
|
|
attributes.resize(true);
|
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Mesh::resize_subd_faces(int numfaces, int num_ngons_, int numcorners)
|
|
|
|
{
|
2020-10-27 11:40:42 +01:00
|
|
|
subd_faces.resize(numfaces);
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.resize(numcorners);
|
|
|
|
num_ngons = num_ngons_;
|
|
|
|
|
|
|
|
subd_attributes.resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::reserve_subd_faces(int numfaces, int num_ngons_, int numcorners)
|
|
|
|
{
|
2020-10-27 11:40:42 +01:00
|
|
|
subd_faces.reserve(numfaces);
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.reserve(numcorners);
|
|
|
|
num_ngons = num_ngons_;
|
|
|
|
|
|
|
|
subd_attributes.resize(true);
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:54:01 +01:00
|
|
|
void Mesh::clear(bool preserve_voxel_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
Geometry::clear();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* clear all verts and triangles */
|
|
|
|
verts.clear();
|
|
|
|
triangles.clear();
|
|
|
|
shader.clear();
|
|
|
|
smooth.clear();
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
triangle_patch.clear();
|
|
|
|
vert_patch_uv.clear();
|
2016-04-11 23:46:00 +02:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
subd_faces.clear();
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_face_corners.clear();
|
|
|
|
|
|
|
|
num_subd_verts = 0;
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
subd_creases.clear();
|
2016-07-16 22:57:06 -04:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
subd_attributes.clear();
|
2018-03-01 11:54:01 +01:00
|
|
|
attributes.clear(preserve_voxel_data);
|
|
|
|
|
2019-08-14 01:53:09 -04:00
|
|
|
vert_to_stitching_key_map.clear();
|
|
|
|
vert_stitching_map.clear();
|
|
|
|
|
2016-07-16 22:57:06 -04:00
|
|
|
delete patch_table;
|
|
|
|
patch_table = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Mesh::clear()
|
|
|
|
{
|
|
|
|
clear(false);
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
void Mesh::add_vertex(float3 P)
|
2013-07-14 12:51:41 +00:00
|
|
|
{
|
2016-05-08 00:09:08 +02:00
|
|
|
verts.push_back_reserved(P);
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (subd_faces.size()) {
|
2016-07-16 19:42:28 -04:00
|
|
|
vert_patch_uv.push_back_reserved(make_float2(0.0f, 0.0f));
|
|
|
|
}
|
2013-07-14 12:51:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 15:32:31 +02:00
|
|
|
void Mesh::add_vertex_slow(float3 P)
|
|
|
|
{
|
|
|
|
verts.push_back_slow(P);
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (subd_faces.size()) {
|
2016-07-16 19:42:28 -04:00
|
|
|
vert_patch_uv.push_back_slow(make_float2(0.0f, 0.0f));
|
|
|
|
}
|
2016-05-31 15:32:31 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-08 00:09:08 +02:00
|
|
|
triangles.push_back_reserved(v0);
|
|
|
|
triangles.push_back_reserved(v1);
|
|
|
|
triangles.push_back_reserved(v2);
|
|
|
|
shader.push_back_reserved(shader_);
|
|
|
|
smooth.push_back_reserved(smooth_);
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (subd_faces.size()) {
|
2016-07-16 19:42:28 -04:00
|
|
|
triangle_patch.push_back_reserved(-1);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Mesh::add_subd_face(int *corners, int num_corners, int shader_, bool smooth_)
|
|
|
|
{
|
2016-07-29 04:00:37 -04:00
|
|
|
int start_corner = subd_face_corners.size();
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
for (int i = 0; i < num_corners; i++) {
|
|
|
|
subd_face_corners.push_back_reserved(corners[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ptex_offset = 0;
|
2020-10-27 11:40:42 +01:00
|
|
|
|
|
|
|
if (subd_faces.size()) {
|
|
|
|
SubdFace &s = subd_faces[subd_faces.size() - 1];
|
2016-07-16 19:42:28 -04:00
|
|
|
ptex_offset = s.ptex_offset + s.num_ptex_faces();
|
|
|
|
}
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
SubdFace face = {start_corner, num_corners, shader_, smooth_, ptex_offset};
|
|
|
|
subd_faces.push_back_reserved(face);
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Mesh::copy_center_to_motion_step(const int motion_step)
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (attr_mP) {
|
|
|
|
Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
Attribute *attr_N = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
float3 *P = &verts[0];
|
|
|
|
float3 *N = (attr_N) ? attr_N->data_float3() : NULL;
|
|
|
|
size_t numverts = verts.size();
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
memcpy(attr_mP->data_float3() + motion_step * numverts, P, sizeof(float3) * numverts);
|
|
|
|
if (attr_mN)
|
|
|
|
memcpy(attr_mN->data_float3() + motion_step * numverts, N, sizeof(float3) * numverts);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::get_uv_tiles(ustring map, unordered_set<int> &tiles)
|
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
Attribute *attr, *subd_attr;
|
|
|
|
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
if (map.empty()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
attr = attributes.find(ATTR_STD_UV);
|
|
|
|
subd_attr = subd_attributes.find(ATTR_STD_UV);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-02-02 12:04:19 +01:00
|
|
|
attr = attributes.find(map);
|
|
|
|
subd_attr = subd_attributes.find(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr) {
|
2020-02-03 21:40:58 +01:00
|
|
|
attr->get_uv_tiles(this, ATTR_PRIM_GEOMETRY, tiles);
|
|
|
|
}
|
|
|
|
if (subd_attr) {
|
2020-02-02 12:04:19 +01:00
|
|
|
subd_attr->get_uv_tiles(this, ATTR_PRIM_SUBD, tiles);
|
Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.
With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.
The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.
The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles
There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images
Thanks to Brecht for the review and to all who tested the intermediate versions!
Differential Revision: https://developer.blender.org/D3509
2019-12-12 16:06:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::compute_bounds()
|
|
|
|
{
|
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
|
|
|
BoundBox bnds = BoundBox::empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
size_t verts_size = verts.size();
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (verts_size > 0) {
|
2013-04-09 20:48:53 +00:00
|
|
|
for (size_t i = 0; i < verts_size; i++)
|
|
|
|
bnds.grow(verts[i]);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2015-03-28 00:15:15 +05:00
|
|
|
if (use_motion_blur && attr) {
|
2014-03-29 13:03:46 +01:00
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
2017-01-16 18:59:22 +01:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
2014-03-29 13:03:46 +01:00
|
|
|
bnds.grow(vert_steps[i]);
|
|
|
|
}
|
|
|
|
|
2013-04-09 20:48:53 +00:00
|
|
|
if (!bnds.valid()) {
|
|
|
|
bnds = BoundBox::empty;
|
|
|
|
|
|
|
|
/* skip nan or inf coordinates */
|
|
|
|
for (size_t i = 0; i < verts_size; i++)
|
|
|
|
bnds.grow_safe(verts[i]);
|
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (use_motion_blur && attr) {
|
2014-03-29 13:03:46 +01:00
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
2017-01-16 18:59:22 +01:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
2014-03-29 13:03:46 +01:00
|
|
|
bnds.grow_safe(vert_steps[i]);
|
|
|
|
}
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bnds.valid()) {
|
|
|
|
/* empty mesh */
|
2011-04-27 11:58:34 +00:00
|
|
|
bnds.grow(make_float3(0.0f, 0.0f, 0.0f));
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
bounds = bnds;
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Mesh::apply_transform(const Transform &tfm, const bool apply_to_motion)
|
|
|
|
{
|
|
|
|
transform_normal = transform_transposed_inverse(tfm);
|
|
|
|
|
|
|
|
/* apply to mesh vertices */
|
|
|
|
for (size_t i = 0; i < verts.size(); i++)
|
|
|
|
verts[i] = transform_point(&tfm, verts[i]);
|
|
|
|
|
|
|
|
if (apply_to_motion) {
|
|
|
|
Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
|
|
|
vert_steps[i] = transform_point(&tfm, vert_steps[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute *attr_N = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
|
|
|
|
if (attr_N) {
|
|
|
|
Transform ntfm = transform_normal;
|
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *normal_steps = attr_N->data_float3();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
|
|
|
normal_steps[i] = normalize(transform_direction(&ntfm, normal_steps[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::add_face_normals()
|
|
|
|
{
|
|
|
|
/* don't compute if already there */
|
2012-04-30 12:49:26 +00:00
|
|
|
if (attributes.find(ATTR_STD_FACE_NORMAL))
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2017-01-16 18:59:22 +01:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* get attributes */
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *attr_fN = attributes.add(ATTR_STD_FACE_NORMAL);
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 *fN = attr_fN->data_float3();
|
|
|
|
|
|
|
|
/* compute face normals */
|
2016-05-08 00:09:08 +02:00
|
|
|
size_t triangles_size = num_triangles();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-10-03 15:31:45 +00:00
|
|
|
if (triangles_size) {
|
2016-08-17 23:49:55 +02:00
|
|
|
float3 *verts_ptr = verts.data();
|
2011-10-03 15:31:45 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
2017-10-10 13:12:06 +05:00
|
|
|
fN[i] = get_triangle(i).compute_normal(verts_ptr);
|
2011-10-03 15:31:45 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-01-15 16:35:05 +00:00
|
|
|
|
|
|
|
/* expected to be in local space */
|
|
|
|
if (transform_applied) {
|
|
|
|
Transform ntfm = transform_inverse(transform_normal);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < triangles_size; i++)
|
|
|
|
fN[i] = normalize(transform_direction(&ntfm, fN[i]));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::add_vertex_normals()
|
|
|
|
{
|
2014-03-29 13:03:46 +01:00
|
|
|
bool flip = transform_negative_scaled;
|
|
|
|
size_t verts_size = verts.size();
|
2016-05-08 00:09:08 +02:00
|
|
|
size_t triangles_size = num_triangles();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* static vertex normals */
|
2016-08-23 13:57:45 -04:00
|
|
|
if (!attributes.find(ATTR_STD_VERTEX_NORMAL) && triangles_size) {
|
2014-03-29 13:03:46 +01:00
|
|
|
/* get attributes */
|
|
|
|
Attribute *attr_fN = attributes.find(ATTR_STD_FACE_NORMAL);
|
|
|
|
Attribute *attr_vN = attributes.add(ATTR_STD_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
float3 *fN = attr_fN->data_float3();
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* compute vertex normals */
|
|
|
|
memset(vN, 0, verts.size() * sizeof(float3));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
|
|
|
for (size_t j = 0; j < 3; j++) {
|
|
|
|
vN[get_triangle(i).v[j]] += fN[i];
|
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
vN[i] = normalize(vN[i]);
|
2016-08-25 10:45:48 -04:00
|
|
|
if (flip) {
|
2014-03-29 13:03:46 +01:00
|
|
|
vN[i] = -vN[i];
|
2016-08-25 10:45:48 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2011-10-03 15:31:45 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* motion vertex normals */
|
|
|
|
Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
|
|
|
Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
if (has_motion_blur() && attr_mP && !attr_mN && triangles_size) {
|
2014-03-29 13:03:46 +01:00
|
|
|
/* create attribute */
|
|
|
|
attr_mN = attributes.add(ATTR_STD_MOTION_VERTEX_NORMAL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
for (int step = 0; step < motion_steps - 1; step++) {
|
|
|
|
float3 *mP = attr_mP->data_float3() + step * verts.size();
|
|
|
|
float3 *mN = attr_mN->data_float3() + step * verts.size();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* compute */
|
|
|
|
memset(mN, 0, verts.size() * sizeof(float3));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
|
|
|
for (size_t j = 0; j < 3; j++) {
|
2017-10-10 13:12:06 +05:00
|
|
|
float3 fN = get_triangle(i).compute_normal(mP);
|
2016-08-25 10:45:48 -04:00
|
|
|
mN[get_triangle(i).v[j]] += fN;
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
mN[i] = normalize(mN[i]);
|
2016-08-25 10:45:48 -04:00
|
|
|
if (flip) {
|
2014-03-29 13:03:46 +01:00
|
|
|
mN[i] = -mN[i];
|
2016-08-25 10:45:48 -04:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 14:29:52 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
/* subd vertex normals */
|
2020-10-27 11:40:42 +01:00
|
|
|
if (!subd_attributes.find(ATTR_STD_VERTEX_NORMAL) && subd_faces.size()) {
|
2016-08-23 13:57:45 -04:00
|
|
|
/* get attributes */
|
|
|
|
Attribute *attr_vN = subd_attributes.add(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
/* compute vertex normals */
|
|
|
|
memset(vN, 0, verts.size() * sizeof(float3));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
for (size_t i = 0; i < subd_faces.size(); i++) {
|
|
|
|
SubdFace &face = subd_faces[i];
|
2016-08-30 12:22:50 -04:00
|
|
|
float3 fN = face.normal(this);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
for (size_t j = 0; j < face.num_corners; j++) {
|
|
|
|
size_t corner = subd_face_corners[face.start_corner + j];
|
2016-08-30 12:22:50 -04:00
|
|
|
vN[corner] += fN;
|
2016-08-23 13:57:45 -04:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-23 13:57:45 -04:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
vN[i] = normalize(vN[i]);
|
|
|
|
if (flip) {
|
|
|
|
vN[i] = -vN[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 12:27:17 -04:00
|
|
|
void Mesh::add_undisplaced()
|
|
|
|
{
|
|
|
|
AttributeSet &attrs = (subdivision_type == SUBDIVISION_NONE) ? attributes : subd_attributes;
|
|
|
|
|
|
|
|
/* don't compute if already there */
|
|
|
|
if (attrs.find(ATTR_STD_POSITION_UNDISPLACED)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get attribute */
|
|
|
|
Attribute *attr = attrs.add(ATTR_STD_POSITION_UNDISPLACED);
|
|
|
|
attr->flags |= ATTR_SUBDIVIDED;
|
|
|
|
|
|
|
|
float3 *data = attr->data_float3();
|
|
|
|
|
|
|
|
/* copy verts */
|
2020-02-03 21:40:58 +01:00
|
|
|
size_t size = attr->buffer_size(this, attrs.prim);
|
2016-09-22 17:34:14 -04:00
|
|
|
|
2019-05-01 21:14:11 +10:00
|
|
|
/* Center points for ngons aren't stored in Mesh::verts but are included in size since they will
|
|
|
|
* be calculated later, we subtract them from size here so we don't have an overflow while
|
|
|
|
* copying.
|
2016-09-22 17:34:14 -04:00
|
|
|
*/
|
|
|
|
size -= num_ngons * attr->data_sizeof();
|
|
|
|
|
2016-08-13 12:27:17 -04:00
|
|
|
if (size) {
|
|
|
|
memcpy(data, verts.data(), size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-10 06:10:14 +01:00
|
|
|
void Mesh::pack_shaders(Scene *scene, uint *tri_shader)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-09-24 13:34:28 +02:00
|
|
|
uint shader_id = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
uint last_shader = -1;
|
|
|
|
bool last_smooth = false;
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
size_t triangles_size = num_triangles();
|
2016-08-17 23:49:55 +02:00
|
|
|
int *shader_ptr = shader.data();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
|
|
|
if (shader_ptr[i] != last_shader || last_smooth != smooth[i]) {
|
|
|
|
last_shader = shader_ptr[i];
|
|
|
|
last_smooth = smooth[i];
|
2020-10-27 11:40:42 +01:00
|
|
|
Shader *shader = (last_shader < used_shaders.size()) ? used_shaders[last_shader] :
|
|
|
|
scene->default_surface;
|
2016-08-16 19:42:08 -04:00
|
|
|
shader_id = scene->shader_manager->get_shader_id(shader, last_smooth);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 13:34:28 +02:00
|
|
|
tri_shader[i] = shader_id;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2018-03-10 06:10:14 +01:00
|
|
|
}
|
|
|
|
|
2018-03-10 06:51:52 +01:00
|
|
|
void Mesh::pack_normals(float4 *vnormal)
|
2018-03-10 06:10:14 +01:00
|
|
|
{
|
|
|
|
Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
if (attr_vN == NULL) {
|
|
|
|
/* Happens on objects with just hair. */
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-03-10 06:10:14 +01:00
|
|
|
bool do_transform = transform_applied;
|
|
|
|
Transform ntfm = transform_normal;
|
|
|
|
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2011-04-27 11:58:34 +00:00
|
|
|
size_t verts_size = verts.size();
|
|
|
|
|
2013-01-15 16:35:05 +00:00
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
float3 vNi = vN[i];
|
|
|
|
|
|
|
|
if (do_transform)
|
2017-05-07 14:40:58 +02:00
|
|
|
vNi = safe_normalize(transform_direction(&ntfm, vNi));
|
2013-01-15 16:35:05 +00:00
|
|
|
|
|
|
|
vnormal[i] = make_float4(vNi.x, vNi.y, vNi.z, 0.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
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 16:13:50 +02:00
|
|
|
void Mesh::pack_verts(const vector<uint> &tri_prim_index,
|
|
|
|
uint4 *tri_vindex,
|
2016-07-16 19:42:28 -04:00
|
|
|
uint *tri_patch,
|
|
|
|
float2 *tri_patch_uv,
|
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 16:13:50 +02:00
|
|
|
size_t vert_offset,
|
|
|
|
size_t tri_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-16 19:42:28 -04:00
|
|
|
size_t verts_size = verts.size();
|
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
if (verts_size && subd_faces.size()) {
|
2016-08-17 23:49:55 +02:00
|
|
|
float2 *vert_patch_uv_ptr = vert_patch_uv.data();
|
2016-07-16 19:42:28 -04:00
|
|
|
|
|
|
|
for (size_t i = 0; i < verts_size; i++) {
|
|
|
|
tri_patch_uv[i] = vert_patch_uv_ptr[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t triangles_size = num_triangles();
|
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t i = 0; i < triangles_size; i++) {
|
|
|
|
Triangle t = get_triangle(i);
|
|
|
|
tri_vindex[i] = make_uint4(t.v[0] + vert_offset,
|
|
|
|
t.v[1] + vert_offset,
|
|
|
|
t.v[2] + vert_offset,
|
|
|
|
tri_prim_index[i + tri_offset]);
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2020-10-27 11:40:42 +01:00
|
|
|
tri_patch[i] = (!subd_faces.size()) ? -1 : (triangle_patch[i] * 8 + patch_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Mesh::pack_patches(uint *patch_data, uint vert_offset, uint face_offset, uint corner_offset)
|
|
|
|
{
|
2020-10-27 11:40:42 +01:00
|
|
|
size_t num_faces = subd_faces.size();
|
2016-07-16 19:42:28 -04:00
|
|
|
int ngons = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
for (size_t f = 0; f < num_faces; f++) {
|
2020-10-27 11:40:42 +01:00
|
|
|
SubdFace face = subd_faces[f];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
if (face.is_quad()) {
|
|
|
|
int c[4];
|
|
|
|
memcpy(c, &subd_face_corners[face.start_corner], sizeof(int) * 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
*(patch_data++) = c[0] + vert_offset;
|
|
|
|
*(patch_data++) = c[1] + vert_offset;
|
|
|
|
*(patch_data++) = c[2] + vert_offset;
|
|
|
|
*(patch_data++) = c[3] + vert_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
*(patch_data++) = f + face_offset;
|
|
|
|
*(patch_data++) = face.num_corners;
|
|
|
|
*(patch_data++) = face.start_corner + corner_offset;
|
|
|
|
*(patch_data++) = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < face.num_corners; i++) {
|
2016-07-16 19:42:28 -04:00
|
|
|
int c[4];
|
2016-08-25 10:45:48 -04:00
|
|
|
c[0] = subd_face_corners[face.start_corner + mod(i + 0, face.num_corners)];
|
|
|
|
c[1] = subd_face_corners[face.start_corner + mod(i + 1, face.num_corners)];
|
|
|
|
c[2] = verts.size() - num_subd_verts + ngons;
|
|
|
|
c[3] = subd_face_corners[face.start_corner + mod(i - 1, face.num_corners)];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
*(patch_data++) = c[0] + vert_offset;
|
|
|
|
*(patch_data++) = c[1] + vert_offset;
|
|
|
|
*(patch_data++) = c[2] + vert_offset;
|
|
|
|
*(patch_data++) = c[3] + vert_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
*(patch_data++) = f + face_offset;
|
2016-08-25 10:45:48 -04:00
|
|
|
*(patch_data++) = face.num_corners | (i << 16);
|
2016-07-16 19:42:28 -04:00
|
|
|
*(patch_data++) = face.start_corner + corner_offset;
|
2016-08-25 10:45:48 -04:00
|
|
|
*(patch_data++) = subd_face_corners.size() + ngons + corner_offset;
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-25 10:45:48 -04:00
|
|
|
ngons++;
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|