Pixel exact collision brush to brush

Discuss any general programming issues here
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Pixel exact collision brush to brush

Post by fingus »

Maybe this is a limitation of using RebelSDL, it would be a nice feature if #BRUSH-to-#BRUSH Collision can handle it pixel exact (on visible alpha-pixels for example).

Or this is a Limitation of Hollywood 9.1 (Linux). I didn't find informations in the readme of the Hollywood 10-Release, that this feature was improved/added.
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Pixel exact collision brush to brush

Post by fingus »

Add: With RebelSDL-Plugin 1.1
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Pixel exact collision brush to brush

Post by airsoftsoftwair »

Hmm, the Collision() function should support pixel-exact collision detection?! What exactly isn't working for you?
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Pixel exact collision brush to brush

Post by fingus »

Imagine a sidescroller like R-Type.
I use a giant wide-brush as prerendered game-level. The level has graphics on top and bottom and in between it is full alpha transparent.
When i put my player brush on it the #brush-collision gives me always true back, even if i don't touch the visible areas of the level (top and bottom).

An other example is, when an object touch the invisible alpha-border of another brush, collision is true immediately.

So in my case the collision will be true if at least one pixel (visible or not) of each BRUSH-BOX is overlapping.

Maybe this is a limitation of Hardware-Brushes in combination with DoubleBuffering and RebelSDL on Linux?
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Pixel exact collision brush to brush

Post by fingus »

@Andreas:

I send you an example (code + images).
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Pixel exact collision brush to brush

Post by airsoftsoftwair »

fingus wrote: Thu Sep 14, 2023 12:48 pm Maybe this is a limitation of Hardware-Brushes in combination with DoubleBuffering and RebelSDL on Linux?
Yes, it's a limitation of hardware brushes, not only on Linux but in general. For hardware brushes collision detection is never pixel exact because that would require reading from the hardware brush but that isn't easily possible because it's in GPU memory and reading from GPU memory is only possible with significant overhead. AmigaOS will also freeze the mouse pointer when reading from video memory but also on other platforms reading from VRAM is a real performance killer.

To work around this limitation you could use hardware brushes for drawing and software copies of the hardware brushes for collision detection. For software brushes collision detection will always be pixel-perfect. I'll add a note in the Collision() documentation that informs the user that hardware brushes don't support pixel-perfect collision detection.
User avatar
Tuxedo
Posts: 351
Joined: Sun Feb 14, 2010 12:41 pm

Re: Pixel exact collision brush to brush

Post by Tuxedo »

airsoftsoftwair wrote: Sun Sep 24, 2023 12:54 pm
Yes, it's a limitation of hardware brushes, not only on Linux but in general. For hardware brushes collision detection is never pixel exact because that would require reading from the hardware brush but that isn't easily possible because it's in GPU memory and reading from GPU memory is only possible with significant overhead. AmigaOS will also freeze the mouse pointer when reading from video memory but also on other platforms reading from VRAM is a real performance killer.

To work around this limitation you could use hardware brushes for drawing and software copies of the hardware brushes for collision detection. For software brushes collision detection will always be pixel-perfect. I'll add a note in the Collision() documentation that informs the user that hardware brushes don't support pixel-perfect collision detection.
Hum...stupid question...but that method dont double the memory usage since you have to load an hardware copy and a non hardware copy of the same brush?
Simone"Tuxedo"Monsignori, Perugia, ITALY.
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Pixel exact collision brush to brush

Post by fingus »

Tuxedo wrote: Tue Sep 26, 2023 11:39 pm
airsoftsoftwair wrote: Sun Sep 24, 2023 12:54 pm
Yes, it's a limitation of hardware brushes, not only on Linux but in general. For hardware brushes collision detection is never pixel exact because that would require reading from the hardware brush but that isn't easily possible because it's in GPU memory and reading from GPU memory is only possible with significant overhead. AmigaOS will also freeze the mouse pointer when reading from video memory but also on other platforms reading from VRAM is a real performance killer.

To work around this limitation you could use hardware brushes for drawing and software copies of the hardware brushes for collision detection. For software brushes collision detection will always be pixel-perfect. I'll add a note in the Collision() documentation that informs the user that hardware brushes don't support pixel-perfect collision detection.
Hum...stupid question...but that method dont double the memory usage since you have to load an hardware copy and a non hardware copy of the same brush?
Yes is does, at least for all bitmaps that need pixel-exact collision. Normally only the Playfield and the small Player-/Enemy-/Bullet-Sprites which doesn't represent the majority of RAM-allocation in my game-project. There are also other big bitmaps like parallax-layer, background-/foreground-layer which didn´t need collision at all. So in times of Gigabytes of RAM/VRAM i can life with it.
Last edited by fingus on Wed Sep 27, 2023 10:28 am, edited 3 times in total.
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: Pixel exact collision brush to brush

Post by fingus »

airsoftsoftwair wrote: Sun Sep 24, 2023 12:54 pm
fingus wrote: Thu Sep 14, 2023 12:48 pm Maybe this is a limitation of Hardware-Brushes in combination with DoubleBuffering and RebelSDL on Linux?
Yes, it's a limitation of hardware brushes, not only on Linux but in general. For hardware brushes collision detection is never pixel exact because that would require reading from the hardware brush but that isn't easily possible because it's in GPU memory and reading from GPU memory is only possible with significant overhead. AmigaOS will also freeze the mouse pointer when reading from video memory but also on other platforms reading from VRAM is a real performance killer.

To work around this limitation you could use hardware brushes for drawing and software copies of the hardware brushes for collision detection. For software brushes collision detection will always be pixel-perfect. I'll add a note in the Collision() documentation that informs the user that hardware brushes don't support pixel-perfect collision detection.
Thank you for the hint, it does work, so i'm not forced to use an own collision-function which saves me a lot of work, thank you!
User avatar
Tuxedo
Posts: 351
Joined: Sun Feb 14, 2010 12:41 pm

Re: Pixel exact collision brush to brush

Post by Tuxedo »

fingus wrote: Wed Sep 27, 2023 10:23 am
Yes is does, at least for all bitmaps that need pixel-exact collision. Normally only the Playfield and the small Player-/Enemy-/Bullet-Sprites which doesn't represent the majority of RAM-allocation in my game-project. There are also other big bitmaps like parallax-layer, background-/foreground-layer which didn´t need collision at all. So in times of Gigabytes of RAM/VRAM i can life with it.
Yes I think same of you, but my Amiga-optimizer heart was still herer :)
Simone"Tuxedo"Monsignori, Perugia, ITALY.
Post Reply