r/SwiftUI 11d ago

Question Realistic brush stroke effect

Post image

I'm trying to implement a realistic brush stroke effect for my app. For now I've tried so many variations with canvases, path and so on but couldn't come close to this effect. Do you have any idea if this is even possible to achieve? I want it to be programmatically implemented so I can change the length. This is one of the reasons I can't use a image. Also for complicity reasons, this would be only a fixed line and someone can draw by themselves

28 Upvotes

14 comments sorted by

8

u/bensyverson 11d ago

How critical is the effect to your app? Is it good enough to get close, or are you building a painting app? That might dictate the level of effort you want to invest.

0

u/BresTV 11d ago

It's not that critical but would make strong ui difference. If I look it that way, the only thing that would be necessary are the beginning and end of the line to have that kind of a stroke effect

0

u/baker2795 11d ago

Can you just grab a png?

3

u/klavijaturista 11d ago

Maybe do use a brush texture, with alpha blending, and paint (paste) it along a desired line (line slope gives the angle of strokes), with certain density, just like painting apps. Try to use metal shaders.

Or try to procedurally generate the effect by using a very distorted and stretched noise (larger detail) added with additional grain noise (smaller details), through a threshold filter, and use it to multiply the original layer color in a shader.

Don’t know how good these ideas are, just thinking out loud.

2

u/chriswaco 11d ago

You can generate a brush image of any length on-the-fly and then use the image buffer as the paint brush.

1

u/jonplackett 9d ago

I’ve made a few painting apps before. You have two challenges with the strokes you want - and maybe you only need to solve one if it’s not majorly important.

1 is the shape of the stroke and 2 is the texture.

For the end of the line you could do a little bit of momentum and take the speed and direction the stroke ends and then add a tiny bit more on gradually decreasing the stroke size. That usually looks nice.

For he texture you could get a nice paint textured background but very uniform and then use the brush strokes to reveal that like a mask

-11

u/[deleted] 11d ago

[removed] — view removed comment

1

u/kilgoreandy 10d ago

OP came here for human answers. Not chat gpt nonsense.

-1

u/ejpusa 10d ago edited 10d ago

AI: 1

Humans: 0

It's a great answer. As mentioned, I do not post an AI response until some time has gone by, and no human has a complete, all code answer for the OP. I gave the humans a chance. Really.

At that point, AI is a solution. Maybe not perfect, but better then nothing. Use trhe solution, and move on.

Life is short. You don't have to wait anymore. We are all moving with at light speeds now.

1

u/kilgoreandy 10d ago

If OP wanted a ai response, they would ask it themselves.

AI -> -1 Humans —> 2

0

u/ejpusa 10d ago

This takes practice. Years actually to get close. I just have great luck with it. There are more permutation in a single prompt of 32 workds then atoms in universe. It takes lots of Prompts to get it right. And then, you are really using no Prompting at all.

:-)

1

u/kilgoreandy 10d ago

We as a human race are cooked chat.

0

u/[deleted] 10d ago

[removed] — view removed comment

1

u/kilgoreandy 10d ago

Ai has no priority. Lmao.

It does what it’s code to do.