GLBasic forum

Main forum => GLBasic - en => Topic started by: bigsofty on 2007-Apr-07

Title: ALHAMODE Error
Post by: bigsofty on 2007-Apr-07
Alphamode does not work in 3D, It simply does not blend properly using 'X_SPRITE' for example. Im writing a 3D particle system and its stopping the particles from blending properly. Works fine in 2D mode thought.

I have seen this problem before, as part of the development of Blitz3D, its a depth sorting issue with alpha blended textures... it was sorted by introducing the W-Buffer... not sure if its the same for OpenGL...
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-Apr-09
Oh dear. Of course, if you want it that way, you should be sorting them first, and draw them back to front. later.
Title: ALHAMODE Error
Post by: bigsofty on 2007-Apr-09
Quote from: GernotFrischOh dear. Of course, if you want it that way, you should be sorting them first, and draw them back to front. later.
Eek! 10000+ particles!,,, I'll look into it, maybe there's an OpenGL solution to this...

Tried disabling the Z-buffer, this fixes the blending artefacts but messes up the draw order...

Idea: maybe use a vertex shader to sort the the vectors with the GPU...?
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-Apr-10
That might be an option. Though I'm not of much help here. I don't even have a shader compatible card :(
Title: ALHAMODE Error
Post by: bigsofty on 2007-Apr-10
Sorry to hear that Gernot... :(

Im not making much headway Im afraid, everything I try is slowing the system down or messing up the graphics... its designed to work in 2D as well, so Ill concentrate on that for now...
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-Apr-11
If you're putting in enough particles, z-order should not be noticable, I guess.
Title: ALHAMODE Error
Post by: bigsofty on 2007-Apr-12
The more particles, the more 'artefacts' are shown unfortunately, also if the Z-order is off, it kinda messes with other 3D objects... so a spaceship with particles, for its weapons, can sometimes be seen with shooting away from the camera with particles visible 'within' the spaceship body...

...Ive not given up yet, though, Im converting the system from frame based movement to time based and with this adding more custom OpenGL code to try and minimise this unwanted affect.

P.S. Gernot, is there any way I can get access, via in-line C, to the GLBasic internal data structures, say the pointer to a sprite image in memory?
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-Apr-12
Yes, there is:
Code (glbasic) Select
// Now access a GLBasic sprite's internal
LOCAL someid
someid = get_sprite_texture(2);
That's the internal sprite/texture id you use with glBindTexture e.g.
Title: ALHAMODE Error
Post by: bigsofty on 2007-Apr-12
Cool! Thank you... that was simple :)
Title: ALHAMODE Error
Post by: mikiex on 2007-May-02
Do you have some screenshots or examples of the problems your having? Maybe I can help
Title: ALHAMODE Error
Post by: bigsofty on 2007-May-03
I've removed the alphablending from the particles for now and concentrated on the functionality.

The problem is simple but hard to  fix.

If you make an x_sprite alphablended and do not display them (that is from back to front) in the correct Z order (usually the GFX card does this for you, but not when alphablending is on), then the usual depth sorting that OpenGL does for a scene simply gets messed up. Objects appear in front of objects, when they should be behind and in this case, blending does not work properly because the Z-buffer is messed up.
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-May-03
...you're drawing the whole scene before the particles, are you? Just the particle's themselfes are sorted incorrectly, maybe.
Like:
SetCamera()
DrawScene()
DrawParticles()
Title: ALHAMODE Error
Post by: mikiex on 2007-May-03
Quote from: bigsoftyI've removed the alphablending from the particles for now and concentrated on the functionality.

The problem is simple but hard to  fix.

If you make an x_sprite alphablended and do not display them (that is from back to front) in the correct Z order (usually the GFX card does this for you, but not when alphablending is on), then the usual depth sorting that OpenGL does for a scene simply gets messed up. Objects appear in front of objects, when they should be behind and in this case, blending does not work properly because the Z-buffer is messed up.
I understand the problem, its something game developers have lived with for a long long time,
I just might be able to show you how to minimize the artefacts
Title: ALHAMODE Error
Post by: bigsofty on 2007-May-04
Quote from: mikiex
Quote from: bigsoftyI've removed the alphablending from the particles for now and concentrated on the functionality.

The problem is simple but hard to  fix.

If you make an x_sprite alphablended and do not display them (that is from back to front) in the correct Z order (usually the GFX card does this for you, but not when alphablending is on), then the usual depth sorting that OpenGL does for a scene simply gets messed up. Objects appear in front of objects, when they should be behind and in this case, blending does not work properly because the Z-buffer is messed up.
I understand the problem, its something game developers have lived with for a long long time,
I just might be able to show you how to minimize the artefacts
Anything you can add would be appreciated Mikie ;)
Title: ALHAMODE Error
Post by: mikiex on 2007-May-04
need an example screenshot or exe to see what it looks like
Title: ALHAMODE Error
Post by: bigsofty on 2007-May-05
Outa town at the mo... will post a couple of screenies when I get back...
...hmmm, you cant attach images here... better find a host...
Title: ALHAMODE Error
Post by: Kitty Hello on 2007-May-07
Imageshack
Title: ALHAMODE Error
Post by: bigsofty on 2007-May-07
Z buffer off, Alpha on

(http://img.photobucket.com/albums/v160/tidles666/part_z_off.jpg)
http://img.photobucket.com/albums/v160/tidles666/part_z_off.jpg

Z on, Alpha on

(http://img.photobucket.com/albums/v160/tidles666/part_alpha.jpg)
http://img.photobucket.com/albums/v160/tidles666/part_alpha.jpg

Z on, No Alpha

(http://img.photobucket.com/albums/v160/tidles666/part_noblend.jpg)
http://img.photobucket.com/albums/v160/tidles666/part_noblend.jpg
Title: ALHAMODE Error
Post by: mikiex on 2007-May-16
Opps sorry I've not been about.

If your going for an glowy explosion type effect you would want to use additive blending with no Z write. If the particles are additive it doesnt matter how they sort.
Title: ALHAMODE Error
Post by: bigsofty on 2007-May-17
There all actually additive, I use my own openGL blending inline commands. Anything dependant on the the ZBuffer for blending has this problem unfortunately... this covers a LOT of the blending modes when in 3D.