22template<
typename GPUType>
28template<
typename GPUType>
33 for (const int i : range) {
34 const BMVert *vert = BM_vert_at_index(&const_cast<BMesh &>(bm), i);
35 vert_data[i] = gpu::convert_normal<GPUType>(bm_vert_no_get(mr, vert));
40template<
typename GPUType>
46template<
typename GPUType>
51 for (const int i : range) {
52 const BMFace *face = BM_face_at_index(&const_cast<BMesh &>(bm), i);
53 face_data[i] = gpu::convert_normal<GPUType>(bm_face_no_get(mr, face));
58template<
typename GPUType>
73 for (const int face : range) {
74 if (!sharp_faces.is_empty() && sharp_faces[face]) {
75 normals.slice(faces[face]).fill(gpu::convert_normal<GPUType>(face_normals[face]));
78 for (const int corner : faces[face]) {
79 normals[corner] = gpu::convert_normal<GPUType>(vert_normals[corner_verts[corner]]);
86template<
typename GPUType>
92 for (const int face_index : range) {
93 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
94 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
95 const IndexRange face_range(BM_elem_index_get(loop), face.len);
96 for (const int corner : face_range) {
97 normals[corner] = gpu::convert_normal<GPUType>(
98 BM_ELEM_CD_GET_FLOAT_P(loop, mr.bm_free_normal_offset_corner));
105 if (!mr.bm_loop_normals.is_empty()) {
109 threading::parallel_for(IndexRange(bm.
totface), 2048, [&](
const IndexRange range) {
110 for (const int face_index : range) {
111 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
112 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
113 const IndexRange face_range(BM_elem_index_get(loop), face.len);
114 if (!BM_elem_flag_test(&face, BM_ELEM_SMOOTH)) {
115 normals.slice(face_range).fill(gpu::convert_normal<GPUType>(bm_face_no_get(mr, &face)));
118 for (const int corner : face_range) {
119 normals[corner] = gpu::convert_normal<GPUType>(bm_vert_no_get(mr, loop->v));
127template<
typename GPUType>
231 const float3 default_normal(0.0f, 0.0f, 0.0f);
253 const Mesh *coarse_mesh = subdiv_cache.
mesh;
255 "vnor", gpu::VertAttrType::SFLOAT_32_32_32);
258 src->data<
float3>().copy_from(coarse_mesh->corner_normals());
271 "vnor", gpu::VertAttrType::SFLOAT_32_32_32);
278 subdiv_corner_verts.get(),
286 subdiv_cache, &pos, vert_normals.get(), subdiv_corner_verts.get(), lnor.get());
#define BLI_assert_unreachable()
Span< T > as_span() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr IndexRange()=default
constexpr MutableSpan take_back(const int64_t n) const
constexpr T * data() const
constexpr void copy_from(Span< T > values) const
constexpr MutableSpan take_front(const int64_t n) const
IndexRange index_range() const
void scatter_face_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
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)
gpu::VertBufPtr extract_normals(const MeshRenderData &mr, MeshBufferCache &cache, bool use_hq)
static void extract_vert_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > vert_data)
static void extract_vert_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > vert_data)
int subdiv_full_vbo_size(const MeshRenderData &mr, const DRWSubdivCache &cache)
static void extract_corner_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > normals)
static void update_loose_normals(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &lnor)
static void extract_face_normals_bm(const MeshRenderData &mr, MutableSpan< GPUType > face_data)
static void extract_face_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > face_data)
static Span< float3 > get_vert_normals(const MeshRenderData &mr)
void gather_vert_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
static const GPUVertFormat & get_normals_format()
gpu::VertBuf * draw_subdiv_build_origindex_buffer(int *vert_origindex, uint num_loops)
static void extract_corner_normals_mesh(const MeshRenderData &mr, MutableSpan< GPUType > normals)
gpu::VertBufPtr extract_normals_subdiv(const MeshRenderData &mr, const DRWSubdivCache &subdiv_cache, gpu::VertBuf &pos)
void draw_subdiv_accumulate_normals(const DRWSubdivCache &cache, gpu::VertBuf *pos, gpu::VertBuf *face_adjacency_offsets, gpu::VertBuf *face_adjacency_lists, gpu::VertBuf *vert_loop_map, gpu::VertBuf *vert_normals)
void loose_data_upload(const MeshRenderData &mr, const Span< T > loose_data, gpu::VertBuf &dst)
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))
void GPU_vertformat_alias_add(GPUVertFormat *, StringRef alias)
gpu::VertBuf * GPU_vertbuf_create_on_device(const GPUVertFormat &format, uint v_len)
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_use(gpu::VertBuf *)
void GPU_vertbuf_update_sub(gpu::VertBuf *verts, uint start, uint len, const void *data)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
VecBase< float, 3 > float3
gpu::VertBuf * subdiv_vert_face_adjacency
int * subdiv_loop_subdiv_vert_index
bool use_custom_loop_normals
gpu::VertBuf * subdiv_vert_face_adjacency_offsets
bool use_simplify_normals
MeshExtractType extract_type
VArraySpan< bool > sharp_faces
Span< float3 > face_normals
int bm_free_normal_offset_corner
Span< float3 > corner_normals
OffsetIndices< int > faces
bke::MeshNormalDomain normals_domain
ccl_device_inline bool is_mesh(const ccl_global KernelLightTreeEmitter *kemitter)