2
$\begingroup$

I would like to add halftone to fill in stroke areas without using texture.

I know it can be done for shading material, can it be done in grease pencil fill in tool?

$\endgroup$
1
$\begingroup$

Unfortunately it is not possible to use procedural textures in Grease Pencil fills. I read that is is planned but definitely not a priority right now.

When I needed to use hatches for Grease Pencil objects I created a script to automatically populate Textures with different hatch patterns (Squares, Bands, Discs). It could be expanded to add other patterns. Maybe this can help :

"""
Running this script will create arrays of images
Which can then be used as "Textures" in Grease Pencil materials
Each array features varying sizes of shapes
Currently there are Disc, Squares and Stripes.
"""

import bpy


def generate_img_shape(size, name, is_in_shape):
    image = bpy.data.images.get(name)
    if image is None:
        image = bpy.data.images.new(name, width=size[0], height=size[1])
    else:
        image.generated_width = size[0]
        image.generated_height = size[1]
    image.file_format = 'PNG'

    pixels = [None] * (size[0] * size[1])

    for x in range(size[0]):
        for y in range(size[1]):
            pixels[(y * size[0]) + x] = is_in_shape(x, y)

    pixels = [v for v in pixels for _ in range(4)]

    image.pixels = pixels

if __name__ == "__main__":    
    size = 150, 150  
    middle_x = size[0] / 2
    middle_y = size[1] / 2
    
    # Generate patterns with 10%, 20%, 30%, 40% and 49% fill :
    for rad, rad_size in zip((0.1, 0.2, 0.3, 0.4, 0.49), ("10", "20", "30", "40", "50")):
        radius_squared = (rad * min(size[0], size[1])) ** 2
        # Disc patterns :
        generate_img_shape(size, "GP_HATCH_DISC_" + rad_size + ".png", lambda x, y: int(((x - middle_x) ** 2 + (y - middle_y) ** 2) < radius_squared))
        
        # Square patterns :
        generate_img_shape(
            size, 
            "GP_HATCH_SQUARE_" + rad_size + ".png", 
            lambda x, y: 
                int(
                    (x - middle_x) ** 2 < radius_squared and
                    (y - middle_y) ** 2 < radius_squared                
                )
        )
        
        # Band patterns :
        generate_img_shape(
            size,
            "GP_HATCH_BAND_" + rad_size + ".png",
            lambda x, y:
                int(
                    (x - middle_x) ** 2 < radius_squared          
                )
        )

How to run a script in blender.

Note : You may need to run the script twice for the textures to register properly. No idea why but it may be an oversight in my script.

Note 2 : You have to be in Material Preview or Rendered Mode to see the Textures.

enter image description here

Result :

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.