PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

"lightmap" question

Hi!

I'm trying to move some of my old code (working with pocketHAL, I had to do everything manually - which I loved ;) ) to EDGELIB to test some things for iPhone (and maybe ppc & smartphone too).

I had a kind of custom "blitLightmap" where I had a gray texture, ranging from 0 to 255, and I used it to produce shadows in 2d backgrounds, kind of 3d lightmap multitexturing but (obviously) in 2d.

128 meant "keep the background color as is", the closer to 0 the darker the background color changed, and closer to 255 would mean to put some light (usually @ 255 it was saturated with white color)

I'm terrible explaining this kind of things, I hope you understood it :)


I loved this method because I used no mults (just shifts & ands to get the R,G,B and a lookup table), and it was pretty fast, but which should be the correct way to do that in EDGELIB? Should I directly use an alpha blit, or is there any way I can make this kind of function run faster?

TIA
Kak
Hi,

For iPhone we recommend using OpenGL, hardware acceleration makes a big difference for this device. You can use the EDGELIB wrappers to draw 2D graphics in OpenGL.

If you can't use OpenGL you can program your routine manually by locking surfaces.

For your example you can also use subtractive blending for the shadow, and additive blending for the lighting. In this case you need to have 2 different surfaces, one for the shadow and one for the light.
edge wrote:For your example you can also use subtractive blending for the shadow, and additive blending for the lighting. In this case you need to have 2 different surfaces, one for the shadow and one for the light.


sorry for answering sooo late (I'm working on this project from time to time).

I suppose the substractive/additive blending is clamped to the bottom/top values (I mean, if I add a lot of light, it will stay at 255)

Is is possible to have a 'signed' image to simulate the substractive/additive effect in just one step? (i.e. 128 means no change, >128 is additive, <128 is substractive)
Hi,

Yes, when using subtractive/additive blitters the colors will clamp to 0 (for subtractive blending) and 255 (for additive blending).

Unfortunately, it's not possible to use a signed image without writing a custom blitter.