Drawing a texture with a soft brush

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Drawing a texture with a soft brush

Post by Ratchet »

I want to make a program for drawing fantasy styled maps. The goal is to draw different regions like wood, sand or rock to the ground
So I need a soft brush like in Photoshop. But I don't want to draw just a color, I want to draw a texture/image.

One of my ideas is to use ImageData and setPixel to do that. Another idea is to use some kind of alpha map. I' not sure what's the best way.

Maybe you can push me to the right direction, please?
macOS 10.14 Mojave | LÖVE 11.2
User avatar
adrix89
Party member
Posts: 135
Joined: Fri Oct 15, 2010 10:58 am

Re: Drawing a texture with a soft brush

Post by adrix89 »

The basic technique is to get a texture and stamp/dibs it multiple times based on a step size.
You need to know some tricks like how flow and opacity is different.
Basically for opacity you draw at full alpha, normalized so that the highest opacity is full alpha, example being if you have a texture with the most opaque part at 180alpha you normalize it so that its 255.
You draw that in a buffer and use that buffer to change its alpha from full 255, that is opacity. This would make it like you paint with water.
Flow is the opposite, you just draw with a set alpha. This will make it stack.
You also have to manage when the brush is too fast so you have to iterate in a line.

Also you basically need canvas support since ImageData has only copy and you need blending. Setting every individual pixels is slow as a snail.

Also when using soft brushes like in Photoshop you basically need algorithmic brushes instead because a textured brush looks like crap and scales like crap and antialiases like crap.

I have a Java project that I abandoned since java is a nightmare for me. You can look around to see how i do things.
Also I remember antialiasing was a big problem.
I use Workflowy but you can check out Dynalist as its the better offer.
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Drawing a texture with a soft brush

Post by Ratchet »

I don't know how to do that. I even don't know how to start. Someone got a clue?

EDIT: My idea is to use an image mask, but no idea how to realize it:
brush.png
brush.png (383.7 KiB) Viewed 3741 times
macOS 10.14 Mojave | LÖVE 11.2
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Drawing a texture with a soft brush

Post by Nixola »

You could draw the brush to a canvas in addive mode, then draw the texture in normal mode, then draw the canvas over the texture in multiplicative mode. Example .love:
Attachments
brush.love
(273.85 KiB) Downloaded 134 times
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Drawing a texture with a soft brush

Post by Ratchet »

That's fantastic and so simple. Thank you so much :)
macOS 10.14 Mojave | LÖVE 11.2
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Drawing a texture with a soft brush

Post by Ratchet »

Got it to work. The trick is to do it in three steps. First canvas only contains the brushed area. The second is for mixing up the brushed mask with the real texture. Finally just draw the mixed stuff to the canvas which contains the final image.

BEWARE OF CRAPPY TEST CODE!
Attachments
terrain-brush.love
Drawing terrain with a soft brush
(358 KiB) Downloaded 124 times
macOS 10.14 Mojave | LÖVE 11.2
Post Reply

Who is online

Users browsing this forum: No registered users and 76 guests