[Bf-blender-cvs] [2317f8c14ae] greasepencil-object: New stroke styles: Texture and Pattern
Antonio Vazquez
noreply at git.blender.org
Sat Jul 1 20:37:20 CEST 2017
Commit: 2317f8c14ae5d44f01fb34373edb21e2ac587a18
Author: Antonio Vazquez
Date: Sat Jul 1 16:41:12 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB2317f8c14ae5d44f01fb34373edb21e2ac587a18
New stroke styles: Texture and Pattern
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/blenloader/intern/readfile.c
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/shaders/gpencil_stroke_frag.glsl
M source/blender/makesdna/DNA_brush_types.h
M source/blender/makesrna/intern/rna_palette.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index bdbc8c28aef..571421cdd49 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -1146,6 +1146,8 @@ class GreasePencilPaletteColorPanel:
col.prop(pcolor, "color", text="")
col.prop(pcolor, "alpha", slider=True)
col.prop(pcolor, "stroke_style", text="")
+ if pcolor.stroke_style in ('TEXTURE', 'PATTERN'):
+ col.template_ID(pcolor, "stroke_image", open="image.open")
# Column 2 - Fill
row = layout.row()
@@ -1188,7 +1190,7 @@ class GreasePencilPaletteColorPanel:
if pcolor.fill_style not in ('TEXTURE', 'PATTERN'):
col.prop(pcolor, "texture_mix", text="Mix Texture")
if pcolor.fill_style in ('TEXTURE', 'PATTERN') or pcolor.texture_mix is True:
- col.template_ID(pcolor, "image", open="image.open")
+ col.template_ID(pcolor, "fill_image", open="image.open")
split = col.split(percentage=0.5)
subcol = split.column(align=True)
subcol.prop(pcolor, "texture_shift", text="Location")
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 2896a06c87f..e4943bfdc51 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2293,6 +2293,9 @@ static void lib_link_palette(FileData *fd, Main *main)
lib_link_animdata(fd, &palette->id, palette->adt);
/* relink images */
for (PaletteColor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
+ if (palcolor->sima != NULL) {
+ palcolor->sima = newlibadr(fd, palette->id.lib, palcolor->sima);
+ }
if (palcolor->ima != NULL) {
palcolor->ima = newlibadr(fd, palette->id.lib, palcolor->ima);
}
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 3905e0724b9..d4ad9c189e2 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -288,8 +288,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(DRWPass *pass, GPUS
}
/* create shading group for strokes */
-DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
- bGPdata *gpd, int id)
+DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
+ bGPdata *gpd, PaletteColor *palcolor, int id)
{
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
const float *viewport_size = DRW_viewport_size_get();
@@ -307,12 +307,16 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass
DRW_shgroup_uniform_float(grp, "objscale", &stl->shgroups[id].obj_scale, 1);
stl->shgroups[id].keep_size = (int)((gpd) && (gpd->flag & GP_DATA_STROKE_KEEPTHICKNESS));
DRW_shgroup_uniform_int(grp, "keep_size", &stl->shgroups[id].keep_size, 1);
+
+ stl->shgroups[id].stroke_style = palcolor->stroke_style;
+ DRW_shgroup_uniform_int(grp, "stroke_type", &stl->shgroups[id].stroke_style, 1);
}
else {
stl->storage->obj_scale = 1.0f;
stl->storage->keep_size = 0;
DRW_shgroup_uniform_float(grp, "objscale", &stl->storage->obj_scale, 1);
DRW_shgroup_uniform_int(grp, "keep_size", &stl->storage->keep_size, 1);
+ DRW_shgroup_uniform_int(grp, "stroke_type", &stl->storage->stroke_style, 1);
}
if (gpd) {
@@ -323,6 +327,33 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_Data *vedata, DRWPass
DRW_shgroup_uniform_int(grp, "xraymode", &stl->storage->xray, 1);
}
+ /* image texture for pattern */
+ if ((palcolor) && ((palcolor->stroke_style == STROKE_STYLE_TEXTURE) || (palcolor->stroke_style == STROKE_STYLE_PATTERN))) {
+ ImBuf *ibuf;
+ Image *image = palcolor->sima;
+ ImageUser iuser = { NULL };
+ void *lock;
+
+ iuser.ok = true;
+
+ ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
+
+ if (ibuf == NULL || ibuf->rect == NULL) {
+ BKE_image_release_ibuf(image, ibuf, NULL);
+ }
+ else {
+ GPUTexture *texture = GPU_texture_from_blender(palcolor->sima, &iuser, GL_TEXTURE_2D, true, 0.0, 0);
+ DRW_shgroup_uniform_texture(grp, "myTexture", texture);
+
+ BKE_image_release_ibuf(image, ibuf, NULL);
+ }
+ }
+ else {
+ /* if no texture defined, need a blank texture to avoid errors in draw manager */
+ DRW_shgroup_uniform_texture(grp, "myTexture", e_data->gpencil_blank_texture);
+ }
+
+
return grp;
}
@@ -480,7 +511,7 @@ static void gpencil_draw_strokes(GpencilBatchCache *cache, GPENCIL_e_data *e_dat
if (gps->totpoints > 1) {
int id = stl->storage->shgroup_id;
stl->shgroups[id].shgrps_fill = DRW_gpencil_shgroup_fill_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_fill_sh, ob, gpd, gps->palcolor, id);
- stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd, id);
+ stl->shgroups[id].shgrps_stroke = DRW_gpencil_shgroup_stroke_create(e_data, vedata, psl->stroke_pass, e_data->gpencil_stroke_sh, ob, gpd, gps->palcolor, id);
++stl->storage->shgroup_id;
fillgrp = stl->shgroups[id].shgrps_fill;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 80817da3a02..8a9a7ab89b5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -27,6 +27,7 @@
#include "DRW_render.h"
#include "BKE_global.h"
+#include "BKE_paint.h"
#include "DNA_gpencil_types.h"
#include "DNA_view3d_types.h"
@@ -124,6 +125,7 @@ static void GPENCIL_cache_init(void *vedata)
/* Alloc transient pointers */
stl->g_data = MEM_mallocN(sizeof(g_data), "g_data");
stl->storage->xray = GP_XRAY_FRONT; /* used for drawing */
+ stl->storage->stroke_style = STROKE_STYLE_SOLID; /* used for drawing */
}
if (!stl->shgroups) {
/* Alloc maximum size because count strokes is very slow and can be very complex due onion skinning.
@@ -155,8 +157,15 @@ static void GPENCIL_cache_init(void *vedata)
stl->g_data->shgrps_edit_volumetric = DRW_gpencil_shgroup_edit_volumetric_create(psl->edit_pass, e_data.gpencil_volumetric_sh);
/* drawing buffer pass */
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Palette *palette = BKE_palette_get_active_from_context(draw_ctx->evil_C);
+ PaletteColor *palcolor = BKE_palette_color_get_active(palette);
+ if (palcolor) {
+ stl->storage->stroke_style = palcolor->stroke_style;
+ }
+
psl->drawing_pass = DRW_pass_create("Gpencil Drawing Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
- stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, -1);
+ stl->g_data->shgrps_drawing_stroke = DRW_gpencil_shgroup_stroke_create(&e_data, vedata, psl->drawing_pass, e_data.gpencil_stroke_sh, NULL, NULL, palcolor, -1);
stl->g_data->shgrps_drawing_fill = DRW_gpencil_shgroup_drawing_fill_create(psl->drawing_pass, e_data.gpencil_drawing_fill_sh);
/* we need a full screen pass to combine the result of zdepth */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 2fec8d9e87c..e6b773a7c7b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -45,6 +45,8 @@ typedef struct tGPencilObjectCache {
/* *********** LISTS *********** */
typedef struct GPENCIL_shgroup {
+ int s_clamp;
+ int stroke_style;
int t_mix;
int t_flip;
int t_clamp;
@@ -58,6 +60,7 @@ typedef struct GPENCIL_shgroup {
typedef struct GPENCIL_Storage {
int shgroup_id; /* total elements */
float unit_matrix[4][4];
+ int stroke_style;
int xray;
int keep_size;
float obj_scale;
@@ -144,7 +147,8 @@ typedef struct GpencilBatchCache {
int cache_idx; /* current slot index */
} GpencilBatchCache;
-struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, struct Object *ob, struct bGPdata *gpd, int id);
+struct DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct DRWPass *pass, struct GPUShader *shader, struct Object *ob,
+ struct bGPdata *gpd, struct PaletteColor *palcolor, int id);
struct DRWShadingGroup *DRW_gpencil_shgroup_point_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
struct DRWShadingGroup *DRW_gpencil_shgroup_edit_volumetric_create(struct DRWPass *pass, struct GPUShader *shader);
struct DRWShadingGroup *DRW_gpencil_shgroup_drawing_fill_create(struct DRWPass *pass, struct GPUShader *shader);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
index d94cec13474..c022a2e6239 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_stroke_frag.glsl
@@ -1,8 +1,32 @@
+uniform int stroke_type;
+uniform sampler2D myTexture;
+
in vec4 mColor;
in vec2 mTexCoord;
out vec4 fragColor;
+#define texture2D texture
+
+/* keep this list synchronized with list in DNA_brush_types.h */
+#define SOLID 0
+#define TEXTURE 2
+#define PATTERN 3
+
void main()
{
- fragColor = mColor;
+ /* Solid */
+ if (stroke_type == SOLID) {
+ fragColor = mColor;
+ }
+ /* texture */
+ if (stroke_type == TEXTURE) {
+ fragColor = texture2D(myTexture, mTexCoord);
+ }
+ /* pattern */
+ if (stroke_type == PATTERN) {
+ vec4 text_color = texture2D(myTexture, mTexCoord);
+ /* normalize texture color */
+ float nvalue = 1.0 - ((text_color.x + text_color.y + text_color.z) / 3.0);
+ fragColor = mix(vec4(0.0, 0.0, 0.0, 0.0), mColor, nvalue);
+ }
}
diff --git a/source/blend
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list