Blender V5.3
osd.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2024 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#ifdef WITH_OPENSUBDIV
8
9/* OpenSubdiv headers use M_PI. */
10# if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
11# define _USE_MATH_DEFINES
12# endif
13
14# include <opensubdiv/far/patchMap.h>
15# include <opensubdiv/far/patchTableFactory.h>
16# include <opensubdiv/far/primvarRefiner.h>
17# include <opensubdiv/far/topologyRefinerFactory.h>
18
19# include "subd/patch.h"
20
21# include "util/types.h"
22# include "util/unique_ptr.h"
23# include "util/vector.h"
24
26
27/* Directly use some OpenSubdiv namespaces for brevity. */
28namespace Far = OpenSubdiv::Far;
29namespace Sdc = OpenSubdiv::Sdc;
30
31class Attribute;
32class Mesh;
33
34/* OpenSubdiv interface for vertex and attribute values. */
35
36template<typename T> struct OsdValue {
37 T value;
38
39 OsdValue() = default;
40
41 void Clear(void *unused = nullptr)
42 {
43 (void)unused;
44 memset((void *)&value, 0, sizeof(T));
45 }
46
47 void AddWithWeight(OsdValue<T> const &src, float weight)
48 {
49 if constexpr (std::is_same_v<T, packed_float3>) {
50 value = float3(value) + float3(src.value) * weight;
51 }
52 else {
53 value += src.value * weight;
54 }
55 }
56};
57
58/* Wrapper around Mesh for TopologyRefinerFactory. */
59
60class OsdMesh {
61 public:
62 /* Face-varying attribute that requires merging of corners with the same value, typically a UV
63 * map. The resulting topology after merging is stored in a topology refiner fvar channel. The
64 * merged attribute values are stored here, in a generic buffer used for different data types. */
65 struct MergedFVar {
66 const Attribute &attr;
67 int channel = -1;
68 vector<char> values;
69 };
70
71 Mesh &mesh;
72 vector<MergedFVar> merged_fvars;
73
74 explicit OsdMesh(Mesh &mesh) : mesh(mesh) {}
75
76 Sdc::Options sdc_options();
77 bool use_smooth_fvar(const Attribute &attr) const;
78 bool use_smooth_fvar() const;
79};
80
81/* OpenSubdiv refiner and patch data structures. */
82
83struct OsdData {
84 unique_ptr<Far::TopologyRefiner> refiner;
85 unique_ptr<Far::PatchTable> patch_table;
86 unique_ptr<Far::PatchMap> patch_map;
87 vector<OsdValue<packed_float3>> refined_verts;
88
89 void build(OsdMesh &osd_mesh);
90};
91
92/* Patch with OpenSubdiv evaluation. */
93
94struct OsdPatch final : Patch {
95 OsdData &osd_data;
96
97 explicit OsdPatch(OsdData &data) : osd_data(data) {}
98 void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, const float u, const float v)
99 const override;
100};
101
103
104#endif
#define final(a, b, c)
Definition BLI_hash_c.hh:21
void build(btStridingMeshInterface *triangles, bool useQuantizedAabbCompression, const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax)
Definition patch.h:12
#define CCL_NAMESPACE_END
VecBase< float, 3 > float3
#define N
#define T
BMesh const char void * data
ResultT eval(const Uniform &uni, const ViewMatrices view, ScreenThicknessParameters thickness_params, sampler2D hiz_tx, sampler2D screen_radiance_tx, sampler2D screen_normal_tx, float3 vP, float3 vN, float4 noise, float2 pixel_size, float search_distance, float angle_bias, const int slice_count, const int sample_count, const bool reversed, const bool ao_only)