FAST alpha posible?

BlitzPlus Forums/BlitzPlus Programming/FAST alpha posible?

cbmeeks(Posted 2003) [#1]
Does anyone know where I can get some fast alpha routines for small sprites? Everyone I have tried seems to be really slow. Slow like dropping my FPS from 800 to 15!!

Thanks

cb


mag.(Posted 2003) [#2]
Did you aready try to make your sprite a checkers of black (one pixel each) and make the black color as its tranferent. I've seen someone did a very big image no problem.


Kevin_(Posted 2003) [#3]
Thats the method I use and it is really fast. Works best in higher resolutions though.

Regards


cbmeeks(Posted 2003) [#4]
Yeah, I actually knew that trick 15 years ago :-P

lol

But thanks though


Who was John Galt?(Posted 2003) [#5]
Theres a userlib of 2D routines that does that stuff on Blitzcoder showcase. Can't remember the name.......


Anthony Flack(Posted 2003) [#6]

I actually knew that trick 15 years ago


And it's showing its age now too.


cbmeeks(Posted 2003) [#7]
Exactly.

Back then, real alpha was a joke...

Today, it's possible. But not for 2D games. Not unless you spend 6 months developing an engine in 3D. lol

cb


Gabriel(Posted 2003) [#8]
I think this might be what 0DFEx meant.

http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=turtle177605192003023744&comments=no


Basically it gives you 8 bit paletted mode, realtime alpha, realtime rotation and realtime scaling for 2d. I don't do 2d so I haven't tried it, but everyone who uses it seems to love it, so it must be worth a try if you haven't already.


cbmeeks(Posted 2003) [#9]
Yeah, I've used it and it is pretty cool!

cb


Who was John Galt?(Posted 2003) [#10]
Yeah that's the ticket thanx Sybixus.

I take it that lib doesn't meet your requirement in some way then cbmeeks?


Paradox7(Posted 2003) [#11]
Only problem is that it requires a 3D card for a 2D game :/ ahh well.. hopefully blitzmax will be far faster, and some of these effects will be able to be done much faster.


cbmeeks(Posted 2003) [#12]
nah...I'm not into it that much anymore. Got tired of trying to do full-screen alpha in 2D. Can't be done at good speeds without using 3D hardware.

cb


Russell(Posted 2003) [#13]
Purebasic does 2d alpha quite well, in real time. ;)

Russell


cbmeeks(Posted 2003) [#14]
Yeah. I just found that out. I mean, I had a tile-engine with two layers and a giant alpha-blended sprite rotating in real time PLUS a giant lava layer that was alpha-blended and it was running SMOOTH!

On one hand, I am happy that it looks like PureBasic will do what I want...on the other, I feel like I am being dis-loyal to Blitz.

cb


Who was John Galt?(Posted 2003) [#15]
First off the bat - no need to feel any guilt - use the tool that suits you best. That said, do you have B3D? I'd bet you can achieve similar with 2D in 3D using Blitz - and this is almost certainly what Purebasic is using.

What Purebasic commands are u using for your test to draw the tilemap and the alpha sprites?


Who was John Galt?(Posted 2003) [#16]
Hmmm.. I stand corrected - specialFX sprites are apparently handled by the CPU.


MrCredo(Posted 2003) [#17]
Here is it:

www.blitzbase.de/blend.zip


cbmeeks(Posted 2003) [#18]

That said, do you have B3D? I'd bet you can achieve similar with 2D in 3D using Blitz - and this is almost certainly what Purebasic is using.

What Purebasic commands are u using for your test to draw the tilemap and the alpha sprites?



I have B3D. I have tried it but the ONLY problem with B3D is the damn fuzzy textures. I'm no 3D expert but I believe it's called b-linear filtering. Or, actually being able to turn it off. In a nutshell, I don't think B3D can scale a textured quad without adding the fuzzies.



Hmmm.. I stand corrected - specialFX sprites are apparently handled by the CPU.



While that is true, it is only true for the specialFX. PureBasic has a few hardware enabled 3D commands.

DisplaySprite3D
RotateSprite3D
TransformSprite3D

These use textured quads I believe.

PureBasic allows me to mix 2D code (for the tiles and parallax layer) and then put 3D sprites on top of that! PLUS!! You can alter the sprite's 4 corners...making neat effects. I have an example that I did in PB. If Blitz can reproduce these, I will ditch PB. But I don't think it can...at least with a good framerate.....oh, and MrCredo. That is AWESOME work. But, is it using hardware acceleration?


http://cb.signaldev.com/lava.zip

Try the above program. I believe I attached the EXE so you won't have to download PB to compile. Oh, and one more thing. I am using the demo version of PB so what you are running is in DEBUG mode and it STILL fast!

cb

EDIT :

Press left/right or joystick to scroll left/right
use the mouse to move Kraid up/down on the far right


Difference(Posted 2003) [#19]

I have B3D. I have tried it but the ONLY problem with B3D is the damn fuzzy textures. I'm no 3D expert but I believe it's called b-linear filtering. Or, actually being able to turn it off. In a nutshell, I don't think B3D can scale a textured quad without adding the fuzzies.


I thought the same until I saw: http://homepage.ntlworld.com/config/spritecontrol/spritecontrol.htm


Anthony Flack(Posted 2003) [#20]
I always thought (still do, actually) that bilinear filtering actually made things look better, anyway.


Zster(Posted 2004) [#21]
The human eye can only perceive 25 individual frames per second and not the 50 or 60 your game is probably rendering at so if you show your image every second frame and it'll look the same as alpha (provided you have a constant frame rate)

run this test code to see

Graphics 640,480,32,2
backimage=CreateImage(640,480)
statex=1
statey=1


SetBuffer ImageBuffer(backimage)
For n=0 To 100
	Color Rand(255),Rand(255),Rand(255)
	Rect Rand(540),Rand(380),100,100,1
Next

sprite=CreateImage(30,30)
SetBuffer ImageBuffer(sprite)
Color 125,125,175

For n=0 To 10
	Color Rand(255),Rand(255),Rand(255)
	Rect Rand(20),Rand(20),10,10,1
Next
SetBuffer BackBuffer()

Repeat

Cls
DrawImage backimage,0,0

If halfcount=1

	If x>610
		statex=-1
	EndIf
	
	If x<1
		statex=1
	EndIf
	
	If y>450
		statey=-1
	EndIf
	
	If y<1
		statey=1
	EndIf
	
	DrawImage sprite,x,y
	
	x=x+statex
	y=y+statey
	
	halfcount=0
Else
	halfcount=1	
EndIf


Flip




Zster(Posted 2004) [#22]
damn how do you post code in that neat black box again?
edit: Thanks Leigh :)


Murilo(Posted 2004) [#23]
The first (opening) [/code] tag should read [code].


Hotcakes(Posted 2004) [#24]
Zster : The human eye can detect closer to around 72 frames per second. More than this, it is said, is overkill - but I think a higher refresh rate will still help reduce headaches in some people.

Televisions blend each frame together in such a way that it looks like motion blur to the human eye. Monitors do not do this. So no motion blur. A game running strictly at 25 fps looks horrible.


cbmeeks(Posted 2004) [#25]
Zster: Plus, while I am familiar with that "on/off" effect, its biggest flaw is flickering. I have yet to see an example that uses that effect and not flicker. Even at higher refresh rates. Problem is that you can NOT have a steady refresh rate. And by steady I mean 60 FPS and it never going below 60 or above 60. (Substitute 60 for any number)

Point is, games often drop and rise in frame rate. So, it would take some serious maths to figure out when the frame dropped and adjust the "on/off" for that. Too much work.

If I wanted to "cheat" I would use the every other pixel blank method. You know, like a checkerboard. That looks good for some things but not small sprites.

Alas, I have written a pretty damn good 2D engine using 3D hardware in C++ that I think I will use for my stuff.


Peter Scheutz: I tried the Sprite Control. It still blurs the sprites some. Try taking the demo sprite that it uses. Then, zoom in and draw a small checkerboard on the sprite. Then, run the demo and scale the sprite. You will see that checkerboard become fuzzy. I think it has been dicussed to death. I just haven't seen a B3D demo where it can take a textured quad and scale it without the fuzzies.

Anthony Flack: Normally I would agree. However, my project is trying to reproduce Metroid. And I can't have my Zoomers looking fuzzy. :-)

cb


Difference(Posted 2004) [#26]
Then, run the demo and scale the sprite. You will see that checkerboard become fuzzy


I'm only talking about 1:1 non rotated display.
Scaling, rotating, distorting etc. will never be the same because data has to be interpolated.

BTW: I have checked in Photoshop using "Image V Sprite - Comparision.bb" and changing the line:
EntityAlpha sprite,0.8 to EntityAlpha sprite,1

They are pixel perfect matches. Really cool.


xlsior(Posted 2004) [#27]
@Zster:

I tried this method, and while it is a nice idea, in reality it doesn't work out very well: there is a very noticable intermittend flicker in the object, that looks like the object doesn't get completely drawn during some cycles.

The Blend DLL that McCredo mention above is much smoother, plus it allows you to set the percentage of alpha blending as well.

If you have to do an all-blitz quick-and-dirty method with low overhead, I think I would go for the every-other-pixel-transparent as well. the image would look a bit more crude, but not having it flicker makes that well worth it.


cbmeeks(Posted 2004) [#28]

Scaling, rotating, distorting etc. will never be the same because data has to be interpolated.



Yes, I know. However, it's the interpolation that bothers me.

For example (and your B3D experts correct me if I am wrong):

Let's say you have a sprite that is 2x2 pixels. In that sprite, the upper-left pixel is white and the lower-right pixel is white and the other two are black...a checkerboard.

Now, if you double that sprite, your new sprite should be 4x4 pixels. The way I want it, the new sprite would have the two upper-left pixels white and the two lower-right pixels white and ONLY black filing the rest. What Blitz does (and SpriteControl to my knowledge) is makes the new sprite have the two upper-left pixels white (along with the two lower-right) PLUS it adds gray anti-aliased pixels in the black area. It tries to smooth out the scale. I do not want this.

This probably didn't make sense...lol

In other words, open Photoshop and scale any image up or down but make sure you use the "Nearest Neighbor" filter. That is what I am talking about.

cb


Who was John Galt?(Posted 2004) [#29]
Not moved over to purebasic yet then mate?


cbmeeks(Posted 2004) [#30]
Well, PureBasic did what I needed but like all canned engines, it didn't support Force Feedback! jeesh

So, I wrote my own engine. I am using C++ and D3D for 2D sprites and it works wonderfully.

Much more difficult but I am really impressed with myself...but then again, I have worked really hard.

So, I guess I will use B+ for my editors.

cb


turtle1776(Posted 2004) [#31]
Just saw this.

cbmeeks, I probably could have saved you a bit of time on the C++ and D3D front by directing you to the source code for my Extended B2D dll. Lots of good stuff in there for 2D users of Direct X.


Zster(Posted 2004) [#32]
Hotcakes:
Yeah got them mixed up. The human eye's ability to notice flicker hits around 60 (but 72 is probably possible for some) and is dependant on the light conditions (ie it's much lower if the screen is bright and room dark compared to a well lit room) but it's ability to percieve motion is only around 24FPS it all to do with the cones and rods in the eye read those interested read http://www.tvtechnology.com/features/Tech-Corner/f_rh_technology_corner.shtml for mor info. The moral is my trick would only work for Vsync or tripple buffered games running 90 FPS+ (which is possible but not practical) or for LCD dispalys on which it works sweet as they have image latency and much lower real refresh rates.


MutteringGoblin(Posted 2004) [#33]
Hi,

I'm not actually a BlitzPlus user, but I was reading this discussion and I was surprised to see no mention of LockedPixels() and related functions. I thought those functions were introduced to speed up writing to graphics buffers? (In fact I thought I saw another topic in General Discussions about it not long ago, something like "2D alpha is possible..."). Could you not use LockedPixels() for alpha blending and so on?


turtle1776(Posted 2004) [#34]
In my experience, LockedPixels() is about 3x faster than WritePixelFast in 2D. That's faster, but not fast enough on older, slower systems. Certainly not as fast as 3D-enabled hardware.

Plus, for alpha you need to read as well as write. Reading from VRAM is dreadfully slow.