Comments and format
parent
8b017f460f
commit
0e2d7dc596
|
@ -339,7 +339,7 @@ void build_regular_mesh(
|
||||||
Vector3i pos;
|
Vector3i pos;
|
||||||
for (pos.z = min_pos.z; pos.z < max_pos.z; ++pos.z) {
|
for (pos.z = min_pos.z; pos.z < max_pos.z; ++pos.z) {
|
||||||
for (pos.y = min_pos.y; pos.y < max_pos.y; ++pos.y) {
|
for (pos.y = min_pos.y; pos.y < max_pos.y; ++pos.y) {
|
||||||
// TODO Change iteration to be ZXY?
|
// TODO Optimization: change iteration to be ZXY? (Data is laid out with Y as deepest coordinate)
|
||||||
unsigned int data_index = Vector3i(min_pos.x, pos.y, pos.z).get_zxy_index(block_size_with_padding);
|
unsigned int data_index = Vector3i(min_pos.x, pos.y, pos.z).get_zxy_index(block_size_with_padding);
|
||||||
|
|
||||||
for (pos.x = min_pos.x; pos.x < max_pos.x; ++pos.x, data_index += block_size_with_padding.y) {
|
for (pos.x = min_pos.x; pos.x < max_pos.x; ++pos.x, data_index += block_size_with_padding.y) {
|
||||||
|
@ -933,7 +933,7 @@ void build_transition_mesh(
|
||||||
cell_gradients[0xB] = cell_gradients[6];
|
cell_gradients[0xB] = cell_gradients[6];
|
||||||
cell_gradients[0xC] = cell_gradients[8];
|
cell_gradients[0xC] = cell_gradients[8];
|
||||||
|
|
||||||
// TODO Get rid of conditionals involved in face_to_block
|
// TODO Optimization: get rid of conditionals involved in face_to_block
|
||||||
cell_positions[1] = face_to_block(fx + 1, fy + 0, fz, direction, block_size_with_padding);
|
cell_positions[1] = face_to_block(fx + 1, fy + 0, fz, direction, block_size_with_padding);
|
||||||
cell_positions[2] = face_to_block(fx + 2, fy + 0, fz, direction, block_size_with_padding);
|
cell_positions[2] = face_to_block(fx + 2, fy + 0, fz, direction, block_size_with_padding);
|
||||||
cell_positions[3] = face_to_block(fx + 0, fy + 1, fz, direction, block_size_with_padding);
|
cell_positions[3] = face_to_block(fx + 0, fy + 1, fz, direction, block_size_with_padding);
|
||||||
|
@ -1212,6 +1212,8 @@ DefaultTextureIndicesData build_regular_mesh(const VoxelBuffer &voxels, unsigned
|
||||||
ERR_FAIL_COND_V(weights_data.size() != voxels_count, default_texture_indices_data);
|
ERR_FAIL_COND_V(weights_data.size() != voxels_count, default_texture_indices_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We settle data types up-front so we can get rid of abstraction layers and conditionals,
|
||||||
|
// which would otherwise harm performance in tight iterations
|
||||||
switch (voxels.get_channel_depth(sdf_channel)) {
|
switch (voxels.get_channel_depth(sdf_channel)) {
|
||||||
case VoxelBuffer::DEPTH_8_BIT: {
|
case VoxelBuffer::DEPTH_8_BIT: {
|
||||||
ArraySlice<const uint8_t> sdf_data = sdf_data_raw.reinterpret_cast_to<const uint8_t>();
|
ArraySlice<const uint8_t> sdf_data = sdf_data_raw.reinterpret_cast_to<const uint8_t>();
|
||||||
|
|
|
@ -60,7 +60,7 @@ void VoxelMesherTransvoxel::build(VoxelMesher::Output &output, const VoxelMesher
|
||||||
static thread_local Transvoxel::Cache s_cache;
|
static thread_local Transvoxel::Cache s_cache;
|
||||||
static thread_local Transvoxel::MeshArrays s_mesh_arrays;
|
static thread_local Transvoxel::MeshArrays s_mesh_arrays;
|
||||||
|
|
||||||
const int channel = VoxelBuffer::CHANNEL_SDF;
|
const int sdf_channel = VoxelBuffer::CHANNEL_SDF;
|
||||||
|
|
||||||
// Initialize dynamic memory:
|
// Initialize dynamic memory:
|
||||||
// These vectors are re-used.
|
// These vectors are re-used.
|
||||||
|
@ -69,7 +69,7 @@ void VoxelMesherTransvoxel::build(VoxelMesher::Output &output, const VoxelMesher
|
||||||
s_mesh_arrays.clear();
|
s_mesh_arrays.clear();
|
||||||
|
|
||||||
const VoxelBuffer &voxels = input.voxels;
|
const VoxelBuffer &voxels = input.voxels;
|
||||||
if (voxels.is_uniform(channel)) {
|
if (voxels.is_uniform(sdf_channel)) {
|
||||||
// There won't be anything to polygonize since the SDF has no variations, so it can't cross the isolevel
|
// There won't be anything to polygonize since the SDF has no variations, so it can't cross the isolevel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,8 @@ void VoxelMesherTransvoxel::build(VoxelMesher::Output &output, const VoxelMesher
|
||||||
// const uint64_t time_before = OS::get_singleton()->get_ticks_usec();
|
// const uint64_t time_before = OS::get_singleton()->get_ticks_usec();
|
||||||
|
|
||||||
Transvoxel::DefaultTextureIndicesData default_texture_indices_data = Transvoxel::build_regular_mesh(
|
Transvoxel::DefaultTextureIndicesData default_texture_indices_data = Transvoxel::build_regular_mesh(
|
||||||
voxels, channel, input.lod, static_cast<Transvoxel::TexturingMode>(_texture_mode), s_cache, s_mesh_arrays);
|
voxels, sdf_channel, input.lod, static_cast<Transvoxel::TexturingMode>(_texture_mode), s_cache,
|
||||||
|
s_mesh_arrays);
|
||||||
|
|
||||||
if (s_mesh_arrays.vertices.size() == 0) {
|
if (s_mesh_arrays.vertices.size() == 0) {
|
||||||
// The mesh can be empty
|
// The mesh can be empty
|
||||||
|
@ -92,7 +93,7 @@ void VoxelMesherTransvoxel::build(VoxelMesher::Output &output, const VoxelMesher
|
||||||
VOXEL_PROFILE_SCOPE();
|
VOXEL_PROFILE_SCOPE();
|
||||||
s_mesh_arrays.clear();
|
s_mesh_arrays.clear();
|
||||||
|
|
||||||
Transvoxel::build_transition_mesh(voxels, channel, dir, input.lod,
|
Transvoxel::build_transition_mesh(voxels, sdf_channel, dir, input.lod,
|
||||||
static_cast<Transvoxel::TexturingMode>(_texture_mode), s_cache, s_mesh_arrays,
|
static_cast<Transvoxel::TexturingMode>(_texture_mode), s_cache, s_mesh_arrays,
|
||||||
default_texture_indices_data);
|
default_texture_indices_data);
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ inline T max(const T a, const T b, const T c, const T d, const T e, const T f, c
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T clamp(const T x, const T min_value, const T max_value) {
|
inline T clamp(const T x, const T min_value, const T max_value) {
|
||||||
// TODO Clang can optimize a min/max implementation. Worth changing to that?
|
// TODO Optimization: clang can optimize a min/max implementation. Worth changing to that?
|
||||||
if (x < min_value) {
|
if (x < min_value) {
|
||||||
return min_value;
|
return min_value;
|
||||||
}
|
}
|
||||||
|
@ -164,4 +164,8 @@ inline Vector3 fract(const Vector3 &p) {
|
||||||
return Vector3(fract(p.x), fract(p.y), fract(p.z));
|
return Vector3(fract(p.x), fract(p.y), fract(p.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inline bool is_power_of_two(int i) {
|
||||||
|
// return i & (i - 1);
|
||||||
|
// }
|
||||||
|
|
||||||
#endif // VOXEL_MATH_FUNCS_H
|
#endif // VOXEL_MATH_FUNCS_H
|
||||||
|
|
Loading…
Reference in New Issue