Implement particle velocity and acceleration visualization
This commit is contained in:
@@ -272,7 +272,7 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
|
||||
{
|
||||
if (cache->pos == NULL) {
|
||||
static VertexFormat format = { 0 };
|
||||
static unsigned pos_id, rot_id;
|
||||
static unsigned pos_id, rot_id, val_id;
|
||||
int i, curr_point;
|
||||
ParticleData *pa;
|
||||
|
||||
@@ -283,6 +283,7 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
|
||||
/* initialize vertex format */
|
||||
pos_id = VertexFormat_add_attrib(&format, "pos", COMP_F32, 3, KEEP_FLOAT);
|
||||
rot_id = VertexFormat_add_attrib(&format, "rot", COMP_F32, 4, KEEP_FLOAT);
|
||||
val_id = VertexFormat_add_attrib(&format, "val", COMP_F32, 1, KEEP_FLOAT);
|
||||
}
|
||||
|
||||
cache->pos = VertexBuffer_create_with_format(&format);
|
||||
@@ -292,9 +293,25 @@ static void particle_batch_cache_ensure_pos(ParticleSystem *psys, ParticleBatchC
|
||||
if (pa->state.time >= pa->time && pa->state.time < pa->dietime &&
|
||||
!(pa->flag & (PARS_NO_DISP | PARS_UNEXIST)))
|
||||
{
|
||||
float val;
|
||||
|
||||
VertexBuffer_set_attrib(cache->pos, pos_id, curr_point, pa->state.co);
|
||||
VertexBuffer_set_attrib(cache->pos, rot_id, curr_point, pa->state.rot);
|
||||
|
||||
switch (psys->part->draw_col) {
|
||||
case PART_DRAW_COL_VEL:
|
||||
val = len_v3(pa->state.vel) / psys->part->color_vec_max;
|
||||
break;
|
||||
case PART_DRAW_COL_ACC:
|
||||
val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
|
||||
break;
|
||||
default:
|
||||
val = -1.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
VertexBuffer_set_attrib(cache->pos, val_id, curr_point, &val);
|
||||
|
||||
curr_point++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
#include "GPU_texture.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_texture.h"
|
||||
|
||||
#include "draw_common.h"
|
||||
|
||||
@@ -44,6 +46,7 @@
|
||||
/* Colors & Constant */
|
||||
GlobalsUboStorage ts;
|
||||
struct GPUUniformBuffer *globals_ubo = NULL;
|
||||
struct GPUTexture *globals_ramp = NULL;
|
||||
|
||||
void DRW_globals_update(void)
|
||||
{
|
||||
@@ -110,6 +113,26 @@ void DRW_globals_update(void)
|
||||
}
|
||||
|
||||
globals_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), &ts);
|
||||
|
||||
ColorBand ramp = {0};
|
||||
float *colors;
|
||||
int col_size;
|
||||
|
||||
ramp.tot = 3;
|
||||
ramp.data[0].a = 1.0f;
|
||||
ramp.data[0].b = 1.0f;
|
||||
ramp.data[0].pos = 0.0f;
|
||||
ramp.data[1].a = 1.0f;
|
||||
ramp.data[1].g = 1.0f;
|
||||
ramp.data[1].pos = 0.5f;
|
||||
ramp.data[2].a = 1.0f;
|
||||
ramp.data[2].r = 1.0f;
|
||||
ramp.data[2].pos = 1.0f;
|
||||
|
||||
colorband_table_RGBA(&ramp, &colors, &col_size);
|
||||
globals_ramp = GPU_texture_create_1D(col_size, colors, NULL);
|
||||
|
||||
MEM_freeN(colors);
|
||||
}
|
||||
|
||||
/* ********************************* SHGROUP ************************************* */
|
||||
|
||||
@@ -3265,6 +3265,7 @@ void DRW_engines_register(void)
|
||||
}
|
||||
|
||||
extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
|
||||
extern struct GPUTexture *globals_ramp; /* draw_common.c */
|
||||
void DRW_engines_free(void)
|
||||
{
|
||||
DRW_shape_cache_free();
|
||||
@@ -3282,6 +3283,9 @@ void DRW_engines_free(void)
|
||||
if (globals_ubo)
|
||||
GPU_uniformbuffer_free(globals_ubo);
|
||||
|
||||
if (globals_ramp)
|
||||
GPU_texture_free(globals_ramp);
|
||||
|
||||
#ifdef WITH_CLAY_ENGINE
|
||||
BLI_remlink(&R_engines, &DRW_engine_viewport_clay_type);
|
||||
#endif
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_particle.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_texture.h"
|
||||
|
||||
#include "ED_view3d.h"
|
||||
#include "ED_view3d.h"
|
||||
@@ -57,6 +58,7 @@
|
||||
#include "draw_common.h"
|
||||
|
||||
extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
|
||||
extern struct GPUTexture *globals_ramp; /* draw_common.c */
|
||||
extern GlobalsUboStorage ts;
|
||||
|
||||
extern char datatoc_object_outline_resolve_frag_glsl[];
|
||||
@@ -1414,6 +1416,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
|
||||
DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
|
||||
DRW_shgroup_uniform_vec3(shgrp, "outlineColor", ma ? &ma->specr : def_sec_col, 1);
|
||||
DRW_shgroup_uniform_short_to_int(shgrp, "size", &part->draw_size, 1);
|
||||
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
|
||||
DRW_shgroup_call_add(shgrp, geom, mat);
|
||||
break;
|
||||
case PART_DRAW_CROSS:
|
||||
@@ -1435,9 +1438,11 @@ static void OBJECT_cache_populate(void *vedata, Object *ob)
|
||||
if (draw_as != PART_DRAW_DOT) {
|
||||
DRW_shgroup_attrib_float(shgrp, "pos", 3);
|
||||
DRW_shgroup_attrib_float(shgrp, "rot", 4);
|
||||
DRW_shgroup_attrib_float(shgrp, "val", 1);
|
||||
DRW_shgroup_uniform_vec3(shgrp, "color", &ma->r, 1);
|
||||
DRW_shgroup_uniform_short_to_int(shgrp, "draw_size", &part->draw_size, 1);
|
||||
DRW_shgroup_uniform_float(shgrp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
|
||||
DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
|
||||
DRW_shgroup_instance_batch(shgrp, geom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec3 outlineColor;
|
||||
uniform sampler1D ramp;
|
||||
|
||||
in vec4 radii;
|
||||
flat in float finalVal;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main() {
|
||||
@@ -23,11 +26,23 @@ void main() {
|
||||
float midStroke = 0.5 * (radii[1] + radii[2]);
|
||||
|
||||
if (dist > midStroke) {
|
||||
if (finalVal < 0.0) {
|
||||
fragColor.rgb = outlineColor;
|
||||
}
|
||||
else {
|
||||
fragColor.rgb = texture(ramp, finalVal).rgb;
|
||||
}
|
||||
|
||||
fragColor.a = mix(1.0, 0.0, smoothstep(radii[1], radii[0], dist));
|
||||
}
|
||||
else {
|
||||
if (finalVal < 0.0) {
|
||||
fragColor.rgb = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist));
|
||||
}
|
||||
else {
|
||||
fragColor.rgb = texture(ramp, finalVal).rgb;
|
||||
}
|
||||
|
||||
fragColor.a = 1.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform int size;
|
||||
|
||||
in vec3 pos;
|
||||
in float val;
|
||||
|
||||
out vec4 radii;
|
||||
flat out float finalVal;
|
||||
|
||||
void main() {
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
|
||||
@@ -20,4 +23,6 @@ void main() {
|
||||
|
||||
// convert to PointCoord units
|
||||
radii /= size;
|
||||
|
||||
finalVal = val;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
|
||||
uniform vec3 color;
|
||||
uniform sampler1D ramp;
|
||||
|
||||
flat in int finalAxis;
|
||||
flat in float finalVal;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (finalAxis == -1) {
|
||||
if (finalVal < 0.0) {
|
||||
fragColor.rgb = color;
|
||||
}
|
||||
else {
|
||||
fragColor.rgb = texture(ramp, finalVal).rgb;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fragColor.rgb = vec3(0.0);
|
||||
fragColor[finalAxis] = 1.0;
|
||||
|
||||
@@ -9,10 +9,12 @@ uniform int draw_size;
|
||||
|
||||
in vec3 pos;
|
||||
in vec4 rot;
|
||||
in float val;
|
||||
in vec3 inst_pos;
|
||||
in int axis;
|
||||
|
||||
flat out int finalAxis;
|
||||
flat out float finalVal;
|
||||
|
||||
vec3 rotate(vec3 vec, vec4 quat)
|
||||
{
|
||||
@@ -46,4 +48,5 @@ void main()
|
||||
}
|
||||
|
||||
finalAxis = axis;
|
||||
finalVal = val;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user