[Bf-blender-cvs] [e6f61a4a379] master: GPencil: New material parameter to rotate texture

Antonio Vazquez noreply at git.blender.org
Fri Oct 30 15:46:33 CET 2020


Commit: e6f61a4a379bbb80296131fae0cef178e2145e52
Author: Antonio Vazquez
Date:   Fri Oct 30 15:41:52 2020 +0100
Branches: master
https://developer.blender.org/rBe6f61a4a379bbb80296131fae0cef178e2145e52

GPencil: New material parameter to rotate texture

Add a parameter to rotate the texture for Dots and Squares

Differential Revision: https://developer.blender.org/D9369

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

M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index ca8999e9588..5da7a3270d9 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -676,6 +676,7 @@ class AddPresetGpencilMaterial(AddPresetBase, Operator):
         "gpcolor.pixel_size",
         "gpcolor.mix_stroke_factor",
         "gpcolor.alignment_mode",
+        "gpcolor.alignment_rotation",
         "gpcolor.fill_style",
         "gpcolor.fill_color",
         "gpcolor.fill_image",
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index da54ff1a137..7c8f6b2309a 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -165,6 +165,7 @@ class MATERIAL_PT_gpencil_strokecolor(GPMaterialButtonsPanel, Panel):
 
             if gpcolor.mode in {'DOTS', 'BOX'}:
                 col.prop(gpcolor, "alignment_mode")
+                col.prop(gpcolor, "alignment_rotation")
 
             if gpcolor.mode == 'LINE':
                 col.prop(gpcolor, "use_overlap_strokes")
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 52b41726276..4361f6f9b51 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -247,6 +247,10 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
 
     gp_style = gpencil_viewport_material_overrides(pd, ob, color_type, gp_style);
 
+    /* Dots or Squares rotation. */
+    mat_data->alignment_rot_cos = cosf(gp_style->alignment_rotation);
+    mat_data->alignment_rot_sin = sinf(gp_style->alignment_rotation);
+
     /* Stroke Style */
     if ((gp_style->stroke_style == GP_MATERIAL_STROKE_STYLE_TEXTURE) && (gp_style->sima)) {
       bool premul;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0922ab6552c..04128dc157e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -62,7 +62,7 @@ typedef struct gpMaterial {
   float stroke_color[4];
   float fill_color[4];
   float fill_mix_color[4];
-  float fill_uv_transform[3][2], _pad0[2];
+  float fill_uv_transform[3][2], alignment_rot_cos, alignment_rot_sin;
   float stroke_texture_mix;
   float stroke_u_scale;
   float fill_texture_mix;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index 5e930af7bd7..94b066c12e5 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -461,6 +461,14 @@ void stroke_vertex()
     float rot_cos = abs(uv_rot);
     x_axis = mat2(rot_cos, -rot_sin, rot_sin, rot_cos) * x_axis;
 
+#  ifdef GP_MATERIAL_BUFFER_LEN
+    if (is_dot) {
+      float alignment_cos = MATERIAL(m).fill_uv_offset.z;
+      float alignment_sin = MATERIAL(m).fill_uv_offset.w;
+      x_axis = mat2(alignment_cos, -alignment_sin, alignment_sin, alignment_cos) * x_axis;
+    }
+#  endif
+
     vec2 y_axis = rotate_90deg(x_axis);
 
     strokeAspect = decode_aspect(aspect1);
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index 355d3d6439b..1d31b876068 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -99,7 +99,8 @@ typedef struct MaterialGPencilStyle {
   float mix_stroke_factor;
   /** Mode used to align Dots and Boxes with stroke drawing path and object rotation */
   int alignment_mode;
-  char _pad[4];
+  /** Rotation for texture for Dots and Squares. */
+  float alignment_rotation;
 } MaterialGPencilStyle;
 
 /* MaterialGPencilStyle->flag */
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 5e16f1187fb..086a182e085 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -24,6 +24,8 @@
 #include "DNA_material_types.h"
 #include "DNA_texture_types.h"
 
+#include "BLI_math.h"
+
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
@@ -594,6 +596,16 @@ static void rna_def_material_greasepencil(BlenderRNA *brna)
       prop, "Alignment", "Defines how align Dots and Boxes with drawing path and object rotation");
   RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");
 
+  /* Rotation of texture for Dots or Strokes. */
+  prop = RNA_def_property(srna, "alignment_rotation", PROP_FLOAT, PROP_ANGLE);
+  RNA_def_property_float_sdna(prop, NULL, "alignment_rotation");
+  RNA_def_property_float_default(prop, 0.0f);
+  RNA_def_property_range(prop, -DEG2RADF(90.0f), DEG2RADF(90.0f));
+  RNA_def_property_ui_range(prop, -DEG2RADF(90.0f), DEG2RADF(90.0f), 10, 3);
+  RNA_def_property_ui_text(
+      prop, "Rotation", "Additional rotation applied to dots and square strokes");
+  RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialGpencil_update");
+
   /* pass index for future compositing and editing tools */
   prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED);
   RNA_def_property_int_sdna(prop, NULL, "index");



More information about the Bf-blender-cvs mailing list