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.

Newcomers DBPro Corner / Addative effect? ("adding" one sprite ontop of another)

Author
Message
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 22nd Aug 2003 19:33
Im not sure how hard or simple this is, I would just like to know how to apply one sprite ontop of another, where the resulting image is the RGB values added together.

Imagine PSP or Photoshop layers, with the mode set to addative.

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 22nd Aug 2003 20:11 Edited at: 22nd Aug 2003 20:14
you can`t do that by sprite directly I think, unless you wrote a dll or a add on command, but you can load the images that make up the sprites into memblocks, then add the values together for corresponding pixel rgb`s and then divide the answer by two to keep it in range (so 255+255=510, thats more than the colour location could hold, so 510/2=255, that trims the range back to fit the memory location...another example 64+128=192...192/2=96) that gives you the mixed colour when you do it to r,g and b values, then store the result in another memblock and then when you finish convert it back to an image and use that for the sprite, this works because unlike paint light is additive colour mixing, or a slower way, put the images into bitmaps and then retrieve the r, g, and b values for each pixel, then add and divide by two and put the result into another bitmap with plot and then make that bitmap the new sprite, cheers.

Mentor.
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 23rd Aug 2003 00:41
Phwee...well, thanks...im supprised its that hard to be honest, but ill give it a go.
I mean, surely some of the 3D shading modes effectively do this, seems odd it cant be done like that in 2D.

I dont know how to use memmory blocks or anything yet...but I guese ill have too. I think bitmaps will be too slow.
(I really wanted this for an animation effect, I see GBA games do this effect all the time to great effect)

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 23rd Aug 2003 14:12 Edited at: 23rd Aug 2003 14:24
well you could do this in 3D with plains, use the effect you want and then grab the section of bitmap 0 (the screen) with the effect in it, but I assumed you where doing this more or less realtime with a 2d game (hence the sprites), initialising 3d to do it would mess up your scene unless you had the backdrop on a plain in front of camera zero and the sprites over that, then mapped the sprite images to plains behind your background plain and pointed another camera at them to get the result of say passing a ghosted plain in front of another, then copy that camera image to a bitmap and then use the bitmap to texture the new sprite, BUT that would involve rewriting the whole game (or at least a large chunk of it), and I didn`t think you would thank me for that suggestion , I havent seen any GBA? games, so I don`t know what you are on about, but many of the old 8 bit games just locked sprites onto one another, like you would have the extra gun turrets in a shoot em up and they would put that sprite with the turrets over the top of the players ship and just show them in the same place, like you get those soldier toys that have the snap on accesories, sprites already have tranparency as normal and you can use diffuse and alpha to make effects that should be pretty much like you have in 3D (since sprites are 3D they should be able to show the same effects), I ain`t sure what you are trying to do, my first thought was you where making an texture editor or an art package or something, you don`t need to mix and recreat the sprites just for a game, just give them the effect you want (eg make a transparent alpha bubble and place it the same position as the ship to give a forcefield effect), if you give a simple example of the effect on a PC game I may know what you mean, but I never owned a console or whatever it is you are on about, so I am not sure what the effect is, sorry.

Mentor.
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 23rd Aug 2003 14:25 Edited at: 23rd Aug 2003 14:25
I think this can do done with sprites - a mixture of the SET SPRITE ALPHA command and maybe SET SPRITE DIFFUSE.

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 23rd Aug 2003 16:17 Edited at: 23rd Aug 2003 16:23
Not really, that mixs the colour it dosnt "add" it.

Do you have PSP?

Try makeing two images the same size, fill them with some paturn or something.

Then go "Image>Arithmatic>Add (all chanels)"

Thats the effect I want.
Any 3DS Max users will also know the effect as "Addative" when setting transparency modes.

Its very usefull for many things, anything from explosions to sorces of light. (say, shining thought a window)

I cant think of a PC example off hand, but if you emulate Golden Sun 2 on a GBA emulator, you will see it used lots of times.
(good game too).
Its often used for Magic effects in pc games like Neverwinter Nights.


In my case, however, Im just using it for a pretty title screen effect :p


