diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-17 17:20:25 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-17 17:20:25 +0300 |
commit | eaa87101cd5a20e577748bfff95b7cb06b04dd4b (patch) | |
tree | 8243ee6bd1479299f23819ef2765720fc9a18889 /source/blender/draw/intern/draw_cache.c | |
parent | 71f091a631c2deae08ff289184f928538b527cb3 (diff) |
Metaball: Evaluate metaball objects as mesh components
With the ultimate goal of simplifying drawing and evaluation,
this patch makes the following changes and removes code:
- Use `Mesh` instead of `DispList` for evaluated basis metaballs.
- Remove all `DispList` drawing code, which is now unused.
- Simplify code that converts evaluated metaballs to meshes.
- Store the evaluated mesh in the evaluated geometry set.
This has the following indirect benefits:
- Evaluated meshes from metaball objects can be used in geometry nodes.
- Renderers can ignore evaluated metaball objects completely
- Cycles rendering no longer has to convert to mesh from `DispList`.
- We get closer to removing `DispList` completely.
- Optimizations to mesh rendering will also apply to metaball objects.
The vertex normals on the evaluated mesh are technically invalid;
the regular calculation wouldn't reproduce them. Metaball objects
don't support modifiers though, so it shouldn't be a problem.
Eventually we can support per-vertex custom normals (T93551).
Differential Revision: https://developer.blender.org/D14593
Diffstat (limited to 'source/blender/draw/intern/draw_cache.c')
-rw-r--r-- | source/blender/draw/intern/draw_cache.c | 83 |
1 files changed, 33 insertions, 50 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 4c0f025e934..275392ec56a 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -780,6 +780,39 @@ GPUBatch *DRW_cache_normal_arrow_get(void) return SHC.drw_normal_arrow; } +void DRW_vertbuf_create_wiredata(GPUVertBuf *vbo, const int vert_len) +{ + static GPUVertFormat format = {0}; + static struct { + uint wd; + } attr_id; + if (format.attr_len == 0) { + /* initialize vertex format */ + if (!GPU_crappy_amd_driver()) { + /* Some AMD drivers strangely crash with a vbo with this format. */ + attr_id.wd = GPU_vertformat_attr_add( + &format, "wd", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT); + } + else { + attr_id.wd = GPU_vertformat_attr_add(&format, "wd", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); + } + } + + GPU_vertbuf_init_with_format(vbo, &format); + GPU_vertbuf_data_alloc(vbo, vert_len); + + if (GPU_vertbuf_get_format(vbo)->stride == 1) { + memset(GPU_vertbuf_get_data(vbo), 0xFF, (size_t)vert_len); + } + else { + GPUVertBufRaw wd_step; + GPU_vertbuf_attr_get_raw_data(vbo, attr_id.wd, &wd_step); + for (int i = 0; i < vert_len; i++) { + *((float *)GPU_vertbuf_raw_step(&wd_step)) = 1.0f; + } + } +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -836,8 +869,6 @@ GPUBatch *DRW_cache_object_edge_detection_get(Object *ob, bool *r_is_manifold) return NULL; case OB_FONT: return NULL; - case OB_MBALL: - return DRW_cache_mball_edge_detection_get(ob, r_is_manifold); case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -860,8 +891,6 @@ GPUBatch *DRW_cache_object_face_wireframe_get(Object *ob) return NULL; case OB_FONT: return NULL; - case OB_MBALL: - return DRW_cache_mball_face_wireframe_get(ob); case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -887,8 +916,6 @@ GPUBatch *DRW_cache_object_loose_edges_get(struct Object *ob) return NULL; case OB_FONT: return NULL; - case OB_MBALL: - return NULL; case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -911,8 +938,6 @@ GPUBatch *DRW_cache_object_surface_get(Object *ob) return NULL; case OB_FONT: return NULL; - case OB_MBALL: - return DRW_cache_mball_surface_get(ob); case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -936,8 +961,6 @@ GPUVertBuf *DRW_cache_object_pos_vertbuf_get(Object *ob) case OB_SURF: case OB_FONT: return NULL; - case OB_MBALL: - return DRW_mball_batch_cache_pos_vertbuf_get(ob); case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -968,8 +991,6 @@ int DRW_cache_object_material_count_get(struct Object *ob) case OB_SURF: case OB_FONT: return DRW_curve_material_count_get(ob->data); - case OB_MBALL: - return DRW_metaball_material_count_get(ob->data); case OB_CURVES: return DRW_curves_material_count_get(ob->data); case OB_POINTCLOUD: @@ -997,8 +1018,6 @@ GPUBatch **DRW_cache_object_surface_material_get(struct Object *ob, return NULL; case OB_FONT: return NULL; - case OB_MBALL: - return DRW_cache_mball_surface_shaded_get(ob, gpumat_array, gpumat_array_len); case OB_CURVES: return NULL; case OB_POINTCLOUD: @@ -2972,39 +2991,6 @@ GPUBatch *DRW_cache_curve_vert_overlay_get(Object *ob) /** \} */ /* -------------------------------------------------------------------- */ -/** \name MetaBall - * \{ */ - -GPUBatch *DRW_cache_mball_surface_get(Object *ob) -{ - BLI_assert(ob->type == OB_MBALL); - return DRW_metaball_batch_cache_get_triangles_with_normals(ob); -} - -GPUBatch *DRW_cache_mball_edge_detection_get(Object *ob, bool *r_is_manifold) -{ - BLI_assert(ob->type == OB_MBALL); - return DRW_metaball_batch_cache_get_edge_detection(ob, r_is_manifold); -} - -GPUBatch *DRW_cache_mball_face_wireframe_get(Object *ob) -{ - BLI_assert(ob->type == OB_MBALL); - return DRW_metaball_batch_cache_get_wireframes_face(ob); -} - -GPUBatch **DRW_cache_mball_surface_shaded_get(Object *ob, - struct GPUMaterial **gpumat_array, - uint gpumat_array_len) -{ - BLI_assert(ob->type == OB_MBALL); - MetaBall *mb = ob->data; - return DRW_metaball_batch_cache_get_surface_shaded(ob, mb, gpumat_array, gpumat_array_len); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Font * \{ */ @@ -3322,9 +3308,6 @@ void drw_batch_cache_validate(Object *ob) case OB_SURF: DRW_curve_batch_cache_validate((Curve *)ob->data); break; - case OB_MBALL: - DRW_mball_batch_cache_validate((MetaBall *)ob->data); - break; case OB_LATTICE: DRW_lattice_batch_cache_validate((Lattice *)ob->data); break; |