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?
Drawing a texture with a soft brush
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Drawing a texture with a soft brush
macOS 10.14 Mojave | LÖVE 11.2
Re: Drawing a texture with a soft brush
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.
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.
Re: Drawing a texture with a soft brush
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:
EDIT: My idea is to use an image mask, but no idea how to realize it:
macOS 10.14 Mojave | LÖVE 11.2
Re: Drawing a texture with a soft brush
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Drawing a texture with a soft brush
That's fantastic and so simple. Thank you so much
macOS 10.14 Mojave | LÖVE 11.2
Re: Drawing a texture with a soft brush
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!
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
Who is online
Users browsing this forum: No registered users and 76 guests