gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Semi-transparent sprite becomes normal

#165176 - sverx - Thu Dec 11, 2008 4:00 pm

Hi!
I'm having a strange problem with an homebrew I'm developing.

In short: I have semi-transparent sprites that are shown as normal, all of them. It doesn't happen with some emulator, but it happens on the hardware (NDS Lite)... so I guess I forgot something in my program. :|

Any idea? Besides setting "OBJ Mode" bits to 0x01 in "OBJ Attribute 0" in the OAM entry of the sprite, what should I do?

Thanks...

#165177 - DiscoStew - Thu Dec 11, 2008 4:58 pm

Have you dealt with the Blend Control for this yet?

http://nocash.emubase.de/gbatek.htm#lcdiocolorspecialeffects
_________________
DS - It's all about DiscoStew

#165178 - sverx - Thu Dec 11, 2008 5:02 pm

DiscoStew wrote:
Have you dealt with the Blend Control for this yet?


mmm... it says:
Quote:
Semi-Transparent OBJs
OBJs that are defined as 'Semi-Transparent' in OAM memory are always selected as 1st Target (regardless of BLDCNT Bit 4), and are always using Alpha Blending mode (regardless of BLDCNT Bit 6-7).


so I guess I don't have to set it for 'Semi-Transparent' objects... wrong?

