Page 2 of 2

Re: Sprite3D functions to accept floats

Posted: Mon Nov 18, 2013 2:51 pm
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.

Re: Sprite3D functions to accept floats

Posted: Mon Nov 18, 2013 3:00 pm
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 :)

Re: Sprite3D functions to accept floats

Posted: Mon Nov 18, 2013 3:39 pm
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
 
 
 

Re: Sprite3D functions to accept floats

Posted: Mon Nov 18, 2013 5:09 pm
by Fred
Ok, now it makes more sens ! Thanks