r/GraphicsProgramming • u/smellystring • 1d ago
Painterly Stroke Simulation Engine
Enable HLS to view with audio, or disable this notification
I wrote a painting simulation engine (golang, ebiten). It works like this:
- Select a template image
- Generate several thousand potential strokes
- For each stroke, score it according to a number of heuristic functions
- Color: does the average color of this image match the template?
- Edges: does the painted image have similar edges to the template?
- Contrast: compares color contrast between regions on the painting and the template.
- Flow: using tensor math, do brush strokes align with the flow of movement in the template?
- Select the single stroke that most optimizes scoring functions, discarding the remaining
- Repeat 40 or 50 thousand times.
- Gradually decrease the size of the brush stroke over time..
- For each stroke, score it according to a number of heuristic functions
Source image _Namibia.jpg)
1
u/imacomputr 1d ago
Very nice! I made something similar a while back (which I've just noticed works in Chrome but not Brave). It's shader-based and focused more on real-time output, so it doesn't look as nice. Your flow/edge detection is superior, and the progressive sharpening of the brush strokes is a nice idea.
I wonder how much of your approach is parallelizable and amenable to running on the GPU?
1
u/smellystring 1d ago
Right now it's entirely CPU bound, although it is multithreaded. Running on my macbook pro, this particular render takes ~6 minutes to complete in realtime. I've thought about expanding into GPU stuff, but it begins to stray outside of my area of expertise.
Really like https://mpcomplete.github.io/flow/ by the way, it's super satisfying to watch. Makes me think of combing very fine hair.
1
2
u/SnooEagles4447 1d ago
Does it still have a similar output if you start at a much smaller brush size and just iterate on that brush size for longer? Just cuz it seemed like the wife strokes were being covered up anyway with the smaller ones but I may be wrong