GPencil: Implement antialiasing parameter to Pixel FX

Related to T78153

Differential Revision: https://developer.blender.org/D8100
This commit is contained in:
Antonio Vazquez 2020-06-23 19:11:52 +02:00
parent f3a8192ef7
commit 11a390e85e
Notes: blender-bot 2023-02-14 03:59:42 +01:00
Referenced by issue #78153, GPencil: Anti-aliasing is not disabled for the "pixel" effect
4 changed files with 15 additions and 7 deletions

View File

@ -262,6 +262,8 @@ static void gpencil_vfx_pixelize(PixelShaderFxData *fx, Object *ob, gpIterVfxDat
mul_v3_m4v3(ob_center, persmat, ob->obmat[3]);
mul_v3_fl(ob_center, 1.0f / w);
const bool use_antialiasing = ((fx->flag & FX_PIXEL_FILTER_NEAREST) == 0);
/* Convert to uvs. */
mul_v2_fl(ob_center, 0.5f);
add_v2_fl(ob_center, 0.5f);
@ -285,7 +287,8 @@ static void gpencil_vfx_pixelize(PixelShaderFxData *fx, Object *ob, gpIterVfxDat
DRW_shgroup_uniform_vec2_copy(grp, "targetPixelSize", pixsize_uniform);
DRW_shgroup_uniform_vec2_copy(grp, "targetPixelOffset", ob_center);
DRW_shgroup_uniform_vec2_copy(grp, "accumOffset", (float[2]){pixel_size[0], 0.0f});
DRW_shgroup_uniform_int_copy(grp, "sampCount", (pixel_size[0] / vp_size_inv[0] > 3.0) ? 2 : 1);
int samp_count = (pixel_size[0] / vp_size_inv[0] > 3.0) ? 2 : 1;
DRW_shgroup_uniform_int_copy(grp, "sampCount", use_antialiasing ? samp_count : 0);
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
}
@ -294,7 +297,8 @@ static void gpencil_vfx_pixelize(PixelShaderFxData *fx, Object *ob, gpIterVfxDat
grp = gpencil_vfx_pass_create("Fx Pixelize Y", state, iter, sh);
DRW_shgroup_uniform_vec2_copy(grp, "targetPixelSize", pixsize_uniform);
DRW_shgroup_uniform_vec2_copy(grp, "accumOffset", (float[2]){0.0f, pixel_size[1]});
DRW_shgroup_uniform_int_copy(grp, "sampCount", (pixel_size[1] / vp_size_inv[1] > 3.0) ? 2 : 1);
int samp_count = (pixel_size[1] / vp_size_inv[1] > 3.0) ? 2 : 1;
DRW_shgroup_uniform_int_copy(grp, "sampCount", use_antialiasing ? samp_count : 0);
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
}
}

View File

@ -172,6 +172,10 @@ typedef struct PixelShaderFxData {
ShaderFxData_Runtime runtime;
} PixelShaderFxData;
typedef enum ePixelShaderFx_Flag {
FX_PIXEL_FILTER_NEAREST = (1 << 0),
} ePixelShaderFx_Flag;
typedef struct RimShaderFxData {
ShaderFxData shaderfx;
int offset[2];

View File

@ -336,11 +336,9 @@ static void rna_def_shader_fx_pixel(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Size", "Pixel size");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_ShaderFx_update");
prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_range(prop, 0.0, 1.0);
RNA_def_property_float_sdna(prop, NULL, "rgba");
RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Color", "Color used for lines");
prop = RNA_def_property(srna, "use_antialiasing", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", FX_PIXEL_FILTER_NEAREST);
RNA_def_property_ui_text(prop, "Antialiasing", "Antialiase pixels");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_ShaderFx_update");
}

View File

@ -68,6 +68,8 @@ static void panel_draw(const bContext *C, Panel *panel)
uiItemFullR(col, &ptr, prop, 0, 0, 0, IFACE_("Size X"), ICON_NONE);
uiItemFullR(col, &ptr, prop, 1, 0, 0, IFACE_("Y"), ICON_NONE);
uiItemR(layout, &ptr, "use_antialiasing", 0, NULL, ICON_NONE);
shaderfx_panel_end(layout, &ptr);
}