Sprite3D functions to accept floats

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Sprite3D functions to accept floats

Post by STARGÅTE »

Fred wrote:ps: on my screen it looks a bit wierd, like a bit of intensity change when being between pixels (I guess it's GFX card interpolations to emulate this)
This is the SpriteQuality(#PB_Sprite_BilinearFiltering), so there is a linear fitting between two texture pixels.
Bilinear means, a white sub-pixel and a black sub-pixel gets a gray full pixel (intensity change)
If you change it to #PB_Sprite_NoFiltering, you can't see this fitting.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Sprite3D functions to accept floats

Post by luis »

Fred wrote: ps: on my screen it looks a bit wierd, like a bit of intensity change when being between pixels (I guess it's GFX card interpolations to emulate this)
It's due to the bilinear filtering. Just change SpriteQuality to #PB_Sprite_NoFiltering and this does not work anymore.
In fact it's not the same image drawn when using subpixel movement, or it would not be possible to move something composed by pixels by less than a pixel when the physical screen resolution is a pixel. The filtering change the pixels colors and give a simil-antialiased illusion of smaller movements and cause the weird effect you are seeing.

Also, if you change the sprite to this one:

Code: Select all

StartDrawing(SpriteOutput(#Sprite))
   Box(0, 0, 32, 32, $FF0000) 
StopDrawing()
does not work even with the filtering active.

EDIT: Well, too late :)
"Have you tried turning it off and on again ?"
A little PureBasic review
skape
User
User
Posts: 17
Joined: Mon Nov 18, 2013 7:24 am

Re: Sprite3D functions to accept floats

Post by skape »

@STARGÅTE, yep, exactly what I'm asking about. I thought that enabling bilinear filtering would do it for DisplaySprite(), but thanks for the TransformSprite() tip. :)

Too bad using RotateSprite() or ZoomSprite(), etc. resets the previous matrix transformations..

@Fred, yeah, I know you can send a float and it will round to the nearest pixel, but IMO this looks worse for certain sprites (not all), than interpolating. The GFX card is basically changing the alpha of image pixels depending on "how much" they are in a physical pixel, so it actually looks good with sprites that already have an antialiased edge to them. (The GFX card is already essentially doing this when transforming image pixels to other resolutions than native.)


EDIT:
It also helps movement appear smoother at fast speeds:

With this image: Image

Code: Select all

InitSprite()

UsePNGImageDecoder()

Enumeration
   #Window
   #Sprite
EndEnumeration

OpenWindow(#Window, 0, 0, 300, 300, "Sprite", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)
SpriteQuality(#PB_Sprite_BilinearFiltering)

;CreateSprite(#Sprite, 32, 32)
; StartDrawing(SpriteOutput(#Sprite))
;    Box(10, 1, 2, 30, $FF8080)
;    Box(16, 1, 2, 30, $80FF80)
;    Box(22, 1, 2, 30, $8080FF)
;    Line(1, 16, 30, 1, $FFFFFF)
;    StopDrawing()
   
   LoadSprite(#Sprite, "circle.png", #PB_Sprite_AlphaBlending)

Define Start = ElapsedMilliseconds()
Define X.f
Define delta.f

Repeat
   
   Repeat
      
      Select WindowEvent()
         Case #PB_Event_CloseWindow
            End
         Case #Null
            Break
      EndSelect
      
    ForEver
    
    delta = (ElapsedMilliseconds() - Start)/1000
    Start = ElapsedMilliseconds()
   
   ClearScreen($FFFFFF)
   
   X = X+9*delta
   
   ZoomSprite(#Sprite, 32, 32)
   DisplayTransparentSprite(#Sprite, X, X)
   
   TransformSprite(#Sprite, X, X+50, X+SpriteWidth(#Sprite), X+50, X+SpriteWidth(#Sprite), X+50+SpriteHeight(#Sprite), X, X+50+SpriteHeight(#Sprite))
   DisplayTransparentSprite(#Sprite, 0, 0)
   
   FlipBuffers()
   
 ForEver
 
 
 
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Sprite3D functions to accept floats

Post by Fred »

Ok, now it makes more sens ! Thanks
Post Reply