19template<
typename GPUType>
29template<
typename GPUType>
35 for (const int face : range) {
36 normals.slice(faces[face]).fill(gpu::convert_normal<GPUType>(face_normals[face]));
41template<
typename GPUType>
44 const auto get_vert_normals = [&]() {
66 for (const int face : range) {
67 if (sharp_faces[face]) {
68 normals.slice(faces[face]).fill(gpu::convert_normal<GPUType>(face_normals[face]));
71 for (const int corner : faces[face]) {
72 normals[corner] = gpu::convert_normal<GPUType>(vert_normals[corner_verts[corner]]);
80template<
typename GPUType>
86 for (const int face_index : range) {
87 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
88 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
89 const IndexRange face_range(BM_elem_index_get(loop), face.len);
90 for (const int corner : face_range) {
91 normals[corner] = gpu::convert_normal<GPUType>(
92 BM_ELEM_CD_GET_FLOAT_P(loop->v, mr.bm_free_normal_offset_vert));
98 else if (!mr.bm_vert_normals.is_empty()) {
102 for (const int face_index : range) {
103 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
104 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
105 const IndexRange face_range(BM_elem_index_get(loop), face.len);
106 for (const int corner : face_range) {
107 normals[corner] = vert_normals_converted[BM_elem_index_get(loop->v)];
115 for (const int face_index : range) {
116 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
117 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
118 const IndexRange face_range(BM_elem_index_get(loop), face.len);
119 for (const int corner : face_range) {
120 normals[corner] = gpu::convert_normal<GPUType>(loop->v->no);
128template<
typename GPUType>
134 for (const int face_index : range) {
135 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
136 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
137 normals.slice(face_range)
138 .fill(gpu::convert_normal<GPUType>(
139 BM_ELEM_CD_GET_FLOAT_P(&face, mr.bm_free_normal_offset_face)));
143 else if (!mr.bm_face_normals.is_empty()) {
145 for (const int face_index : range) {
146 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
147 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
148 normals.slice(face_range)
149 .fill(gpu::convert_normal<GPUType>(mr.bm_face_normals[face_index]));
155 for (const int face_index : range) {
156 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
157 const IndexRange face_range(BM_elem_index_get(BM_FACE_FIRST_LOOP(&face)), face.len);
158 normals.slice(face_range).fill(gpu::convert_normal<GPUType>(face.no));
164template<
typename GPUType>
176 for (const int face_index : range) {
177 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
178 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
179 const IndexRange face_range(BM_elem_index_get(loop), face.len);
180 for (const int corner : face_range) {
181 normals[corner] = gpu::convert_normal<GPUType>(
182 BM_ELEM_CD_GET_FLOAT_P(loop, mr.bm_free_normal_offset_corner));
188 else if (!mr.bm_loop_normals.is_empty()) {
193 for (const int face_index : range) {
194 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
195 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
196 const IndexRange face_range(BM_elem_index_get(loop), face.len);
198 if (!BM_elem_flag_test(&face, BM_ELEM_SMOOTH)) {
199 if (!mr.bm_face_normals.is_empty()) {
200 normals.slice(face_range)
201 .fill(gpu::convert_normal<GPUType>(mr.bm_face_normals[face_index]));
204 normals.slice(face_range).fill(gpu::convert_normal<GPUType>(face.no));
208 if (!mr.bm_vert_normals.is_empty()) {
209 for (const int corner : face_range) {
210 normals[corner] = gpu::convert_normal<GPUType>(
211 mr.bm_vert_normals[BM_elem_index_get(loop->v)]);
216 for (const int corner : face_range) {
217 normals[corner] = gpu::convert_normal<GPUType>(loop->v->no);
302 const float3 default_normal(0.0f, 0.0f, 0.0f);
324 const Mesh *coarse_mesh = subdiv_cache.
mesh;
326 "vnor", gpu::VertAttrType::SFLOAT_32_32_32);
329 src->data<
float3>().copy_from(coarse_mesh->corner_normals());
342 "vnor", gpu::VertAttrType::SFLOAT_32_32_32);
349 subdiv_corner_verts.get(),
357 subdiv_cache, &
pos, vert_normals.get(), subdiv_corner_verts.get(), lnor.get());
blender::gpu::VertBuf * GPU_vertbuf_create_on_device(const GPUVertFormat &format, uint v_len)
void GPU_vertbuf_use(blender::gpu::VertBuf *)
static blender::gpu::VertBuf * GPU_vertbuf_create_with_format(const GPUVertFormat &format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
void GPU_vertbuf_update_sub(blender::gpu::VertBuf *verts, uint start, uint len, const void *data)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
constexpr bool is_empty() const
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr MutableSpan take_back(const int64_t n) const
constexpr T * data() const
constexpr void fill(const T &value) const
constexpr MutableSpan take_front(const int64_t n) const
constexpr int64_t size() const
static float normals[][3]
VecBase< short, 4 > short4
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, int64_t grain_size=4096)
static void extract_face_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
gpu::VertBufPtr extract_vert_normals(const MeshRenderData &mr)
void draw_subdiv_build_lnor_buffer(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *vert_normals, gpu::VertBuf *subdiv_corner_verts, gpu::VertBuf *lnor)
void draw_subdiv_interp_corner_normals(const DRWSubdivCache &cache, gpu::VertBuf &src_data, gpu::VertBuf &dst_data)
static void extract_vert_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
gpu::VertBufPtr extract_normals(const MeshRenderData &mr, bool use_hq)
int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
static void extract_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void update_loose_normals(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &lnor)
static void extract_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static const GPUVertFormat & get_normals_format()
gpu::VertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
gpu::VertBufPtr extract_normals_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &pos)
static void extract_face_normals(const MeshRenderData &mr, MutableSpan< GPUType > normals)
void draw_subdiv_accumulate_normals(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vertex_loop_map, gpu::VertBuf *vert_normals)
void convert_normals(Span< float3 > src, MutableSpan< GPUType > dst)
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
blender::VecBase< int16_t, 4 > short4
VecBase< float, 3 > float3
int * subdiv_loop_subdiv_vert_index
gpu::VertBuf * subdiv_vertex_face_adjacency_offsets
gpu::VertBuf * subdiv_vertex_face_adjacency
bool use_custom_loop_normals
bool use_simplify_normals
MeshExtractType extract_type
VArraySpan< bool > sharp_faces
int bm_free_normal_offset_face
Span< float3 > face_normals
int bm_free_normal_offset_corner
Span< float3 > corner_normals
OffsetIndices< int > faces
bke::MeshNormalDomain normals_domain
int bm_free_normal_offset_vert