diff options
author | Luca Rood <dev@lucarood.com> | 2017-05-23 15:37:01 +0300 |
---|---|---|
committer | Luca Rood <dev@lucarood.com> | 2017-05-23 15:37:01 +0300 |
commit | 6f063bdb1c316d31d108d2d609de36a0e4461db5 (patch) | |
tree | 1198ec39a4003af05ccc93c25780c9465ecdc6f0 /source/blender | |
parent | 340e4394d43e8c3eed6ef84dafb4093299f22a29 (diff) |
Use pointers to actual data for particle uniforms
This makes particle color uniforms point directly to material color, and
particle size uniforms point directly to ParticleSettings size.
Diffstat (limited to 'source/blender')
6 files changed, 34 insertions, 33 deletions
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 4ec4cc5bda8..06ec0f746e0 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -2299,6 +2299,7 @@ Batch *DRW_cache_particles_get_prim(int type) float co[3] = {-1.0f, 0.0f, 0.0f}; int axis = -1; VertexBuffer_set_attrib(vbo, pos_id, 0, co); + VertexBuffer_set_attrib(vbo, axis_id, 0, &axis); co[0] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 1, co); @@ -2308,6 +2309,7 @@ Batch *DRW_cache_particles_get_prim(int type) co[0] = 0.0f; co[1] = -1.0f; VertexBuffer_set_attrib(vbo, pos_id, 2, co); + VertexBuffer_set_attrib(vbo, axis_id, 2, &axis); co[1] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 3, co); @@ -2317,6 +2319,7 @@ Batch *DRW_cache_particles_get_prim(int type) co[1] = 0.0f; co[2] = -1.0f; VertexBuffer_set_attrib(vbo, pos_id, 4, co); + VertexBuffer_set_attrib(vbo, axis_id, 4, &axis); co[2] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 5, co); @@ -2343,6 +2346,7 @@ Batch *DRW_cache_particles_get_prim(int type) float co[3] = {0.0f, 0.0f, 0.0f}; int axis = 0; VertexBuffer_set_attrib(vbo, pos_id, 0, co); + VertexBuffer_set_attrib(vbo, axis_id, 0, &axis); co[0] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 1, co); @@ -2352,6 +2356,7 @@ Batch *DRW_cache_particles_get_prim(int type) co[0] = 0.0f; axis = 1; VertexBuffer_set_attrib(vbo, pos_id, 2, co); + VertexBuffer_set_attrib(vbo, axis_id, 2, &axis); co[1] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 3, co); @@ -2361,6 +2366,7 @@ Batch *DRW_cache_particles_get_prim(int type) co[1] = 0.0f; axis = 2; VertexBuffer_set_attrib(vbo, pos_id, 4, co); + VertexBuffer_set_attrib(vbo, axis_id, 4, &axis); co[2] = 1.0f; VertexBuffer_set_attrib(vbo, pos_id, 5, co); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index ee95d4a0598..0259e1055af 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1400,46 +1400,33 @@ static void OBJECT_cache_populate(void *vedata, Object *ob) unit_m4(mat); if (draw_as != PART_DRAW_PATH) { - static float size; - static float axis_size; - static float col[4] = {1.0f, 1.0f, 1.0f, 1.0f}; - static float o_col[4] = {0.5f, 0.5f, 0.5f, 1.0f}; struct Batch *geom = DRW_cache_particles_get_dots(psys); DRWShadingGroup *shgrp; static int screen_space[2] = {0, 1}; + static float def_prim_col[3] = {0.5f, 0.5f, 0.5f}; + static float def_sec_col[3] = {1.0f, 1.0f, 1.0f}; Material *ma = give_current_material(ob, part->omat); - if (ma) { - copy_v3_v3(col, &ma->r); - copy_v3_v3(o_col, &ma->specr); - } - - size = (float)part->draw_size; - axis_size = size * 2.0f; - switch (draw_as) { case PART_DRAW_DOT: shgrp = DRW_shgroup_create(e_data.part_dot_sh, psl->particle); - DRW_shgroup_uniform_vec4(shgrp, "color", col, 1); - DRW_shgroup_uniform_vec4(shgrp, "outlineColor", o_col, 1); - DRW_shgroup_uniform_float(shgrp, "size", &size, 1); + 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_call_add(shgrp, geom, mat); break; case PART_DRAW_CROSS: shgrp = DRW_shgroup_instance_create(e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS)); DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1); - DRW_shgroup_uniform_float(shgrp, "draw_size", &size, 1); break; case PART_DRAW_CIRC: shgrp = DRW_shgroup_instance_create(e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC)); DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[1], 1); - DRW_shgroup_uniform_float(shgrp, "draw_size", &size, 1); break; case PART_DRAW_AXIS: shgrp = DRW_shgroup_instance_create(e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS)); DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1); - DRW_shgroup_uniform_float(shgrp, "draw_size", &axis_size, 1); break; default: break; @@ -1448,7 +1435,8 @@ 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_uniform_vec4(shgrp, "color", col, 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_instance_batch(shgrp, geom); } diff --git a/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl b/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl index eae5ee633ae..044a949ef98 100644 --- a/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl +++ b/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl @@ -1,6 +1,6 @@ -uniform vec4 color; -uniform vec4 outlineColor; +uniform vec3 color; +uniform vec3 outlineColor; in vec4 radii; out vec4 fragColor; @@ -23,11 +23,12 @@ void main() { float midStroke = 0.5 * (radii[1] + radii[2]); if (dist > midStroke) { - fragColor.rgb = outlineColor.rgb; - fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist)); + fragColor.rgb = outlineColor; + fragColor.a = mix(1.0, 0.0, smoothstep(radii[1], radii[0], dist)); } else { - fragColor = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist)); + fragColor.rgb = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist)); + fragColor.a = 1.0; } if (fragColor.a == 0.0) { diff --git a/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl b/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl index d9d30c8e677..36b665173f1 100644 --- a/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl +++ b/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl @@ -1,6 +1,6 @@ uniform mat4 ModelViewProjectionMatrix; -uniform float size; +uniform int size; in vec3 pos; out vec4 radii; diff --git a/source/blender/draw/modes/shaders/object_particle_prim_frag.glsl b/source/blender/draw/modes/shaders/object_particle_prim_frag.glsl index 50572f293d9..791d38390a2 100644 --- a/source/blender/draw/modes/shaders/object_particle_prim_frag.glsl +++ b/source/blender/draw/modes/shaders/object_particle_prim_frag.glsl @@ -1,5 +1,5 @@ -uniform vec4 color; +uniform vec3 color; flat in int finalAxis; @@ -8,12 +8,12 @@ out vec4 fragColor; void main() { if (finalAxis == -1) { - fragColor = color; + fragColor.rgb = color; } else { - vec4 col = vec4(0.0); - col[finalAxis] = 1.0; - col.a = 1.0; - fragColor = col; + fragColor.rgb = vec3(0.0); + fragColor[finalAxis] = 1.0; } + + fragColor.a = 1.0; } diff --git a/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl b/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl index 2483ca5b2d2..ff16f61b884 100644 --- a/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl +++ b/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl @@ -5,7 +5,7 @@ uniform mat4 ModelViewMatrix; uniform mat4 ProjectionMatrix; uniform int screen_space; uniform float pixel_size; -uniform float draw_size; +uniform int draw_size; in vec3 pos; in vec4 rot; @@ -36,7 +36,13 @@ void main() gl_Position = ProjectionMatrix * gl_Position; } else { - gl_Position = ModelViewProjectionMatrix * vec4(pos + rotate(inst_pos * pix_size * draw_size, rot), 1.0); + int size = draw_size; + + if (axis > -1) { + size *= 2; + } + + gl_Position = ModelViewProjectionMatrix * vec4(pos + rotate(inst_pos * pix_size * size, rot), 1.0); } finalAxis = axis; |