Archived

This topic is now archived and is closed to further replies.

Game Maker

Alphablending is too slow...

Recommended Posts

Game Maker    122
Hi there. I have a problem. I''m making a isometric engine with DelphiX and I would like to make some lightning effects. I use following procedures to do that: ImageList1.Items[1].DrawAlpha ImageList1.items[1].DrawAdd ImageList1.Items[1].DrawSub And those are so slow that my fps will drop from about 350 to 3. There are same problem with: Dxdraw1.Surface.FillRectAlpha (and Sub and Add...) My computer is 900 mhz Athlon and i will have Elsa Gladiac 32 display adapter. So the problem is not in my hardware. I use 800x600 resolution with 16 bit colours. So could you give me some source how you use those procedures Like: Dxdraw.Surface.FillrectAlpha(rect(0,0,800,600),0,128); Thanks Game Maker

Share this post


Link to post
Share on other sites
LoreKeeper    152
I''m not sure... but to my knowledge DelphiX still uses a reasonably clunky software procedure to do alpha-blending. Certainly not the ideal procedure for extended effect programming -

I suggest writing your own low-level procedure (look into MMX for some good stuff for alpha-blending), or porting to your own Graphic Engine that uses DX8 and do things with Direct3D (don''t worry... the 3D aspect of D3D can be ignored for most practical purposes if you are making an isometric bitmap based game/engine).

On the plus side ofcoz... that gives you access to a whole new world of hardware supported effects (alpha, rotation, etc.)

g''luck!
A-Lore

Share this post


Link to post
Share on other sites
Sly    128
To do alpha-blending in DirectDraw, it must go through a certain number of steps.

  • Lock the surface. This is a costly process.
  • For each pixel in the source image

    • Read the pixel in the destination image that corresponds to this pixel in the source image.
    • Blend the source and destination pixels according to the alpha value.
    • Write the pixel to the destination.

  • Unlock the surface.

Do that for every frame. As you can see, it is a very costly procedure that is not hardware accelerated at any step. That is why it is inherently slow.

As LoreKeeper suggested, you could go to D3D, but then you would not be able to use DelphiX (until a new version comes out, if a new version is being developed).

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post


Link to post
Share on other sites
turbo    115
For all extensive purposes DelphiX has a very speedy DrawSUB/ADD/Alpha in most cases. It is MMX optimized and uses some ASM instructions to speed things up even faster. The blending routines can be found in DXRender.pas.

The major routine that does all the work is dxrCopyRectBlend(); which calls other routines to do all the things that Steve talks about above.

DXRender.pas *could* be re-written to speed things up, but at the cost of flexability (DXRender supports 15/16/24 surfaces and input DIBs of 8/16/32, with a re-write you could focus on just 16 or 32 surfaces like FastDIB etc...) *But* if you format your graphics to make things easier on DelphiX you will see a speed improvment.

Try these suggestions...

1. Convert everything that will be blended to the screen to 8-bit (256 color) uncompressed BMPs. DelphiX will convert the BMP to a Surface that matches the screen mode, and 8-bit BMPS will convert faster and save memory.

2. Make sure that the ImageList.Item[] that is to be blended has it''s SystemMemory property set to true. This allows DelphiX to do the Blend operations in (fast) system memory rather than (slow) video memory. (An over simplification I know, but you get the point...)

3. Set a transparency key color on the ImageList.Item[] that is to be blended. Use the key color in place of pixels where the Alpha=0. DelphiX will skip them rather than draw them.

4. Keep blended images small.

5. Use ADD instead of Alpha if you can. ADD is (10-20%) faster that Alpha because the math is simpler.

That''s about it. If you decide to write a better blend for DelphiX take a look at PowerDraw for DelphiX by Lifepower. He wrote a fast 50/50 alphablend for 16 bit modes only. It may give you a place to start. Grab the file here...

http://turbo.gamedev.net/powerdraw.zip



[ Michael Wilson | turbo sys-op | turbo.gamedev.net ]

Share this post


Link to post
Share on other sites
Buster    100
I feel your pain. Back in the day when I was using DX7 for my iso stuff, I had do bit-twiddle to get alpha.

Now I use D3D so alpha-blending is done automatically!

Share this post


Link to post
Share on other sites
Gunner    122
Hi GameMaker,

K, if you want to do some serious blending and lightmapping effects then forget about DelphiX''s DrawAlpha and other simillar software blending routines.

It won''t work, correction, it works ok for menus, but it''s no fun playing the menu

Take a good look at OpenGL and DirectX8'' D3D for your 2D needs, they''re very simillar and you can do all of your blending in hardware.
Can''t beat the speed of hardware blending 2 or 3 textures in a single pass.

You can still use the other DelphiX components for your sound, input, network .. etc

but for your 2D Blits, definitly go with 3D hardware acceleration.

Trust me, been there, done that, tried using mmx, try someone elses mmx routines, nothing came close to hardware blending.

Well that''s my 2cents on the subject

Good luck,

Gunner.

Share this post


Link to post
Share on other sites
Game Maker    122
Hi.

