2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:56 +01:00
|
|
|
#pragma once
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2023-08-23 13:30:55 +10:00
|
|
|
/* DiagSplit: Parallel, Crack-free, Adaptive Tessellation for Micro-polygon Rendering
|
2012-03-20 22:56:26 +00:00
|
|
|
* Splits up patches and determines edge tessellation factors for dicing. Patch
|
2011-04-27 11:58:34 +00:00
|
|
|
* evaluation at arbitrary points is required for this to work. See the paper
|
|
|
|
|
* for more details. */
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
#include "scene/mesh.h"
|
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "subd/dice.h"
|
|
|
|
|
#include "subd/subpatch.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2025-03-09 03:59:40 +01:00
|
|
|
#include "util/set.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/types.h"
|
|
|
|
|
#include "util/vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
class Mesh;
|
|
|
|
|
class Patch;
|
2025-03-23 19:35:33 +01:00
|
|
|
class SubdAttributeInterpolation;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
class DiagSplit {
|
2025-03-09 03:59:40 +01:00
|
|
|
private:
|
2013-11-28 00:13:32 +01:00
|
|
|
SubdParams params;
|
2025-03-09 04:10:17 +01:00
|
|
|
vector<SubPatch> subpatches;
|
2025-03-09 23:01:28 +01:00
|
|
|
vector<bool> owned_verts;
|
2025-03-09 03:59:40 +01:00
|
|
|
unordered_set<SubEdge, SubEdge::Hash, SubEdge::Equal> edges;
|
|
|
|
|
int num_verts = 0;
|
|
|
|
|
int num_triangles = 0;
|
|
|
|
|
|
|
|
|
|
/* Allocate vertices, edges and subpatches. */
|
|
|
|
|
int alloc_verts(const int num);
|
2025-05-18 22:35:33 +02:00
|
|
|
SubEdge *alloc_edge(const int v0, const int v1, const int depth, bool &was_missing);
|
2025-03-09 23:01:28 +01:00
|
|
|
void alloc_edge(SubPatch::Edge *sub_edge,
|
|
|
|
|
const int v0,
|
|
|
|
|
const int v1,
|
2025-05-18 22:35:33 +02:00
|
|
|
const int depth,
|
2025-03-09 23:01:28 +01:00
|
|
|
const bool want_to_own_edge,
|
|
|
|
|
const bool want_to_own_vertex);
|
2025-03-09 03:59:40 +01:00
|
|
|
void alloc_subpatch(SubPatch &&sub);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2025-03-09 03:59:40 +01:00
|
|
|
/* Compute edge factors. */
|
2025-03-09 04:10:17 +01:00
|
|
|
float3 to_world(const Patch *patch, const float2 uv);
|
2025-05-18 22:35:33 +02:00
|
|
|
std::pair<int, float> T(const Patch *patch,
|
|
|
|
|
const float2 uv_start,
|
|
|
|
|
const float2 uv_end,
|
|
|
|
|
const int depth,
|
|
|
|
|
const bool recursive_resolve = false);
|
|
|
|
|
int limit_edge_factor(const Patch *patch,
|
|
|
|
|
const float2 uv_start,
|
|
|
|
|
const float2 uv_end,
|
|
|
|
|
const int T);
|
|
|
|
|
void assign_edge_factor(SubEdge *edge,
|
|
|
|
|
const Patch *patch,
|
|
|
|
|
const float2 uv_start,
|
|
|
|
|
const float2 uv_end,
|
|
|
|
|
const bool recursive_resolve = false);
|
|
|
|
|
void resolve_edge_factors(const SubPatch &sub);
|
2025-03-09 03:59:40 +01:00
|
|
|
|
|
|
|
|
/* Split edge, subpatch, quad and n-gon. */
|
2025-03-09 23:01:28 +01:00
|
|
|
float2 split_edge(const Patch *patch,
|
|
|
|
|
SubPatch::Edge *subedge,
|
|
|
|
|
SubPatch::Edge *subedge_a,
|
|
|
|
|
SubPatch::Edge *subedge_b,
|
2025-05-18 22:35:33 +02:00
|
|
|
float2 uv_start,
|
|
|
|
|
float2 uv_end);
|
|
|
|
|
void split_quad(SubPatch &&sub);
|
2025-04-15 17:18:50 +02:00
|
|
|
void split_triangle(SubPatch &&sub);
|
|
|
|
|
void split_quad_into_triangles(SubPatch &&sub);
|
2025-03-23 19:35:33 +01:00
|
|
|
void split_quad(const Mesh::SubdFace &face, const int face_index, const Patch *patch);
|
2025-03-09 04:10:17 +01:00
|
|
|
void split_ngon(const Mesh::SubdFace &face,
|
2025-03-23 19:35:33 +01:00
|
|
|
const int face_index,
|
2025-03-09 04:10:17 +01:00
|
|
|
const Patch *patches,
|
|
|
|
|
const size_t patches_byte_stride);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2025-03-09 03:59:40 +01:00
|
|
|
public:
|
|
|
|
|
explicit DiagSplit(const SubdParams ¶ms);
|
|
|
|
|
|
|
|
|
|
void split_patches(const Patch *patches, const size_t patches_byte_stride);
|
2025-03-23 19:35:33 +01:00
|
|
|
|
|
|
|
|
size_t get_num_subpatches() const
|
|
|
|
|
{
|
|
|
|
|
return subpatches.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SubPatch &get_subpatch(const size_t i) const
|
|
|
|
|
{
|
|
|
|
|
return subpatches[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get_num_verts() const
|
|
|
|
|
{
|
|
|
|
|
return num_verts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int get_num_triangles() const
|
|
|
|
|
{
|
|
|
|
|
return num_triangles;
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|