Commit: 6cb1d3c8f1f5609db8bc49e81de223994257a02c
Author: Antonio Vazquez
Date:   Fri Aug 18 13:10:16 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB6cb1d3c8f1f5609db8bc49e81de223994257a02c

New VFX Swirl modifier

===================================================================

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/draw/CMakeLists.txt
M       source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
M       source/blender/draw/engines/gpencil/gpencil_engine.c
M       source/blender/draw/engines/gpencil/gpencil_engine.h
M       source/blender/draw/engines/gpencil/gpencil_vfx.c
A       source/blender/draw/engines/gpencil/shaders/gpencil_swirl_frag.glsl
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/CMakeLists.txt
M       source/blender/modifiers/MOD_modifiertypes.h
A       source/blender/modifiers/intern/MOD_gpencilswirl.c
M       source/blender/modifiers/intern/MOD_util.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index c92f669a30b..007fdbcca3d 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1816,6 +1816,20 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.enabled = md.use_lines
         col.prop(md, "color")
 
+    def GP_SWIRL(self, layout, ob, md):
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Center:")
+        col.prop(md, "center", text="")
+
+        col.separator()
+        col.prop(md, "radius")
+        col.prop(md, "angle")
+
+        col.separator()
+        col.prop(md, "transparent")
+
 
 classes = (
     DATA_PT_modifiers,
diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index bfb8450daea..2010a721480 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -217,6 +217,7 @@ 
data_to_c_simple(engines/gpencil/shaders/gpencil_point_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_wave_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_pixel_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_swirl_frag.glsl SRC)
 
 list(APPEND INC
 )
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c 
b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 644f8cd6b75..1340d0de2e2 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -94,6 +94,9 @@ void gpencil_object_cache_add(tGPencilObjectCache *cache, 
Object *ob, int *gp_ca
        cache[*gp_cache_used].init_vfx_pixel_sh = NULL;
        cache[*gp_cache_used].end_vfx_pixel_sh = NULL;
 
+       cache[*gp_cache_used].init_vfx_swirl_sh = NULL;
+       cache[*gp_cache_used].end_vfx_swirl_sh = NULL;
+
        /* calculate zdepth from point of view */
        float zdepth = 0.0;
        if (rv3d->is_persp) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c 
b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 3344df5e699..24a836e27a5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -48,6 +48,7 @@ extern char datatoc_gpencil_point_frag_glsl[];
 extern char datatoc_gpencil_gaussian_blur_frag_glsl[];
 extern char datatoc_gpencil_wave_frag_glsl[];
 extern char datatoc_gpencil_pixel_frag_glsl[];
+extern char datatoc_gpencil_swirl_frag_glsl[];
 
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
@@ -149,6 +150,7 @@ static void GPENCIL_engine_free(void)
        DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_blur_sh);
        DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_wave_sh);
        DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_pixel_sh);
+       DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_swirl_sh);
 
        DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
 }
@@ -201,6 +203,9 @@ static void GPENCIL_cache_init(void *vedata)
        if (!e_data.gpencil_vfx_pixel_sh) {
                e_data.gpencil_vfx_pixel_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_pixel_frag_glsl, NULL);
        }
+       if (!e_data.gpencil_vfx_swirl_sh) {
+               e_data.gpencil_vfx_swirl_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_swirl_frag_glsl, NULL);
+       }
 
        {
                /* Stroke pass */
@@ -277,6 +282,8 @@ static void GPENCIL_cache_init(void *vedata)
                psl->vfx_blur_pass_4 = DRW_pass_create("GPencil VFX Blur Pass 
4", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS);
 
                psl->vfx_pixel_pass = DRW_pass_create("GPencil VFX Pixel Pass", 
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS);
+
+               psl->vfx_swirl_pass = DRW_pass_create("GPencil VFX Swirl Pass", 
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS);
        }
 }
 
