[Bf-blender-cvs] [1da03b2e806] greasepencil-refactor: GPencil: Refactor: Make Texture UV transform behave like normal 3D ones

Clément Foucault noreply at git.blender.org
Sat Jan 11 20:28:15 CET 2020


Commit: 1da03b2e806081ed500f22e4ba8b3e7a8dac0907
Author: Clément Foucault
Date:   Sat Jan 11 20:27:31 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB1da03b2e806081ed500f22e4ba8b3e7a8dac0907

GPencil: Refactor: Make Texture UV transform behave like normal 3D ones

Meaning we apply location then rotation then scale. This makes positioning
using the parameters easier.

Also since the gradients now use the same UV space, we can reuse the same
properties for the transform.

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

M	release/scripts/startup/bl_ui/properties_material_gpencil.py
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c

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

diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index 279fb82ec5c..8fdc4b8aeb4 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -190,41 +190,32 @@ class MATERIAL_PT_gpencil_fillcolor(GPMaterialButtonsPanel, Panel):
         col.enabled = not gpcolor.lock
         col.prop(gpcolor, "fill_style", text="Style")
 
-        if gpcolor.fill_style == 'GRADIENT':
-            col.prop(gpcolor, "gradient_type")
 
-        if gpcolor.fill_style != 'TEXTURE':
+        if gpcolor.fill_style == 'SOLID':
             col.prop(gpcolor, "fill_color", text="Base Color")
 
-            if gpcolor.fill_style == 'GRADIENT':
-                col.prop(gpcolor, "mix_color", text="Secondary Color")
-
-            if gpcolor.fill_style == 'GRADIENT':
-                col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
-
-            if gpcolor.fill_style == 'GRADIENT':
-                col.prop(gpcolor, "flip", text="Flip Colors")
+        elif gpcolor.fill_style == 'GRADIENT':
+            col.prop(gpcolor, "gradient_type")
 
-                col.prop(gpcolor, "pattern_shift", text="Location")
-                col.prop(gpcolor, "pattern_scale", text="Scale")
+            col.prop(gpcolor, "fill_color", text="Base Color")
+            col.prop(gpcolor, "mix_color", text="Secondary Color")
+            col.prop(gpcolor, "mix_factor", text="Mix Factor", slider=True)
+            col.prop(gpcolor, "flip", text="Flip Colors")
 
-            if gpcolor.gradient_type == 'RADIAL' and gpcolor.fill_style == 'SOLID':
-                col.prop(gpcolor, "pattern_radius", text="Radius")
-            else:
-                if gpcolor.fill_style != 'SOLID':
-                    col.prop(gpcolor, "pattern_angle", text="Angle")
+            col.prop(gpcolor, "texture_offset", text="Location")
+            col.prop(gpcolor, "texture_angle", text="Rotation")
+            col.prop(gpcolor, "texture_scale", text="Scale")
 
-        # Texture
-        if gpcolor.fill_style == 'TEXTURE':
+        elif gpcolor.fill_style == 'TEXTURE':
             col.template_ID(gpcolor, "fill_image", open="image.open")
 
             col.prop(gpcolor, "fill_color", text="Base Color")
+            col.prop(gpcolor, "texture_opacity", slider=True)
             col.prop(gpcolor, "mix_factor", text="Factor", slider=True)
 
-            col.prop(gpcolor, "texture_offset", text="Offset")
+            col.prop(gpcolor, "texture_offset", text="Location")
+            col.prop(gpcolor, "texture_angle", text="Rotation")
             col.prop(gpcolor, "texture_scale", text="Scale")
-            col.prop(gpcolor, "texture_angle")
-            col.prop(gpcolor, "texture_opacity")
             col.prop(gpcolor, "texture_clamp", text="Clip Image")
 
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_data.c b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
index 8c88c3e64a8..11dedd1d038 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_data.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_data.c
@@ -79,6 +79,7 @@ static struct GPUTexture *gpencil_image_texture_get(Image *image, bool *r_alpha_
   return gpu_tex;
 }
 
+#if 0 /* Old implementation. Reference for doing versioning code. TODO remove. */
 static void gpencil_uv_transform_get(const float ofs[2],
                                      const float scale[2],
                                      const float rotation,
@@ -100,6 +101,27 @@ static void gpencil_uv_transform_get(const float ofs[2],
   copy_v2_v2(r_uvmat[1], mat[1]);
   copy_v2_v2(r_uvmat[2], mat[3]);
 }
+#endif
+
+static void gpencil_uv_transform_get(const float ofs[2],
+                                     const float scale[2],
+                                     const float rotation,
+                                     float r_uvmat[3][2])
+{
+  /* OPTI this could use 3x2 matrices and reduce the number of operations drastically. */
+  float mat[4][4];
+  unit_m4(mat);
+  /* Offset to center. */
+  translate_m4(mat, 0.5f, 0.5f, 0.0f);
+  /* Reversed order. */
+  rescale_m4(mat, (float[3]){1.0f / scale[0], 1.0f / scale[1], 0.0});
+  rotate_m4(mat, 'Z', -rotation);
+  translate_m4(mat, ofs[0], ofs[1], 0.0f);
+  /* Convert to 3x2 */
+  copy_v2_v2(r_uvmat[0], mat[0]);
+  copy_v2_v2(r_uvmat[1], mat[1]);
+  copy_v2_v2(r_uvmat[2], mat[3]);
+}
 
 #define HSV_SATURATION 0.5
 #define HSV_VALUE 0.8
@@ -293,9 +315,9 @@ GPENCIL_MaterialPool *gpencil_material_pool_create(GPENCIL_PrivateData *pd, Obje
       pool->tex_fill[mat_id] = NULL;
       mat_data->flag |= GP_FILL_GRADIENT_USE;
       mat_data->flag |= use_radial ? GP_FILL_GRADIENT_RADIAL : 0;
-      gpencil_uv_transform_get(gp_style->gradient_shift,
-                               gp_style->gradient_scale,
-                               gp_style->gradient_angle,
+      gpencil_uv_transform_get(gp_style->texture_offset,
+                               gp_style->texture_scale,
+                               gp_style->texture_angle,
                                mat_data->fill_uv_transform);
       copy_v4_v4(mat_data->fill_color, gp_style->fill_rgba);
       copy_v4_v4(mat_data->fill_mix_color, gp_style->mix_rgba);



More information about the Bf-blender-cvs mailing list