Use pointers to actual data for particle uniforms
authorLuca Rood <dev@lucarood.com>
Tue, 23 May 2017 12:37:01 +0000 (14:37 +0200)
committerLuca Rood <dev@lucarood.com>
Tue, 23 May 2017 12:37:01 +0000 (14:37 +0200)
This makes particle color uniforms point directly to material color, and
particle size uniforms point directly to ParticleSettings size.

source/blender/draw/intern/draw_cache.c
source/blender/draw/modes/object_mode.c
source/blender/draw/modes/shaders/object_particle_dot_frag.glsl
source/blender/draw/modes/shaders/object_particle_dot_vert.glsl
source/blender/draw/modes/shaders/object_particle_prim_frag.glsl
source/blender/draw/modes/shaders/object_particle_prim_vert.glsl

index 4ec4cc5bda8ab32f904737a8649261461f8051fa..06ec0f746e05698e631bcd88ccdaeb85d5bbc57a 100644 (file)
@@ -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);
index ee95d4a0598cdad6d4233cfc8a9ee48359be927f..0259e1055afc23bd738e03aa94cb114e0165c259 100644 (file)
@@ -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);
                                                }
index eae5ee633aec4bf493aec4729dfe6ba766705181..044a949ef98c6b959b15c32cd469767bfb180222 100644 (file)
@@ -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) {
index d9d30c8e6777c7b5aa8f85d2a35a84e5fb5c8f8f..36b665173f15b8c925f544619ba008babac92a92 100644 (file)
@@ -1,6 +1,6 @@
 
 uniform mat4 ModelViewProjectionMatrix;
-uniform float size;
+uniform int size;
 
 in vec3 pos;
 out vec4 radii;
index 50572f293d9a0dfdc5ca68e542e8e0e9b15d156a..791d38390a2001d2f9e1350c5adc40a7bb2721c1 100644 (file)
@@ -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;
 }
index 2483ca5b2d24c8e42551288913ba8fe78307b6bf..ff16f61b88479fb125f19559e3f81aeb73aaa37c 100644 (file)
@@ -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;