Heres my attempted at the techique mentioned earlier by Mentor.
Any idea what im doing wrong?

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 23rd Aug 2003 19:23 Edited at: 23rd Aug 2003 19:24
the code below gives you an image made from 2 (added together) the first is just a grass texture and the other is a circular gradient on a black background, the result is dark grass with a highlight in the middle since it adds the two images together, is that what you wanted?, I just modified the code to use a couple of loaded images since its easier to see whats happening in an image like that, this is what I meant anyway, just get two 640x480 images and try this and you will see what I meant, if this isn`t what you wanted then I don`t know (I don`t have photoshop..MGI Photosuite or Painter classic are my apps), sorry.

Mentor.
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 24th Aug 2003 14:39 Edited at: 24th Aug 2003 14:40
No...I just get a "Memory Block out of range error" when I try to run your code.

Are you sure that should be "640*480*4" ?
It works when I reduce it to *2, but then I get horrible currupted image ((

(the exact same result I get on my code)
--
Incidently, I have just realised this formular dosnt produce the effect I want.
(a+b)/2

Can actualy produce a darker image if "b" is lower then "a"
The effect in Paint Shop Pro (www.jasc.com, I dont use photoshop...overpriced), is quite different...it can only make the image lighter.
Obviously, if using this for explosions or fake lighting, Id only want the image to be lighter :p


I guese the formular is more like:
r=(255-a)
(a+(r/255)*b)

or something.
(ie, it adds the B image, scaleing it to fit in the "gap" between the a value and the max of 255).
---
Regardless, Id be happy if I just got any result at the moment..then I can play with the formular later

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Aug 2003 15:48
Here's the formula I use the blend 2 rgb values together:



There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 24th Aug 2003 15:52
Demo snippet

There's no place like 127.0.0.1

There are 10 people in this world, those who understand binary and those who don't.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 24th Aug 2003 16:12 Edited at: 24th Aug 2003 16:14
you must have a 16 bit image then, that would also explain the trashed colour on the screen since you just need 5 bits per colour (I think...bit 16 is for alpha IIRC), my snippet was coded for 32 bit (8 bits each for r,g,b and 8 bits for alpha), on my system that just gets half way down the screen when it is set to 2, it does the whole image at 4 with no error, check what your maximum colour depth settings are for your card, I think some cheaper, older cards can only manage 16 bit, if your desktop is in high colour(16bit) then try to change it to true colour(32bit), then in your code make sure you load 32bit images and set the screen mode with "set display mode 640,480,32" and it should work as I intended, to brighten the image you could just use the brighter of the two values, but remember if you are in 16 bit then you just need 5 bits per colour, you need to logicaly and the value with 00011111 for the first byte, and so on, much more complicated in 16bit, so check if you can use 32, most cards will perform better in 32 anyway since they too will have problems using fractions of bytes for the colours, cheers.

Mentor.
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 25th Aug 2003 16:36
Thanks a lot, yes that was the problem
Changing the mode to 32 exclusive worked
(I normaly use that for my desktop, but my DBp was set to 16)
---
ok, there is still some miss-understanding of the difference between simply blending and "adding".
Picking the lighter colour still dosnt give you the correct effect (because lighter colours should still get even more light if the "b" image is anything except black)

But now, thats to Mentors excelent help I have done it
(as least, I think so)

The difference between Adding and Blending is subtle in some images, but strong in others.
The main point is that no pixal in the resulting image will be darker then the source images. And, unlike using an "if a>b then", the resulting image is seamless.

This can be used for lighting effects, and works more effectively then blend.
I hope to have a proper demo of the effect to show off why its better then just blending white or something.

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 28th Aug 2003 20:15 Edited at: 28th Aug 2003 20:20
ok, an example of the effect is here, including DBp code:

www.darkflame.co.uk/Addative Test.ace

Its very slow and jerky, but hopefull you can see the advantages of the effect. (ie, you can just use a greyscale overlay to light up 2D sprites correctly, without the dark bits of the overlay darking your picture)

Now, any advice how to speed it up?

please?

Its too dam slow :p
I refuse to have my 1.4ghz PC beaten by my Gameboy due to my poor codeing

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 29th Aug 2003 14:00
gah! Ace file alert, I know Ace users love em, but I don`t have Ace, I don`t like to use anything that gives stability problems and that does on my setup, the only way to speed up the effect would be to make a C++ dll and use that to run the effect, or use the inline JIT assembler add on that was in the snippets board and encode the operations to run on that, for such a short bit it should be relativley easy, but if it was me then I would just fake the effect, (whatever it is), sigh!, I suppose I will have to download Ace and take a look at this effect, back in a while.

Mentor.
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 29th Aug 2003 14:54
do your 2D game in top down 3D, just use ghosted light grey triangles for the fans of light and position light scources set to spots at those positions, would be easier and the light effects are far easier in 3D than 2D, I was going to have a play about with your graphics but for some reason MGI decides your jpg images are not image files, so I didn`t bother, busy with the compy anyway, just one Q, you don`t apply the effect to the whole screen every frame I hope?, you could code it to just do the area that changes (the sphere sprite) after you have done the initial bitmap mod, I wouldn`t have thought a 40x40 or whatever sprite would have slowed it down that much, or you could store the sprite as an animation strip, lit from different positions and use a matrix to index the sprite for the different positions, but an editior would be useful for that, you could also try overlaying white fan shaped sprites set to translucent, if you fade them down enough then they would look like light cones over the image, cheers.

Mentor.
Darkflame
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location:
Posted: 29th Aug 2003 17:21
The Ace file I made was the smallest, I tried zip & rar, but they were bigger, I only got 5MB free on my domain :p
==
The whole point of the techique is you dont have to code individualy each room in the game :p
You just make a "lightmap" for each room.

White fans would indeed do a simerlar thing (though without the nice defuse edges). But it would be hell setting them up for each room in a game.

Your idea of just updateing just the sprite, however, is excelent.
Thanks

Now I just gota figure out how...


Yes, it may seem like im going though a lot of work for this effect, but its pretty standared in games and graphic work.
And, as I said, I refuse to be forced to "fake" an image a gameboy can pull of easily.
I did wonder why I never saw DB games use it, I see why now :p

"The man who says it cannot be done is generally interrupted by someone doing it." ~ Elbert Hubbard
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 29th Aug 2003 17:46 Edited at: 29th Aug 2003 17:50
it`s strongley inclined to 3D is DB, fancy screen effects could be done it there was a demand for them, you will find the gameboy has a blitter that can handle those effects automaticly, somebody could even do them from a dll for DarkBasic, but not me, I`m busy and not too good at C++ or ASM, your sprite code would be something like

for i=ypos*(640*4) to ypos*(640*4)+sprite_height*(640*4)
for l=i+xpos to (i+xpos)+sprite_width
mix_those_pixels(i,l)
next l
next i

(not tried),you might want to check that since my maths isn`t brilliant nowdays, it`s several decades since I sat my O levels, you might want to replace those 640*4`s with 2560 too, cheers.

Mentor.
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 29th Aug 2003 17:50
it`s several decades since I sat my O levels

It would be several decades if you sat O-Levels

Theres no place like 127.0.0.1
There are 10 people in this world, those who understand binary and those who don't
Bus station = where bus stops. Train station = where train stops. Workstation = ?

Login to post a reply

Server time is: 2024-11-10 17:00:29
Your offset time is: 2024-11-10 17:00:29