#123378 - Noda - Tue Mar 27, 2007 7:51 pm
Could you tell me if it's possible to alpha blend a 3D object with a tiled background?
I recently rewrote my game engine to use 3D quads insteads of OAM sprites for more flexibility, but I can't manage to make those 'fake' sprites transparent over the tiled background like I did with 2D sprites :/
If you know how to do this, please help me, thanks a lot ;)
#123398 - silent_code - Tue Mar 27, 2007 10:02 pm
i already hate myself for that answer: search the forum. it is there. *sorry*
ps: yes, you can.
#123404 - Noda - Tue Mar 27, 2007 10:40 pm
Thanks, that's all I needed to know then ;) I'll make some searches...
edit: sorry, but it seems that I have no luck with searches... :( I tried to read quite a lot subjects but then none of them answers my question.
Could I ask you to point me some topics, or at least some keywords for my search (I used combinations of 3D, transparency, alpha blending, backgrounds, no luck)
thanks a lot.
#123581 - qw3rty - Thu Mar 29, 2007 7:56 am
The search-engine of DSdev.org sucks - I almost never find the info I'm after , and also bug other people with stupid questions ;)
I'll try to help :
On the NDS you can do either BG-BG blending.
The COMPLETE 3d-scene can be used as "background" too.
you can't unfortunately do per-polygon blending against an background.
At least not with BG-BG-blending.
You can however make the polygons transparent at rendering - which may be what you want...(glPolyFmt(alpha(xx),....); )
Draw you Background you want to be the "lowest" part with the lowest priority (BG_PRIORITY3).
The 3d-BG needs a higher priority (BG_PRIORITY0).
(BG_PRIRITY0 will be drawn on top of BG_PRIORITY3)
I hope I could help.
#123758 - Payk - Fri Mar 30, 2007 9:52 pm
If you update devkitpro, you can choose on clearcolor-function a blend value from 0 to 31(its the 4th argument...totaly new since antialias works). If you choose 0 you should directly see a bg behind the polygone.
If now the polygone it self has blending between 1 and 30 (polyfmt blending) it should be semitransparent to the bg.
(notice: i didnt tested it !)
BTW: Noda you did a great game ;)
#123765 - silent_code - Fri Mar 30, 2007 10:58 pm
another solution is the socalled "clear image". that is, instead of a single colored clear plane, you can set up an entire image (aswell as an depth image - think resident evil etc) that will clear the display. now, any part of the scene you don't draw to will contain that image. downpart: you have to use 2 whole vram banks, as each, the color and depth image, need to be a 15/16bit full resolution bitmap. :^|
#124009 - Noda - Mon Apr 02, 2007 1:37 pm
Thanks, I'll check Payk solution as I already use all 4 vram banks ;) And I know how to do BG-BG blending but I only want specific polys to be transparent over the BG ^^
I'll report if it works as it may be useful for other people or future requests.
PS: You did a great job too Payk, your 3d engine is quite impressive ^^
#124963 - Payk - Tue Apr 10, 2007 12:21 pm
:D thanx Noda. And congrats btw. I really think your game is the better one, the gameplay is still fun for me :D
#125198 - RavenWorks - Thu Apr 12, 2007 1:47 am
Have you still not succeeded? I've got a 2D engine running on transparent quads. I'll see what I can do to help if you're still having trouble.
#151521 - TwentySeven - Thu Feb 28, 2008 6:36 am
*necro bump*
I'm running into this, and another weird issue as well. I've searched the forums and updated my setup a little, but the basic problems remain.
I have a 3d layer floating over two Tiled BGs.
I try and render a texture quad with a 16bit alphacutout texture, that works fine. Once I turn on per poly alpha translucency, things start going weird:
Specifically, at values of ALPHA_POLY(22 to 31) the quad remains fully opaque, except for the textures alpha cutout.
At values of ALPHA_POLY(0 to 21) the quad disapears completely.
I noticed in the nehe lesson 8 it uses a glClearColor alpha of 31, making the 3d background fully opaque. When I tried this, it indeed blends correctly against the ClearCcolor (black) but of course I want the 3d layer transparent..
Here's my setup:
Code: |
glInit();
//Enable texturing
glEnable(GL_TEXTURE_2D);
// setup the rear plane
glClearColor(0,0,0,0);
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
glClearDepth(0x7FFF);
glViewport(0,0,255,191);
//camera junk
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,255,191,0,-512,1024);
glTranslatef(0,0,-1024);
///
while (1)
{
glEnable(GL_BLEND);
glAlphaFunc(BLEND_ALPHA);
glPolyFmt(POLY_ALPHA(15) | POLY_CULL_NONE | POLY_ID(0) );
//bind a texture
glBegin(GL_QUAD);
// ~~ draw some stuff
glEnd();
glFlush(0) ;
//glFlush(GL_TRANS_MANUALSORT); //Makes no difference
swiWaitForVBlank();
}
|
#151533 - Cydrak - Thu Feb 28, 2008 4:56 pm
What's BLEND_ALPHA for? glAlphaFunc controls the alpha test. Alpha less than the threshold isn't rendered. Maybe that's what you're seeing?
Having tried this--alpha test applies to the poly, not the texture alone, so it seems a POLY_ALPHA less than glAlphaFunc will never show up. This is more obvious with A5I3 / A3I5 textures, which can have fractional alpha (like color, it's further modulated by the poly's).
Also, a transparent "clear color" isn't enough. You still need to tell the layer engine to _use_ the alpha, by setting BLEND_CR:
Code: |
glClearColor(0, 0, 0, 0);
glClearDepth(0x7fff);
glClearPolyID(63);
glEnable(GL_BLEND);
/* unless needed--like all glEnable*, this is scene global */
glDisable(GL_ALPHA_TEST);
glAlphaFunc(0);
BG0_CR = BG_PRIORITY(m);
BGx_CR = ... | BG_PRIORITY(n); /* n > m */
BLEND_CR = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_*;
glPolyFmt(POLY_ID(x) | POLY_ALPHA(y) | ...);
glBegin(...);
|
When 3D on BG0 is selected as a source (and it appears atop any "dest"), it is always a per-pixel alpha blend, ignoring BLEND_AB, BLEND_Y and the blend mode. This might not be true of other matched "blending pairs", though...
#151559 - TwentySeven - Fri Feb 29, 2008 4:44 am
Ok, thankyou very much for the tips Crydak.
My BG_CR's now have BLEND_ALPHA, and Ive done alot of messing around with BLEND_CR, but I still can't get things working correctly.
Could someone possibly provide some demo source of this working?
#151580 - M3d10n - Fri Feb 29, 2008 6:53 pm
Make sure the priorities are correct, so the tiled BG renders below the 3D BG. Also, are you testing on hardware? I wouldn't trust emulators for such graphic effect (exaple: none of the emulators emulate fog properly yet).
#151589 - TwentySeven - Sat Mar 01, 2008 12:30 am
Yeah theres definately a difference between the hardware and the emulators.
My BG's are rendering in the correct order, things are rendering opaquely just fine.
Its when I introduce polyalpha and attempt to see the tile bg's through the translucent polys, that it just either renders them completely opaque or not at all.
#151596 - Cydrak - Sat Mar 01, 2008 2:39 am
BLEND_ALPHA goes in BLEND_CR, not BGx_CR. (Was that what you meant?)
http://draci.chaosnet.org/code/ex-3dblend.zip
Here, hopefully this works. Don't bother with the emulators. Even the lovely NO$GBA gets it wrong. :/
I actually found some quirks with this (see source comments). Briefly, the DS' blending is normal for RGB, but alpha is treated rather curiously. My guess would be out.A = MAX(source.A, dest.A). Notice when touching, that it's never possible to fully hide the BG... and how stuff seems not to blend outside the quads, because the alpha stays constant.
You can also see (watch the quads at the very end of the trail) the thing with alpha + poly IDs, and how it leads to "draw behind" effects. This seems order or Z-dependent. Like if I draw quads of ID 0, 1, then 0; and 1 sits in the middle of the stack, then the IDs may not clash as usual.
#151597 - TwentySeven - Sat Mar 01, 2008 3:07 am
And the winner is Cydrak! Thankyou so much for taking the time to put that sample together, it let me fix what I was doing wrong in about 30 seconds :D
BLEND_CR accepts multiple DST_ flags. I had been experimenting with a single DST at a time. >_<
I've added all of the required DST_BGs and DST_BACKDROP and its working now.
Thankyou so much!
#151599 - TwentySeven - Sat Mar 01, 2008 3:35 am
Small Update: No$GBA 2.6a seems to get it right. The version I was using before (2.5x?) was goofing it badly.
#151601 - Cydrak - Sat Mar 01, 2008 4:05 am
Heh, welcome. :)
BLEND_CR is an odd beast, and takes any combination of anything. It will only blend once, but it can make different choices. As I understand, for each pixel it looks at the layers and sprite visible there (literally--so index or alpha 0 is invisible). Then, for blending it considers the top two; for fades, just the top of the stack...
(ed: you're right, release notes say blends/ids are addressed in 2.6a... I still have 2.6)