BTW it's true I'm using it for alpha blending two BGs (and it's working). Can this affect the objects semi-transparency?

#165259 - sverx - Mon Dec 15, 2008 11:55 am

I'm stuck with that.

Does somebody knows if are there some things I shouldn't do when using semi-transparent sprites?

Can I use alpha blending between BGs? Can I use 3D? Can I use BG priority and object priority? Can I use extended palettes? I'm using all these...

Don't know why, these semi-transparent sprites just aren't semi-transparent... and it happens only on hardware! (on no$gba it's ok...)

Ideas? Hints? Help?

Please...

#165268 - Cydrak - Mon Dec 15, 2008 7:43 pm

Can you elaborate on your settings? (Mainly BLEND_CR, BG_CR, OBJ attributes, and 3D rear plane?) It would help to have a minimal example; I can't really imagine palettes affecting anything.

To answer your question: When you have 3+ layers, priority can and will affect things, since the hardware does at most one blend per pixel. For example, if you blend a solid "cloud" layer over everything else, I expect nothing can blend beneath it--everything below should behave as solid. If parts of the cloud are transparent, then that may allow further blending, just not below the clouds themselves.

I thought no$gba emulates that, though I could be wrong. So not sure if it's your problem. :/

#165269 - Maxxie - Mon Dec 15, 2008 7:47 pm

sverx wrote:

BTW it's true I'm using it for alpha blending two BGs (and it's working). Can this affect the objects semi-transparency?


Just a quick try.
Since you are using alpha blending, could it be that you set the blending parameter in it, so that it is set to (nearly) 100% opaque?
Then it would still be processed as transparent but not appear as.
_________________
Trying to bring more detail into understanding the wireless hardware

#165299 - sverx - Tue Dec 16, 2008 10:16 am

Cydrak wrote:
Can you elaborate on your settings? (Mainly BLEND_CR, BG_CR, OBJ attributes, and 3D rear plane?) It would help to have a minimal example; I can't really imagine palettes affecting anything.


I have all BGs on, BG0 being used for 3D and it has priority 0, so it's ahead. 3D back plane is transparent. Then there's another BG, with priority 1, that is semitransparent, and finally the other 2 BGs, both "normal". All these BGs are 256 colors extended palette 'text' modes.

My sprites all have priority 1 or 2, so they should be right behind the 3D layer or right behind the semitransparent 2D BG.
edit:Those with priority 2 are 'normal', half of the ones having priority 1 should be semi-transparent. The other half of the sprite are also 'normal' and have the same priority, 1, but they have lower object ID so that they are drawn behind the one that should be semi-transparent.

Pressing a key on my DS I can even turn off the BG0... but unfortunatly nothing changes :|

Here's the video mode:
Code:
videoSetMode ( (FadeActive?DISPLAY_BG0_ACTIVE:0) | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_BG3_ACTIVE | MODE_0_2D | ENABLE_3D | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D_LAYOUT | DISPLAY_SPR_1D_SIZE_128 | DISPLAY_BG_EXT_PALETTE | DISPLAY_SPR_EXT_PALETTE );


the BGs:
Code:
BG1_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(BGActive+4) | BG_TILE_BASE(5) | BG_PRIORITY(3);  //ultimo dietro!
BG2_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(BGActive)   | BG_TILE_BASE(1) | BG_PRIORITY(2);
BG3_CR = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(BGActive+2) | BG_TILE_BASE(1) | BG_PRIORITY(1);  //davanti!


the Blend:
Code:
BLEND_AB = 0x0B | ( 0x05 << 8 );
BLEND_CR = BLEND_ALPHA | BLEND_SRC_BG1 | BLEND_SRC_BG2 | BLEND_SRC_BG3 | BLEND_SRC_BACKDROP | BLEND_DST_SPRITE |  BLEND_DST_BG1 | BLEND_DST_BG2 | BLEND_DST_BG3 | BLEND_DST_BACKDROP | ((FadeActive)?BLEND_SRC_BG0 | BLEND_DST_BG0:0);


3D rear plane
Code:
glClearColor(31,31,31,0);     // BG must be transparent! (r,g,b,alpha)


Cydrak wrote:
[...] the hardware does at most one blend per pixel.


I'm always keeping this in mind, I'm sure I'm not trying to blend more... at least, if I'm not mistaking...

Thanks :)


Last edited by sverx on Tue Dec 16, 2008 3:04 pm; edited 2 times in total

#165300 - sverx - Tue Dec 16, 2008 10:21 am

Maxxie wrote:
Since you are using alpha blending, could it be that you set the blending parameter in it, so that it is set to (nearly) 100% opaque?
Then it would still be processed as transparent but not appear as.


No, I'm using 0x0B and 0x05 for blending... :|

#165377 - sverx - Thu Dec 18, 2008 3:19 pm

No news? Does somebody know if semi-transparent sprite should have higher priority than others or if they should be the first/last objects or if they can't stay behind a BGs or... what?

Help appreciated. A lot! :|
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165409 - silent_code - Fri Dec 19, 2008 8:05 pm

I am pretty sure GBAtek can answer your question.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#165414 - Cydrak - Fri Dec 19, 2008 10:00 pm

Maybe there's something more to it, because I couldn't reproduce the problem (even with 3D, ext. palettes etc). :/

You didn't mention OBJ attributes, but this is what I had:
Code:
attribute[0] = OBJ_Y(...) | ATTR0_COLOR_256 | ATTR0_TYPE_BLENDED;
attribute[1] = OBJ_X(...) | ATTR1_SIZE_32;
attribute[2] = objTile    | ATTR2_PRIORITY(1);

If you can *see* the sprites I doubt OAM order is a problem. TONC's final chapter points out some GBA quirks if your indices/priorities conflict, but GBATEK says that's fixed on the DS. Though, overlapping semi-transparent sprites can cause some unintuitive effects.

Putting them behind a BG should work; however, if the BG itself is a BLEND_SRC then its solid areas will effectively hide any further blending.

You have pretty much all the BLEND_DSTs, so--if there's no BG above the sprite, you can see it, other stuff blends, and it still doesn't work, the only thing I can think of is it's not getting set as "1st" for some reason. Do they all turn semi-transparent if you add BLEND_SRC_SPRITE? If so, perhaps check the OAM.

Something else to check... any chance you turn on windowing? I'm not as familiar but apparently there's a "color effect" bit, similar to the layer bits, that needs to be assigned for each region. If zero, blending would be disabled.

#165433 - JYC376 - Sat Dec 20, 2008 2:39 am

Perhaps you should update your devkitARM and libnds first. From your code it seems you're using an older version.

#165441 - silent_code - Sat Dec 20, 2008 11:43 pm

I do not have enough time to read all of this, but you can set sprite transparency without the blend registers. I remember reading something about problems when you have transparent sprites and set the object layer in the blending registers.
Again, GBATek should help to clarify things.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#165472 - sverx - Mon Dec 22, 2008 2:24 pm

Hi! Thanks for the replies...

Cydrak wrote:
You didn't mention OBJ attributes


I have a for cycle that defines two OBJs at time: the lower (higher OBJ id) is solid, the upper (lower OBJ id) is solid or semi-transparent, it depends on the priority (it should be transparent when prio==1)

Code:
SpriteCTRL->Sprite[2+en*2].y_attrib_0= ATTR0_SQUARE | ATTR0_COLOR_256  | OBJ_Y (ey);
SpriteCTRL->Sprite[2+en*2].x_attrib_1= ATTR1_SIZE_32                   | OBJ_X (ex);
SpriteCTRL->Sprite[2+en*2].attrib_2  = TILE256_1D_128K(128) | ATTR2_PRIORITY(prio) | ATTR2_PALETTE(15);

SpriteCTRL->Sprite[1+en*2].y_attrib_0= ATTR0_SQUARE | ATTR0_COLOR_256  | ((prio==1)?ATTR0_TYPE_BLENDED:ATTR0_TYPE_NORMAL) | OBJ_Y (ey);
SpriteCTRL->Sprite[1+en*2].x_attrib_1= ATTR1_SIZE_32                   | OBJ_X (ex);
SpriteCTRL->Sprite[1+en*2].attrib_2  = TILE256_1D_128K(2048-16-en*16) | ATTR2_PRIORITY(prio) | ATTR2_PALETTE(0);


(TILE256_1D_128K is a simple define)
Code:
#define   TILE256_1D_128K(n)   ((n)>>1)


Cydrak wrote:
Putting them behind a BG should work; however, if the BG itself is a BLEND_SRC then its solid areas will effectively hide any further blending.


when it is semi-transparent, it has priority=1 so it's above all the BGs, excluding BG0 (the 3D layer), that can be deactivated --but it doesn't change :|

Cydrak wrote:
You have pretty much all the BLEND_DSTs, so--if there's no BG above the sprite, you can see it, other stuff blends, and it still doesn't work, the only thing I can think of is it's not getting set as "1st" for some reason. Do they all turn semi-transparent if you add BLEND_SRC_SPRITE? If so, perhaps check the OAM.


I'll do this test asap. (Everything else blends ok...)

Cydrak wrote:
Something else to check... any chance you turn on windowing? I'm not as familiar but apparently there's a "color effect" bit, similar to the layer bits, that needs to be assigned for each region. If zero, blending would be disabled.


No, I'm (still) not using any windowing effects.

JYC376 wrote:
Perhaps you should update your devkitARM and libnds first.


Of course I will, but I think it's not related. And I'm not using a very old version, I think... or am I?

Quote:
[devkitARM]
Version=22
[libnds]
Version=20071023

_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165493 - wintermute - Tue Dec 23, 2008 2:20 am

sverx wrote:

Quote:
[devkitARM]
Version=22
[libnds]
Version=20071023


Quite old, yes.

Quote:
[devkitARM]
Version=24
[libnds]
Version=1.3.1


libnds 1.3.1 was released a couple of weeks ago. 1.3.2 will probably be released before New Year.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#165498 - sverx - Tue Dec 23, 2008 9:53 am

Cydrak wrote:
Do they all turn semi-transparent if you add BLEND_SRC_SPRITE? If so, perhaps check the OAM.


I made this test yesterday: NO they DO NOT turn semi-transparent (!!!) 8| 8| Something really strange is happening...

Cydrak wrote:
Something else to check... any chance you turn on windowing?


Any chance I didn't do that but it's turned on by the R4 software? Should I somehow 'reset' it?

wintermute wrote:
Quite old, yes. [...] 1.3.2 will probably be released before New Year.


Thanks. Going to update soon then :)
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165625 - sverx - Tue Dec 30, 2008 12:25 pm

wintermute wrote:
[devkitARM]
Version=24
[libnds]
Version=1.3.1


Upgraded, no change with that :|

Going to dissect my code until I find what's wrong there...
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165662 - sverx - Fri Jan 02, 2009 10:33 am

Hi!

BAD BAD news, I hope someone can prove I'm wrong... :|

I was running a couple of tests these days, and the results, in their shortest form, it's:

you can't display any sprite behind a semi-transparent sprite.

It just doesn't work, no matter the value of SUB_BLEND_CR :|

So, if you've got a sprite 0, semi-transparent, on top of a sprite 1, normal, on top of a BG, looking thru sprite 0 you can't see sprite 1, but you'll see those BG pixels that were hidden by sprite 1 (!!!).

So, what GBATEK (here) says:
Quote:
The OBJ Layer
Before special effects are applied, the display controller computes the OBJ priority ordering, and isolates the top-most OBJ pixel. In result, only the top-most OBJ pixel is recursed at the time when processing special effects. Ie. alpha blending and semi-transparency can be used for OBJ-to-BG or BG-to-OBJ , but not for OBJ-to-OBJ.

also applies when you're not using color special effects.

Again, I hope I'm wrong. Feedback / help / comments appreciated. A lot!

(btw, Happy New Year!)




.
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary

#165674 - DiscoStew - Fri Jan 02, 2009 10:00 pm

sverx wrote:
you can't display any sprite behind a semi-transparent sprite.


Unfortunately, this is true. The 2D hardware is not capable of that. I was thinking that you could take all the semi-transparent sprites, and render them as quads with the 3D hardware, but after thinking about it a little more, you'd be very restricted with that method. They'd be semi-transparent to each other, but you are still dealing with the 2D hardware, but in terms of BGs instead of sprites, and that's only one BG vs multiple sprites.

You wouldn't be able to have these special sprites with their own amount of semi-transparency, because they'd only be effecting anything within the 3D hardware, which means if there is nothing but black behind these sprites in the 3D hardware, they'd end up having a shade of black in the final resulting render on the BG itself, and not be semi-transparent at all against other BGs and sprites.

Unless you were able to take your entire 2D engine, and convert it all to be rendered with the 3D hardware, I don't see how you could get this effect easily.
_________________
DS - It's all about DiscoStew

#165717 - sverx - Mon Jan 05, 2009 10:19 am

Thanks for your reply, and for confirming me that it's true.

Well, actually I guess I won't turn everything into 3D, I think I'll redesign parts of my work to use one semi-transparent BG instead of the semi-transparent sprites I can't use on top of other sprites.

Anyway if somebody discover a trick (besides flickering...) to display a sprite behind a semi-transparent one... well, I'm here ready to listen :)

Thanks!
_________________
libXM7|NDS programming tutorial (Italiano)|Waimanu DS / GBA|A DS Homebrewer's Diary