@@ -446,6 +453,19 @@ static void GPENCIL_draw_scene(void *vedata)
                                        DRW_framebuffer_clear(true, true, 
false, clearcol, 1.0f);
                                        DRW_draw_pass(psl->vfx_copy_pass);
                                }
+                               /* swirl pass */
+                               if ((cache->init_vfx_swirl_sh) && 
(cache->end_vfx_swirl_sh)) {
+                                       
DRW_framebuffer_bind(fbl->vfx_color_fb_b);
+                                       DRW_framebuffer_clear(true, true, 
false, clearcol, 1.0f);
+                                       /* pixel pass */
+                                       
DRW_draw_pass_subset(psl->vfx_swirl_pass,
+                                               cache->init_vfx_swirl_sh,
+                                               cache->end_vfx_swirl_sh);
+                                       /* copy pass from b to a */
+                                       
DRW_framebuffer_bind(fbl->vfx_color_fb_a);
+                                       DRW_framebuffer_clear(true, true, 
false, clearcol, 1.0f);
+                                       DRW_draw_pass(psl->vfx_copy_pass);
+                               }
                                /* Combine with scene buffer */
                                DRW_framebuffer_bind(dfbl->default_fb);
                                /* Mix VFX Pass */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 7c653bb72e0..9c8fac7e26f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -44,6 +44,13 @@ struct GPENCIL_StorageList;
 #define GPENCIL_COLOR_PATTERN 2
 
  /* *********** OBJECTS CACHE *********** */
