Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_cache_impl_lattice.c
| Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | |||||
| static const BPoint *lattice_render_data_vert_bpoint(const LatticeRenderData *rdata, | static const BPoint *lattice_render_data_vert_bpoint(const LatticeRenderData *rdata, | ||||
| const int vert_idx) | const int vert_idx) | ||||
| { | { | ||||
| BLI_assert(rdata->types & LR_DATATYPE_VERT); | BLI_assert(rdata->types & LR_DATATYPE_VERT); | ||||
| return &rdata->bp[vert_idx]; | return &rdata->bp[vert_idx]; | ||||
| } | } | ||||
| /* TODO, move into shader? */ | |||||
| static void rgb_from_weight(float r_rgb[3], const float weight) | |||||
| { | |||||
| const float blend = ((weight / 2.0f) + 0.5f); | |||||
| if (weight <= 0.25f) { /* blue->cyan */ | |||||
| r_rgb[0] = 0.0f; | |||||
| r_rgb[1] = blend * weight * 4.0f; | |||||
| r_rgb[2] = blend; | |||||
| } | |||||
| else if (weight <= 0.50f) { /* cyan->green */ | |||||
| r_rgb[0] = 0.0f; | |||||
| r_rgb[1] = blend; | |||||
| r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f)); | |||||
| } | |||||
| else if (weight <= 0.75f) { /* green->yellow */ | |||||
| r_rgb[0] = blend * ((weight - 0.50f) * 4.0f); | |||||
| r_rgb[1] = blend; | |||||
| r_rgb[2] = 0.0f; | |||||
| } | |||||
| else if (weight <= 1.0f) { /* yellow->red */ | |||||
| r_rgb[0] = blend; | |||||
| r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f)); | |||||
| r_rgb[2] = 0.0f; | |||||
| } | |||||
| else { | |||||
| /* exceptional value, unclamped or nan, | |||||
| * avoid uninitialized memory use */ | |||||
| r_rgb[0] = 1.0f; | |||||
| r_rgb[1] = 0.0f; | |||||
| r_rgb[2] = 1.0f; | |||||
| } | |||||
| } | |||||
| static void lattice_render_data_weight_col_get(const LatticeRenderData *rdata, | |||||
| const int vert_idx, | |||||
| const int actdef, | |||||
| float r_col[4]) | |||||
| { | |||||
| if (actdef > -1) { | |||||
| float weight = defvert_find_weight(rdata->dvert + vert_idx, actdef); | |||||
| if (U.flag & USER_CUSTOM_RANGE) { | |||||
| BKE_colorband_evaluate(&U.coba_weight, weight, r_col); | |||||
| } | |||||
| else { | |||||
| rgb_from_weight(r_col, weight); | |||||
| } | |||||
| r_col[3] = 1.0f; | |||||
| } | |||||
| else { | |||||
| zero_v4(r_col); | |||||
| } | |||||
| } | |||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /* Lattice GPUBatch Cache */ | /* Lattice GPUBatch Cache */ | ||||
| typedef struct LatticeBatchCache { | typedef struct LatticeBatchCache { | ||||
| GPUVertBuf *pos; | GPUVertBuf *pos; | ||||
| GPUIndexBuf *edges; | GPUIndexBuf *edges; | ||||
| GPUBatch *all_verts; | GPUBatch *all_verts; | ||||
| ▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | |||||
| static GPUVertBuf *lattice_batch_cache_get_pos(LatticeRenderData *rdata, | static GPUVertBuf *lattice_batch_cache_get_pos(LatticeRenderData *rdata, | ||||
| LatticeBatchCache *cache, | LatticeBatchCache *cache, | ||||
| bool use_weight, | bool use_weight, | ||||
| const int actdef) | const int actdef) | ||||
| { | { | ||||
| BLI_assert(rdata->types & LR_DATATYPE_VERT); | BLI_assert(rdata->types & LR_DATATYPE_VERT); | ||||
| if (cache->pos == NULL) { | if (cache->pos == NULL) { | ||||
| static GPUVertFormat format = {0}; | GPUVertFormat format = {0}; | ||||
| static struct { | struct { | ||||
| uint pos, col; | uint pos, col; | ||||
| } attr_id; | } attr_id; | ||||
| GPU_vertformat_clear(&format); | |||||
| /* initialize vertex format */ | |||||
| attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | attr_id.pos = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | ||||
| if (use_weight) { | if (use_weight) { | ||||
| attr_id.col = GPU_vertformat_attr_add(&format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | attr_id.col = GPU_vertformat_attr_add(&format, "weight", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| } | } | ||||
| const int vert_len = lattice_render_data_verts_len_get(rdata); | const int vert_len = lattice_render_data_verts_len_get(rdata); | ||||
| cache->pos = GPU_vertbuf_create_with_format(&format); | cache->pos = GPU_vertbuf_create_with_format(&format); | ||||
| GPU_vertbuf_data_alloc(cache->pos, vert_len); | GPU_vertbuf_data_alloc(cache->pos, vert_len); | ||||
| for (int i = 0; i < vert_len; i++) { | for (int i = 0; i < vert_len; i++) { | ||||
| const BPoint *bp = lattice_render_data_vert_bpoint(rdata, i); | const BPoint *bp = lattice_render_data_vert_bpoint(rdata, i); | ||||
| GPU_vertbuf_attr_set(cache->pos, attr_id.pos, i, bp->vec); | GPU_vertbuf_attr_set(cache->pos, attr_id.pos, i, bp->vec); | ||||
| if (use_weight) { | if (use_weight) { | ||||
| float w_col[4]; | const float no_active_weight = 666.0f; | ||||
| lattice_render_data_weight_col_get(rdata, i, actdef, w_col); | float weight = (actdef > -1) ? defvert_find_weight(rdata->dvert + i, actdef) : | ||||
| w_col[3] = 1.0f; | no_active_weight; | ||||
| GPU_vertbuf_attr_set(cache->pos, attr_id.col, i, &weight); | |||||
jbakker: We should make a constant for this number and name it the same in the shaders | |||||
| GPU_vertbuf_attr_set(cache->pos, attr_id.col, i, w_col); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return cache->pos; | return cache->pos; | ||||
| } | } | ||||
| static GPUIndexBuf *lattice_batch_cache_get_edges(LatticeRenderData *rdata, | static GPUIndexBuf *lattice_batch_cache_get_edges(LatticeRenderData *rdata, | ||||
| ▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines | |||||
We should make a constant for this number and name it the same in the shaders