Sprite3D() - Improvements / Questions

Advanced game related topics
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Sprite3D() - Improvements / Questions

Post by syntax error »

From writing a set of sprite commands/functions for Blitz3D I have been looking over the PB's Sprite3D lib and have some questions, improvements, and ideas etc ...

Are the 3d sprites which share one 2D sprite single-surface?
That is, if I do:

Code: Select all

For s=1 to 50
 CreateSprite3D(s, #mysprite)
Next
Will the 50 sprites belong to 1 surface?
Under Blitz it turns out that single-surface sprites are significantly faster than separate-surface ones.

How about adding commands/functions like:

Code: Select all

FlipSprite3D(#mysprite,Horizontally,Vertically)
I assume the 3D sprites use internal UV coordinates for the texture. If so then it's just a matter of swapping these around to make the texture appear flipped.

Code: Select all

SpritesOverlap3D(#sprite1,#sprite2)
Return TRUE if 2 sprites are overlapping.
In my lib I have a routine to check if each vertex in one sprite is 'inside' the vertices of the other sprite (and vice-versa).
It works on rotated/flipped sprites as well.

Code: Select all

SpriteColor3D(#mysprite,r,g,b)
Manipulate the vertex colors of the 3d sprite

Code: Select all

ChangeSpriteUVCoord3D(#mysprite,vert,u,v)
vert = vertext number (1 to 4)
u/v = new texture coordinate of vertex

Could be used to change image on the fly by setting the texture coordinates to point at a different region in the texture.

I have 2 speed tests here for you guys to try out if you wish.
One in Blitz3D and the other in PB.
Not really a fair comparision though. Both use different techniques to render the balloons.

Image
Download HERE

What are your thoughts on the above proposed commands/functions?
Last edited by syntax error on Sat May 08, 2004 5:16 pm, edited 2 times in total.
fweil
Enthusiast
Enthusiast
Posts: 725
Joined: Thu Apr 22, 2004 5:56 pm
Location: France
Contact:

Post by fweil »

Well,

First part of the test is at least the size of executables !

Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

Yes. Can't take that away from PB. Exe sizes are fantastically small.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The proposed commands are interresting, I will see how to implement them.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Just one word :

You shouldn't use texture with this size 95x128 ( your balloon.bmp size )
because on some graphic cards like mine ( ATI ) it doesn't work... nothing on the screen...

But by resizing your bmp to 128x128 it's OK.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

You shouldn't use texture with this size 95x128 ( your balloon.bmp size )
You're right. I could have sworn I resized the balloon before putting it in the zip (64x128).

How I handled odd-sized textures previously was to load the image and pad it out to the nearest power of 2 then set the UV coords to the image only (ignoring the padded border).
The proposed commands are interresting, I will see how to implement them
Nice one Fred. As I mentioned before, single-surface sprites are significantly faster than separate suface ones.
The demo above (Blitz version) uses a single surface and all the balloons are quads using the same surface.

From my image packer tool I have a set of functions to extract individual images/sprites/textures.
Something like this:

Code: Select all

pack1=LoadPack("mypack.png")
sprite1=GetPackedSprite("balloon",pack1)
tex=GetPackedTexture("brick",pack1)
image=GetPackedImage("runner",pack1)
All sprites grabbed from the pack share the surface/texture.
Here is an example texture pack below. The Image Packer saves a definitions file which details what images are stored and where. Complete with animation and border settings.
Borders are something to be aware of though. Images in a texture living next door to each other may have there edges bleed with each other.
More notable if you rotate a quad.

Again, as mentioned above, another advantage is for animating the 3d sprites. The runner in the pack below uses one quad. Since the frames are spaced out evenly I can just shift the UV coords to get the required frame to show up in the quad.

Example pack (halved in size to save space):
Image

Lots to think about Fred !!
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

yes, interesting ideas :)
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Code: Select all

SpriteColor3D(#mysprite,r,g,b)
could be very useful, but if we had the chance to modify the color of the four single corners, thanks to the hardware gourad-shading much more nice effects could be added.
Give the same color to the four corners to have a solid color.

And don't forget that with R G B there is a fouth channel: A (for alpha!)

8)
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

Post by scurrier »

i tried the speed test and i got
PB 176FPS
Blitz 144FPS

Sean
scurrier
Enthusiast
Enthusiast
Posts: 169
Joined: Sat May 03, 2003 4:10 am

Post by scurrier »

sorry i just noticed that blitz starts out with 250 sprited and PB 100

i would like to see the sorce code if posible
i wrote a screensaver in PB with 20,000 sprites and has better framerate than that.

but you have a good idea and maybe Fred can impliment it or maybe you could help Fred seeing how he is very busy.

Sean
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

PureBasic Source code to speedtest demo above:

Code: Select all

; Sprite3D - speed test

#windowed=#FALSE    ; TRUE=windowed FALSE=full screen

#sw=640             ; screen width
#sh=480             ; screen height
#sd=32              ; screen depth
#numsprites=100     ; start with this amount of sprites

#win=0
#sprite2d=1

Structure spritetype
  s.l
  x.w
  y.w
  alpha.w
EndStructure
NewList sprite.spritetype()


If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Requires DirectX 7 Or later", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Direct3D not initialized", 0)
  End
EndIf

If #windowed=#TRUE

  If OpenWindow(#win,50,100,#sw+8,#sh+8,#PB_Window_TitleBar,"Sprite Test")
    If OpenWindowedScreen(WindowID(#win),4,4,#sw, #sh, 0, 0,0)=0
      MessageRequester("Error", "Unable to open windowed screen", 0)
      End
    EndIf
  EndIf
Else
    If OpenScreen(#sw,#sh,#sd,"Sprite Test")=0
      MessageRequester("Error", "Unable to open Screen", 0)
      End
    EndIf
EndIf


LoadSprite(#sprite2d, "balloon.bmp", #PB_Sprite_Texture)


For num=1 To #numsprites
 Gosub addsprite
Next

quit.b=#FALSE
sync.b=1

;- mainloop
Repeat

  If #windowed : ev=WindowEvent() : EndIf
  
  FlipBuffers(sync)
  ClearScreen(100,180,240)

  ExamineKeyboard()
  sync=1
  If KeyboardPushed(#PB_Key_Space) : sync=0 : EndIf
  If KeyboardPushed(#PB_Key_Escape) : quit=#TRUE : EndIf

  ; ADD SPRITES
  count+1
  If (count % 4) =0
    If KeyboardPushed(#PB_Key_Return)
      Gosub addsprite
    EndIf

    ; REMOVE SPRITES
    If KeyboardPushed(#PB_Key_Back)
      If CountList(sprite())>0
        LastElement(sprite())
        DeleteElement(sprite())
      EndIf
    EndIf
  EndIf
  
  ; UPDATE SPRITES
  If Start3D()
    ForEach sprite()
      sprite()\y+4
      If sprite()\y>#sh+60 : sprite()\y=-40 : EndIf
      RotateSprite3D(sprite()\s,4,1)
      DisplaySprite3D(sprite()\s,sprite()\x,sprite()\y,sprite()\alpha)
    Next
    Stop3D()
   EndIf
   
   ; fps
   If GetTickCount_()>oldtime
    oldtime=GetTickCount_()+1000
    fps=framecount : framecount=0
   Else
    framecount+1
   EndIf
   
  If StartDrawing(ScreenOutput())
    DrawingMode(3)
    FrontColor($ff,$ff,$ff)
    Locate(10,10) : DrawText("FPS:"+Str(fps))
    Locate(20,50) : DrawText("[RETURN] = Add sprites")
    Locate(20,70) : DrawText("[BACKSPACE] = Remove sprites")
    Locate(#sw/3,#sh-60) : DrawText("Hold SPACE to turn off frame sync")
    Locate(10,#sh-32) : DrawText("Total 3D sprites="+Str(CountList(sprite())))
    StopDrawing()
  EndIf
    
Until quit=#TRUE    

End
    
addsprite:
 AddElement(sprite())
 sprite()\s=CreateSprite3D(#PB_ANY,#sprite2d)
 sprite()\x=10+(Random(#sw)-20)
 sprite()\y=10+(Random(#sh)-20)
 sprite()\alpha=Random(255)
 ZoomSprite3D(sprite()\s,20+Random(60),20+Random(60))
 RotateSprite3D(sprite()\s,Random(360),1)
Return
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

@syntax error:
Half year ago i wrote some functions for the stuff you request here:
TransformSprite3D.zip (78k)

The functions you want are:
- SetSprite3DColor()
- SetSprite3DSpecular()
- SetSprite3DTextureCoordinates()

The texture flipping can be done with the last command.
Fred wrote:The proposed commands are interresting, I will see how to implement them.
Feel free to use my procedures as a base... only few lines of code,
so you can implement this new commands in 5 minutes.

I think you knew this procedures... maybe you only forgot about it. ;)
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
syntax error
User
User
Posts: 93
Joined: Tue Jan 13, 2004 5:11 am
Location: Midlands , UK

Post by syntax error »

Danilo,
Cool stuff indeed. Way beyond me but I've got the basics.

For some reason no image shows in the *.pb code although the exe works fine.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Post by Danilo »

@syntax error:
Its half a year old, maybe it doesnt compile with newest PB-Version
anymore or something has changed.

Just grab the 3 procedures and use it for your own games/demos/whatever...
cya,
...Danilo
...:-=< http://codedan.net/work >=-:...
-= FaceBook.com/DaniloKrahn =-
newart
User
User
Posts: 34
Joined: Sat Feb 12, 2005 1:59 am
Location: Russia, SPb

Post by newart »

Witch 50 fps (stabbility)

Blitz - 290 sprites
Pure - 65 sprites :(

geforce2 mx 400, 32mb,
cpu 1.4gg
Post Reply