Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Memblock Image Blend .... use an alpha map to blend any two images

Author
Message
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Sep 2007 17:12 Edited at: 13th Sep 2007 17:26
This function will take two images of any size (equal or not) and blend them together according to the values of a third greyscale alpha map image.

It has been written as a function so that is can easily be included in any project.

IMPORTANT: In order to use the code as it is, you will need to download and install IanM's Matrix1 Utils plug-in.
You can still run the code with out the plugin but you will need to change the FIND FREE MEMBLOCK() & FIND FREE BITMAP() commands.






The first two images have been blended using the thrid image to produce the final image below. Note the differing sizes, none of the first three images need to be the same size or even the size of the final image.








Xenocythe
18
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 11th Sep 2007 03:55


This is absolutely genius!

Great work scraggle!

Meh. Signatures. Lame :p
Image All
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: Home
Posted: 12th Sep 2007 00:45
Neat.

Maybe I will try to make one myself But that would imply that I am not half as lazy as I actually am.

Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 13th Sep 2007 00:39
hmm, this might work with a heightmap for terrains. so you can make the terrain texture depending on your terrain height...

Kelebrindae
20
Years of Service
User Offline
Joined: 15th Sep 2003
Location: Where cheeses are scarier than dragons.
Posted: 13th Sep 2007 11:14
Great work, Scraggle, as always !

However, there's something strange at the end of the "blend_Images":
Quote: "
write memblock dword mResult, Pos + 0, ResultBlue
write memblock dword mResult, Pos + 1, ResultGreen
write memblock dword mResult, Pos + 2, ResultRed
write memblock dword mResult, Pos + 3, 255
"

You use "write memblock dword" to write Byte variables, with only a +1 byte offset, so that each new dword overwrite the end of the previous value. Shouldn't you use "write memblock byte" instead ?

(Yeah, I know, it works perfectly well that way; I'm just being a fastidious bore... )

Ideas: memories of things which did not occur yet...
http://keleb.free.fr/codecorner
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Sep 2007 17:30
Quote: "this might work with a heightmap for terrains"


Funny you should say that, that was the reason for writing this, to include in Magrathea.

@Kelebrindae
I really don't know why I put Dword in there, it should, of course be byte. I have now change it ... thanks (although like you said, it still works)



Green7
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 13th Sep 2007 21:37
LOL: Magrathea! I once made Tent-Camp week with the local boy-scouts as leader with 'The Hitch-hikers Guide To The Galaxy' as topic.

with this technique you can not make a extreme steep slope as rock, as it would only recognize the height as such, but not an extreme difference on a short distance. and if you do a very steep slope the texture will be stretched there. but for not so steep stuff it will work perfectly, good idea.

Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 25th Oct 2007 19:54 Edited at: 25th Oct 2007 20:18
I use a similar method of blending for texture layering. But no alpha map needed.

It will even do what you're doing but instead it uses the images transparency data. Which means you can make a transparent PNG in photoshop and not have to make a separate image for the alpha. Even semi-transparency.





If your RPG or MMO has lots of skin tones and you don't want to make a texture for every clothing x skin tone...

You can cut down the number of texture files you need exponentially by simply blending them in-game.

http://www.thegamecreators.com/?m=codebase_view&i=5bf5d37d24d5605df99ab4739e77b4ca

Login to post a reply

Server time is: 2024-05-11 06:35:12
Your offset time is: 2024-05-11 06:35:12