well, I could try that.. what was it.. D3D (I assume that is Direct 3D). So I''m familiar with 2d graphics programming, but not in 3d. Could you tell me some good tutorials, examples, etc.
Can I use DelphiX''s D3D support? There are some component named TD3D. Can I use it, or must i use some unknown protocol (I really don''t want to use OpenGl)


2d is bad, 3d is good?

Game Maker

Share this post


Link to post
Share on other sites
spacemadness    122
This is the deal, as I have gone through the same thing myself, with regard to DD and a-blending.

1) As previously stated each pixel must be read, blended then re-written. Along with a lock and unlocking of the surface. This is SLOW AS HELL. Since, DirectDraw has to be software a-blended this is your only choice. ( I found it works fine for smaller sprites. Like a ship or character etc but still lets face it, it still sux... ) Even with MMX, ASM and all that great optimization stuff it will STILL be slow as hell... just the way it goes for 2D.

2) D3D is in.. Its hipper.. DirectDraw is losing it''s power for making games. ( Well games that LOOK GOOD anyways. ) Why do you think M$ stopped Deving DirectDraw? Now, there are a few things you need to know about with regards to the differences in DX 7 and DX 8.

Direct X 7 D3D is best suited for if you need the ''niceness'' of blitting RECTs ( With DirectDraw ) and the power of D3D... Because, D3D in Direct X 7 and DD can be used together will allow you to blit Rectangles. Like say blitting a background you just use DirectDraw 7 and for the sprites and all other graphics use D3D. Unfortuanely, and I dont know why, M$ decided to DROP DirectDraw all together in Direct X 8... This means you no longer can do DirectDraw AND Direct 3D on the same surface... This means no more blitting capabilities... only texture mapping to polys are allow in DX 8... ( And in D3D map size is limited to 256X256 ) Were as in DX7 you COULD combine DD and D3D... The reason WHY they dropped DD7 from the 3D realm was to force game makers to use D3D features ( Which as you know are all hardware accelerated ... this is good reason enough. ) But now if you want to blit a background and still render your characters in D3D ( To get hardware acceleration on a-blending and such ) you have to use Direct 3D version 7... Version 8 simple will NOT allow the existance of both a DD and D3D object...

So, to summarize... base your DX version picking like this...

If you need make 2D/3D games use DX 7.

If you are just doing PURE 3D use DX 8.

Share this post


Link to post
Share on other sites
Sly    128
quote:
Original post by Game Maker

Hi.

well, I could try that.. what was it.. D3D (I assume that is Direct 3D). So I''m familiar with 2d graphics programming, but not in 3d. Could you tell me some good tutorials, examples, etc.
Can I use DelphiX''s D3D support? There are some component named TD3D. Can I use it, or must i use some unknown protocol (I really don''t want to use OpenGl)


2d is bad, 3d is good?

Game Maker


To use hardware-accelerated 3D in a manner simulating 2D, you use orthographic projection. This means that there is no perspective in the scene (objects do not get smaller as they go off into the distance). You replace your blits with the rendering of two triangles that form a rectangle. The image that was to be blitted is used as the texture for these triangles. You generally use an alpha layer in the image to designate the transparent areas. There is no color keying in D3D8, hence the requirement for an alpha layer.

There is an article here on GameDev.Net that explains how to use D3D to draw a tiled background.
http://www.gamedev.net/reference/programming/features/d3dtile/

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post


Link to post
Share on other sites
Gunner    122
One of the biggest problems is Microsoft,
they''ve promised us 2d hardware alpha blending since DirectX 5 or 6 i think but was never implemented.
In the DX docs it clearely has the blending calls but right under em it says '' not implemented ''

Our videocards has had the hardware 2D blending capability for years but lack of MS support has made this great feature dormant.

It''s too bad because most of the games that i play are still 2D.

Trying to shove 3D down my throat will not change my stance on this. today, 2D characters in games still look better than 3D polygonal ones, period '' Flames on ''.

In an interview with Id software, there was one answer to a question that made me laught.
ID was boasting the new GeForce 3 for the upcoming Doom 3.

the question was : how many characters can we expect on screen at the same time ?

ID Soft''s answer: well, you''ve seen the complexity of the new Doom 3 characters with the Geforce 3, those are very polygon heavy characters, you draw your own conclusions !

Great, another game spent walking in a castle and no one around.
Don''t get me wrong, i am excited about the geforce 3, it''s definitly a leap in the right direction. but i''m still sticking to my guns for now(2d).

Ok sorry about side tracking.
Back to your question,

Yes you can use DelphiX for your 2d/D3D.

Take a look at the examples hori made in your D3DIM subdirectory under your DelphiX subdir.

It has three sample programs that uses a cube with textures on the faces.. you basically have all you need right there.
I suggest you also download the directX helpfile (it''s pretty small).
It will exlpain alot of what you see in Hori''s example.

I modified that example a while back, i wanted to see how easy it would be to modify the textures and have a full 2d moving background blitted on the screen with the blended cube rotating over it.
It''s relatively easy and it looks great !
and on the plus side, he''s using a dximagelist to manage his textures. pretty sweet.

I suggest you start on those examples, they look complicated but they''re not. go line by line and what you don''t understand, just post a question here.

k, that''s it for now.
I hope this helps a bit,
Best Regards,

Gunner.

Share this post


Link to post
Share on other sites