Sprite Compatibility - workaround?

Blitz3D Forums/Blitz3D Programming/Sprite Compatibility - workaround?

jfk EO-11110(Posted 2010) [#1]
Hi everybody. Since Sprites seem to make more and more problems, I wonder if there is a workaround, using a quad. I haven't got a problem in createing a Quad. What I need is the maths to rotate the Quad in order to have it always faceing to the camera like a Sprite in default mode. The CreateSprite and LoadSprite Functions will then be replaced by a quadbased substitute, and in the main loop there's a UpdateSpriteFix function call that will rotate the sprites accordingly. I just remember I tried this once but failed with the maths, my Quads were distoreted somehow. Any Ideas oder Code?


Yue(Posted 2010) [#2]
Hello sprites problem I have solved with the flags.

Sprite = loadsprite ("f.png ", 1+2)


Krischan(Posted 2010) [#3]
Take a look at my Spiral Galaxy - it is using a lot of quads always facing to the camera. But you can't rotate them in another angle - only ALWAYS to the cam (using a "trick": 2x Tformvector and just realign the vertices). And it should be faster than sprites, too.

EDIT: here is a quick and dirty one showing the algorithm "standalone"



Last edited 2010


xlsior(Posted 2010) [#4]
Didn't the latest 1.106 B3D update address the sprite problems?


jfk EO-11110(Posted 2010) [#5]
Not on my Machine. I get some kind of fancy rubberband fx with sprites that are parented to the camera (rubberband connected to the map...)

Yue: this is not what I am talking about. The Alpha Bug is a general bug and affects all textures, not only Loadsprite. IMO it has something to do with DirectX.

Krischan, thanks a lot. This might work, but what I was searching for, was a full substitute with Function Overriding. Well, I used to write something, it seems to work nicely.

(note: in the orig code there were some bugs, see updated version here:)
http://www.blitzbasic.com/codearcs/codearcs.php?code=2786

Last edited 2010


Ross C(Posted 2010) [#6]
Create all your quads facing the camera.
Parent the mesh/surface entity to the camera.
Then simply position the vertices where you need them.

No need to worry about rotating the quads to face the camera ;)


jfk EO-11110(Posted 2010) [#7]
Repeated update of vertices isn't really what I wanted, although it might be a further option, thanks.

The way it is right now (see source) is nice. It was so easy, I'm still not sure if this is really correct. Let me know when you see some logical errors in it.

Last edited 2010


Ross C(Posted 2010) [#8]
Are you using a single surface system? I only pointed that option out for use with a single surface system :)


jfk EO-11110(Posted 2010) [#9]
No, my Approach was a set of commands with the same names as the original sprite functions, that will replace the existing sprites commands using quads. Especially for huge programs that you don't want to revisit line after line, to replace Sprites with eg. a singlesurface system.

What seems to be really slow with sprites/quads in moderate Particle systems and FX (eg. a few dozen of them onscreen) is not the surface count, but the number of alpha layers and their size on screen. 5 Sprites or Quads, all alphablended, all covering the entire screen will slow down things seriously. OF course, when you want thousands of particles then it's a nono not to use a singlesurface system.

BTW In my original code were some bugs, I corrected most of them (see code archives).


Ross C(Posted 2010) [#10]
Ah right. No worries. Yeah, alpha blending seems to be very slow, with that many sprites. Dunno if blitz is doing something different, or newer engines are optimsed in some way, or newer versions of direct x are?


Matty(Posted 2010) [#11]
So how does your system fare with multiple cameras - since you cannot have more than 1 parent to an entity.


jfk EO-11110(Posted 2010) [#12]
I don't understand the question. You have to call UpdateSubstSprites(camera) in your main loop to make sure "Sprites" are facing to the camera. With the native Sprite commands this is done automaticly with the currently rendering camera. If you have multiple camera perspectives on one screen, then you maybe have to Renderworld them one by one, with an initial UpdateSubstSprites(camera) with the corresponding camera. This, I agree, may be a little bit uncomfortable. Then again, I never have multiple cameras on a screen, except maybe for some advanced behind-the curtain stuff like 3*2 Cubemapprendering.

It is s quick hack, agreed. It should work in simple situations. Thare are still some incompatibilities, also because the EntityClass$ of the Sprite is now "Mesh". When parented to other meshes, problems may arise, eg. with CopyEntity (that will create a copy of the child sprite as well, but that one will be out of control of UpdateSubstSprites(camera) and ReleaseSprite), see comments in code archives.
I however managed to completely wipe out any native Sprite usage in the CSP FPS engine. Maybe it's only me, but I felt like it was getting a bit faster too. :°)


Ross C(Posted 2010) [#13]
I think he may be refering to the system I mentioned? If so, then I dunno. I've never tried it, or tried to work around it :)


jfk EO-11110(Posted 2010) [#14]
Oh, I see.