+typedef struct GPencilVFXSwirl {
+       float center[2];
+       float radius; 
+       float angle;
+       int transparent;
+} GPencilVFXSwirl;
+
 typedef struct GPencilVFXPixel {
        float size[2];
        float rgba[4];
@@ -81,6 +88,9 @@ typedef struct tGPencilObjectCache {
 
        DRWShadingGroup *init_vfx_pixel_sh;
        DRWShadingGroup *end_vfx_pixel_sh;
+
+       DRWShadingGroup *init_vfx_swirl_sh;
+       DRWShadingGroup *end_vfx_swirl_sh;
        float zdepth;
 } tGPencilObjectCache;
 
@@ -89,6 +99,7 @@ typedef struct GPENCIL_vfx {
        GPencilVFXBlur vfx_blur;
        GPencilVFXWave vfx_wave;
        GPencilVFXPixel vfx_pixel;
+       GPencilVFXSwirl vfx_swirl;
 } GPENCIL_vfx;
 
 typedef struct GPENCIL_shgroup {
@@ -136,6 +147,7 @@ typedef struct GPENCIL_PassList {
        struct DRWPass *vfx_blur_pass_3;
        struct DRWPass *vfx_blur_pass_4;
        struct DRWPass *vfx_pixel_pass;
+       struct DRWPass *vfx_swirl_pass;
 } GPENCIL_PassList;
 
 typedef struct GPENCIL_FramebufferList {
@@ -184,6 +196,7 @@ typedef struct GPENCIL_e_data {
        struct GPUShader *gpencil_vfx_blur_sh;
        struct GPUShader *gpencil_vfx_wave_sh;
        struct GPUShader *gpencil_vfx_pixel_sh;
+       struct GPUShader *gpencil_vfx_swirl_sh;
        /* temp depth texture */
        struct GPUTexture *temp_fbcolor_depth_tx;
        struct GPUTexture *temp_fbcolor_color_tx;
diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c 
b/source/blender/draw/engines/gpencil/gpencil_vfx.c
index e8dc8cc7870..b2a85d6212e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_vfx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -267,6 +267,43 @@ static void DRW_gpencil_vfx_pixel(ModifierData *md, int 
ob_idx, GPENCIL_e_data *
        cache->end_vfx_pixel_sh = vfx_shgrp;
 }
 
+/* Swirl VFX */
+static void DRW_gpencil_vfx_swirl(ModifierData *md, int ob_idx, GPENCIL_e_data 
*e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cache)
+{
+       if (md == NULL) {
+               return;
+       }
+
+       GpencilSwirlModifierData *mmd = (GpencilSwirlModifierData *)md;
+
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+       GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+       DRWShadingGroup *vfx_shgrp;
+       stl->vfx[ob_idx].vfx_swirl.center[0] = mmd->center[0];
+       stl->vfx[ob_idx].vfx_swirl.center[1] = mmd->center[1];
+       stl->vfx[ob_idx].vfx_swirl.radius = mmd->radius;
+       stl->vfx[ob_idx].vfx_swirl.angle = mmd->angle;
+       stl->vfx[ob_idx].vfx_swirl.transparent = (int)mmd->flag & 
GP_SWIRL_MAKE_TRANSPARENT;
+
+       struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
+       vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_swirl_sh, 
psl->vfx_swirl_pass);
+       DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
+       DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", 
&e_data->vfx_fbcolor_color_tx_a);
+       DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", 
&e_data->vfx_fbcolor_depth_tx_a);
+       DRW_shgroup_uniform_vec2(vfx_shgrp, "center", 
&stl->vfx[ob_idx].vfx_swirl.center[0], 1);
+       DRW_shgroup_uniform_float(vfx_shgrp, "radius", 
&stl->vfx[ob_idx].vfx_swirl.radius, 1);
+       DRW_shgroup_uniform_float(vfx_shgrp, "angle", 
&stl->vfx[ob_idx].vfx_swirl.angle, 1);
+       DRW_shgroup_uniform_int(vfx_shgrp, "transparent", 
&stl->vfx[ob_idx].vfx_swirl.transparent, 1);
+
+       /* set first effect sh */
+       if (cache->init_vfx_swirl_sh == NULL) {
+               cache->init_vfx_swirl_sh = vfx_shgrp;
+       }
+
+       /* set last effect sh */
+       cache->end_vfx_swirl_sh = vfx_shgrp;
+}
+
 void DRW_gpencil_vfx_modifiers(int ob_idx, struct GPENCIL_e_data *e_data, 
struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache 
*cache)
 {
        bool ready = false;
@@ -300,6 +337,15 @@ void DRW_gpencil_vfx_modifiers(int ob_idx, struct 
GPENCIL_e_data *e_data, struct
                                        DRW_gpencil_vfx_pixel(md, ob_idx, 
e_data, vedata, ob, cache);
                                }
                                break;
+                       case eModifierType_GpencilSwirl:
+                               if (modifier_is_active(ob, md)) {
+                                       if (!ready) {
+                                               DRW_gpencil_vfx_copy(ob_idx, 
e_data, vedata, ob, cache);
+                                               ready = true;
+                                       }
+                                       DRW_gpencil_vfx_swirl(md, ob_idx, 
e_data, vedata, ob, cache);
+                               }
+                               break;
                }
        }
 
diff --git 
a/source/blender/draw/engines/gpencil/shaders/gpencil_swirl_frag.glsl 
b/source/blender/draw/engines/gpencil/shaders/gpencil_swirl_frag.glsl
new file mode 100644
index 00000000000..efde63aa976
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_swirl_frag.glsl
@@ -0,0 +1,41 @@
+out vec4 FragColor;
+
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+
+uniform vec2 center;
+uniform float radius;
+uniform float angle;
+uniform int transparent;
+
+/* This swirl shader is a modified version of original Geeks3d.com code */
+void main()
+{
+       vec2 uv = vec2(gl_FragCoord.xy);
+       float stroke_depth;
+       vec4 outcolor;
+       
+       vec2 tc = uv - center;
+       float dist = length(tc);
+    if (dist <= radius) {
+               float percent = (radius - dist) / radius;
+               float theta = percent * percent * angle * 8.0;
+               float s = sin(theta);
+               float c = cos(theta);
+               tc = vec2(dot(tc, vec2(c, -s)), dot(tc, vec2(s, c)));
+               tc += center;
+
+               stroke_depth = texelFetch(strokeDepth, ivec2(tc), 0).r

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to