diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 21:42:55 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-04-05 21:42:55 +0300 |
commit | eae36be372a6b16ee3e76eff0485a47da4f3c230 (patch) | |
tree | d1ca2dc30951e31f1b91eed6a4edfdfb0824bf1f /source/blender/gpu | |
parent | a3e122b9aec59fc303c2375a78183cfb8642c14f (diff) |
Refactor: Unify vertex and sculpt colors into new
color attribute system.
This commit removes sculpt colors from experimental
status and unifies it with vertex colors. It
introduces the concept of "color attributes", which
are any attributes that represents colors. Color
attributes can be represented with byte or floating-point
numbers and can be stored in either vertices or
face corners.
Color attributes share a common namespace
(so you can no longer have a floating-point
sculpt color attribute and a byte vertex color
attribute with the same name).
Note: this commit does not include vertex paint mode,
which is a separate patch, see:
https://developer.blender.org/D14179
Differential Revision: https://developer.blender.org/D12587
Ref D12587
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 7 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 61 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 1 |
3 files changed, 53 insertions, 16 deletions
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 610b0f384a2..1af0080baef 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -9,6 +9,8 @@ #include <stddef.h> +#include "BKE_attribute.h" + #ifdef __cplusplus extern "C" { #endif @@ -82,11 +84,12 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, const struct MVert *mvert, const float (*vert_normals)[3], const float *vmask, - const struct MLoopCol *vcol, + const void *vcol_data, + int vcol_type, + AttributeDomain vcol_domain, const int *sculpt_face_sets, int face_sets_color_seed, int face_sets_color_default, - const struct MPropCol *vtcol, int update_flags); /** diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index b90dd9c2a8a..110fdfbd2d9 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -25,7 +25,9 @@ #include "DNA_userdef_types.h" #include "BKE_DerivedMesh.h" +#include "BKE_attribute.h" #include "BKE_ccg.h" +#include "BKE_customdata.h" #include "BKE_mesh.h" #include "BKE_paint.h" #include "BKE_pbvh.h" @@ -196,18 +198,25 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, const MVert *mvert, const float (*vert_normals)[3], const float *vmask, - const MLoopCol *vcol, + const void *vcol_data, + int vcol_type, + AttributeDomain vcol_domain, const int *sculpt_face_sets, - const int face_sets_color_seed, - const int face_sets_color_default, - const MPropCol *vtcol, - const int update_flags) + int face_sets_color_seed, + int face_sets_color_default, + int update_flags) { + const MPropCol *vtcol = vcol_type == CD_PROP_COLOR ? vcol_data : NULL; + const MLoopCol *vcol = vcol_type == CD_MLOOPCOL ? vcol_data : NULL; + const float(*f3col)[3] = vcol_type == CD_PROP_FLOAT3 ? vcol_data : NULL; + + const bool color_loops = vcol_domain == ATTR_DOMAIN_CORNER; + const bool show_vcol = (vtcol || vcol || f3col) && + (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; + const bool show_mask = vmask && (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0; const bool show_face_sets = sculpt_face_sets && (update_flags & GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS) != 0; - const bool show_vcol = (vcol || (vtcol && U.experimental.use_sculpt_vertex_colors)) && - (update_flags & GPU_PBVH_BUFFERS_SHOW_VCOL) != 0; bool empty_mask = true; bool default_face_set = true; @@ -290,16 +299,40 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers, /* Vertex Colors. */ if (show_vcol) { ushort scol[4] = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX}; - if (vtcol && U.experimental.use_sculpt_vertex_colors) { - scol[0] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[0]); - scol[1] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[1]); - scol[2] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[2]); - scol[3] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[3]); + if (vtcol) { + if (color_loops) { + scol[0] = unit_float_to_ushort_clamp(vtcol[lt->tri[j]].color[0]); + scol[1] = unit_float_to_ushort_clamp(vtcol[lt->tri[j]].color[1]); + scol[2] = unit_float_to_ushort_clamp(vtcol[lt->tri[j]].color[2]); + scol[3] = unit_float_to_ushort_clamp(vtcol[lt->tri[j]].color[3]); + } + else { + scol[0] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[0]); + scol[1] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[1]); + scol[2] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[2]); + scol[3] = unit_float_to_ushort_clamp(vtcol[vtri[j]].color[3]); + } memcpy(GPU_vertbuf_raw_step(&col_step), scol, sizeof(scol)); } - else { + else if (f3col) { + if (color_loops) { + scol[0] = unit_float_to_ushort_clamp(f3col[lt->tri[j]][0]); + scol[1] = unit_float_to_ushort_clamp(f3col[lt->tri[j]][1]); + scol[2] = unit_float_to_ushort_clamp(f3col[lt->tri[j]][2]); + scol[3] = USHRT_MAX; + } + else { + scol[0] = unit_float_to_ushort_clamp(f3col[vtri[j]][0]); + scol[1] = unit_float_to_ushort_clamp(f3col[vtri[j]][1]); + scol[2] = unit_float_to_ushort_clamp(f3col[vtri[j]][2]); + scol[3] = USHRT_MAX; + } + memcpy(GPU_vertbuf_raw_step(&col_step), scol, sizeof(scol)); + } + else if (vcol) { const uint loop_index = lt->tri[j]; - const MLoopCol *mcol = &vcol[loop_index]; + const MLoopCol *mcol = vcol + (color_loops ? loop_index : vtri[j]); + scol[0] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->r]); scol[1] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->g]); scol[2] = unit_float_to_ushort_clamp(BLI_color_from_srgb_table[mcol->b]); diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index a96f157981f..e462308d3ee 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -635,6 +635,7 @@ static const char *attr_prefix_get(CustomDataType type) case CD_TANGENT: return "t"; case CD_MCOL: + case CD_MLOOPCOL: return "c"; case CD_PROP_COLOR: return "c"; |