Mask transparency issues - ability to change mask colour on the fly

Previous topic - Next topic

Ian Price

Hi Gernot

Would it be possible to implement a change in transparency on the fly, rather than using SETTRANSPARENCY for LOADSPRITE/GRABSPRITE and LOADFONT?

The reason I ask is that it's not actually possible to draw some things with transparency at RGB(255,0,128) - you can use DRAWRECT fine, but you can't with DRAWLINE or POLYVECTOR.

Being able to change the transparency in realtime on the fly could help create some visual effects very quickly (eg halos of light around torches/characters, colour changes to sprites etc.).

See this example here, where the inconsistencies of the colour mask cause problems

Code (glbasic) Select

CREATESCREEN 1,999,64,64

USESCREEN 1

DRAWRECT 0,0,64,64,RGB(255,0,128)
//DRAWRECT 0,0,64,64,RGB(255,0,129)

USESCREEN -1


WHILE TRUE

DRAWRECT 100,100,64,64,RGB(255,0,128)

STARTPOLY 999
POLYVECTOR 200,100,0,0
POLYVECTOR 264,100,64,0
POLYVECTOR 264,164,64,64
POLYVECTOR 200,164,0,64
ENDPOLY

DRAWLINE 300,100,364,100,RGB(255,0,128)
//DRAWLINE 300,100,364,100,RGB(255,0,129)

SHOWSCREEN

WEND


I'm working on something right now that while working well on pc and (slower) on webos it kills the speed significantly on Pandora. Being able to draw in a transparent colour onto a sprite would significantly increase the speed on all systems.

Cheers :)
I came. I saw. I played.

Kitty Hello


erico

I didn´t quite understant what you mean Ian, but in case I did,...

Couldn´t we have multiplication modes similar to, let´s say photoshop, on our sprite drawing commands?
I mean, other then actually drawing the sprite, you have a few option on drawing that, like add, multiply, subtract, screen, color, hue,etc.

I guess that way we could use our sprite masks to change the total hue of a sprite.
If I remmember correctly, Mentalthink suggested that a few months ago too.

I get a feeling such results could be done by sprite to mem + lot´s of math.
But I thing such thing inside the drawsprite command, for example, or a command like alphamode before drawing would come cool.

I hope I did understand what Ian meant correcly as I think he could achieve what he wants this way.

Ian Price

Gernot - it's an alternative (and I'm using alternatives), but it's nowhere near as fast as what I proposed.

BlitzMax allowed changing of transparency on the fly and it had lots of dynamic uses.

There'd be a fair bit of data being pushed for what I want with SPRITE2MEM/MEM2SPRITE, which in essence is to make "holes" on a larger map - changing transparency I can draw a load of "hole" sprites onto another sprite in one go then change transparency back to make "holes" on the main sprite quickly and easily. Even on Pandora that should be much faster as there's no array management or data pushing. If you think of Lemmings, and worms blasting holes into a landscape you wouldn't be far off, however as the landscape behind needs to be visible, you can't use the same colour background as in Lemmings. As I said - I can do this in a variety of ways, which are OK on pc (500 FPS) and even on webOS I'm getting 50+ FPS, but on Pandora (and probably GP2X, Caanoo and Wiz) , it's a killer - and I seriously want this effect on those machines. I know none of those machines are that powerful, but the affect I'm after is available on 8/16bit machines with far less power. Lemmings, Zelda, Marion, and The Addams Family all did something similar back in the 80s.

No erico, that wouldn't work for two things I'm working on. It would be useful for GLB to have though.

If it can't be done, then that's fair enough - I guess it would be a hassle to implement, but the SETTRANSPARENCY command isn't too far off already, although I suppose it may also affect performance.

[EDIT] Here's some code

Code (glbasic) Select

CREATESCREEN 1,999,640,480

USESCREEN 1

DRAWRECT 0,0,640,480,RGB(0,0,0)

USESCREEN -1

LOCAL time

WHILE TRUE

INC time

IF time>20
USESCREEN 1
  DRAWRECT RND(640),RND(480),RND(64),RND(64),RGB(255,0,128)
USESCREEN -1

time=0
ENDIF

FOR n=0 TO 1000
DRAWRECT RND(640)-32,RND(480)-32,64,64,RGB(RND(255),RND(255),RND(255))
NEXT

DRAWSPRITE 999,0,0

SHOWSCREEN

WEND


Imagine the above, but where the holes are actually moving and are not squares/rects. Try doing that with MEM2SPRITE quickly. If you could "paste" a circle of RGB(255,0,128) onto the black background (by turning off the transparency or changing it to another colour on the fly), then you could do what I want easily. Like I said, you can use DRAWRECT (you can make a circle with several rects), but you can't draw with POLYVECTOR or DRAWLINE or use predefined sprites.
I came. I saw. I played.

Kitty Hello

I see. This is a quite complex beast. We need to write a blit function with mem2sprite that punches holes. On the caanoo you have the software rasterozer. This might be a bit slow..,
We'd have to test.

Ian Price

If it comes down to it, this feature of my game can be removed for lower specced/powered machines, however I think it would be a shame. As I said, I do have a couple of workarounds, but they do tax lower machines. I just hoped that being able to blit a "hole" tytpe sprite onto another sprite without (or by being able to change) transparency would be a dynamic feature.

It's not really worthy of your time tbh Gernot - I'm sure you're busy enough as it is.

No worries :)
I came. I saw. I played.