Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Smooth/Antialiased Rendering of Rotated Boxes

Author
Message
ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 20th Jan 2014 18:05
Hey there,

I'm currently working on a small platformer style game. The geometry fully consists of black rectangles, which can have any size and rotation.

So far I rendered them using a 1x1 pixel sprite, which is resized to the size of the block, then rotated and finally pasted. Which works relatively fine - however, there's this old DBP problem of lack of antialiasing:



(scaled to 200% to amplify the effect)

Blocks with angle 0, 90, 180 or 270 look fine of course, but as soon as they are rotated by any other angle, it results in these unaesthetically rigged edges.

I had a somewhat similar problem a few months ago, regarding sprite rendering: http://forum.thegamecreators.com/?m=forum_view&t=204050&b=1
I solved it by using the Advanced Sprites plugin, which lets you use filters for sprite rendering to interpolate between individual pixels. (ImageKit allows that as well btw, but it doesn't let me resize images "on the fly" as it's possible with (advanced as well as usual) sprites if I am not mistaken.)

Hence I tried using that same approach for my blocks. First I used a 1x1 sized Advanced Sprite - but as it turned out, the filtering only works inside the sprite, not at its edges (in other words, the results were exactly the same since there were no pixels to interpolate between). So I created a new sprite (~1024x32 pixels, which is about the size of most blocks in the game) which was bigger and had a few transparent pixels at its sides. But it doesn't really solve the problem: if that size differs too much from the block size, I get effects like this one:



Long story short, Advanced Sprites doesn't seem to be able to solve the problem either (unless I create a new image of the exact size of a block for each newly created block - but since there are hundres of blocks in each level, that's not a viable option).

So.. what possible options have I left? How can I draw antialiased rotated rectangles? (Possible even with float coordinates to avoid blocks "jumping" between pixels when the camera moves very slowly)

I already considered writing a pixel shader that I would use with the appropriate Image Kit commands which renders an antialiased rectangle to the screen. I assume that would work, but it would probably be slower than any "sane" method of rendering rectangles and generally quite an overkill.

Alternatively I thought of using Advanced 2Ds commands for antialiased line drawing and add 4 antialiased lines to the edges of each block - which would again be relatively slow since I'd have to draw 5 things for each block, but I could live with that - however, as we found out here, A2Ds antialiasing doesn't seem to work with AMD graphics cards. So not an option either.

Ideas? Anyone?

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 20th Jan 2014 18:48
Well, new plan: I use Advanced Sprites now to do what I previously considered to do with Advanced2D, and simply draw the 4 edges individuall on top of the "non-antialiased" DBPro-rectangle. So now I use a 1024x3 pixel sized image, with transparent top and bottom row of pixels and black in the middle, change it's width depending on how long the line is and keep the height the same, which allows me to draw nice (and consistent) antialiased lines.



And now, please tell me there's an easier solution to this. This is such a horrible workaround, I probably won't be able to sleep again until I've found an alternative..

Blobby 101
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 20th Jan 2014 19:14
I'm not too familiar with Advanced 2D/Sprites or Image Kit, but I imagine at least one of them must support scaling like bilinear or bicubic filtering? Basically just anything but nearest-neighbor?

If so, you could draw your sprites and everything to an off-screen bitmap (at 2x resolution), and then paste that to the screen. Basically how actual MSAA works.

I'm not an expert by all means though, so I don't know how well this'll perform, but when I used to use DBP I seem to remember the paste sprite command being very efficient - hope this helps!

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 21st Jan 2014 01:01
Yes, that's actually a pretty great idea. However, it doesn't seem to work out in DBP, unless I'm doing something fundamentally wrong. It seems that big render targets (especially > than the desktop) slow down games immensely. I tried multiple ways, including "draw to image" (Matrix Utils), "ik paste image on image" (Image Kit), the strange built in "set current bitmap -1" solution of DBPro and probably more, but each of them resultet in heavy frame rate drops. And while 2x AA (screen width*2 x screen height*2) is maybe an option (if you accept the FPS reducing by more than 50% for the relatively subtle effect 2x AA has), using 4x4 times the resolution, which would increase the visual quality of the effect quite a bit in comparison to 2x2, doesn't seem to be viable at all.

Again, I might just have made some kind of mistake. There surely must be some way to do what you described, I just don't know how. But I wish I did, so if anybody has working code to do that... please post it.

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 23rd Jan 2014 14:38 Edited at: 23rd Jan 2014 14:59
Example code trying this technique:



(Requires Matrix1 Utils and Image Kit)

I get around 2000 FPS with no AA, 1200 FPS with 2x and 350 FPS with 4x AA.
However, the question remains whether the performance reduction is absolute (i.e. it's caused mainly by drawing the interpolated, downscaled huge render targets to the screen) or relative to everything you render (i.e. drawing sprites etc. to the huge render target needs longer than rendering them to the screen). I guess that needs further testing.

Edit: Neither apparently. The speed difference is not in the sprite drawing in my code, nor in interpolated downscaling of the render targets - it's the sync command that makes the difference, and which needs way more time when 4xAA is activated. Not sure why exactly, but I'm sure it makes sense.

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Jan 2014 16:56
I imagine you could do the AA through a shader instead for added performance.

"Get in the Van!" - Van B
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Jan 2014 20:21
Increase the resolution of your game. More pixels = smoother appearing edges.

ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 23rd Jan 2014 21:08
Quote: "Increase the resolution of your game. More pixels = smoother appearing edges"


Still, the resolution is limited by the screen you're using, hence the need for AA. My monitor (just as many others) can't handle anything above 1920x1200, and on that resolution you still see the individual pixels well enough to realize the lack of antialiasing.



@Sasuke:
Quote: "I imagine you could do the AA through a shader instead for added performance."


Could you go a little more into detail? A shader to render individual rectangles? A shader to render antialiased images in general? Or what exactly do you mean?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Jan 2014 22:53 Edited at: 24th Jan 2014 23:33
Doesn't the set display mode command support antialiasing in the final flag? It's been a while since I tried that so perhaps there's a problem I've forgotten about?

Edit Just done a quick test - and yes there seems to be a problem. The following simple demo (using a 1x1 black image) doesn't use antialiasing whereas I guess it should since my GFX card is set to for "Application controlled". I could only get AA by setting it explicitly in the GFX card control panel. When you run the demo just press "r" to rotate the sprite (and <space> to exit).



Edit2: removed a redundant commented line.



Powered by Free Banners
ShellfishGames
12
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 25th Jan 2014 08:48 Edited at: 25th Jan 2014 08:52
Quote: "Edit Just done a quick test - and yes there seems to be a problem. "


Indeed. I remember messing around with it in the past, and while it seemed to kind of work for 3D scenes (as far as I remember that is), it didn't have any effect on sprites or other 2D commands unfortunately.

What can't things just be easy?


Edit:

Your example code with 3D:



Only seems to work with multisampling values of 2, 4 and 8 though, (and they even all seem to look identical from what I can tell).

GregA
13
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 25th Jan 2014 19:46
Woah! Thanks for this thread. So much to learn about the DBP command set.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jan 2014 21:59
Quote: "and while it seemed to kind of work for 3D scenes (as far as I remember that is), it didn't have any effect on sprites or other 2D commands unfortunately."


Yes, I wondered whether I ought to check that as well. I'll try your code later as this laptop is supposed to support up to 16 samples.

Quote: "Only seems to work with multisampling values of 2, 4 and 8 though, (and they even all seem to look identical from what I can tell)."


Does your GFX card support all those modes? (I vaguely recall seeing similar problems myself a while back now you mention it. Yet another thing to check. )



Powered by Free Banners
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 25th Jan 2014 23:30
I believe the AA flag only works when you set window off if I remember correctly.

Login to post a reply

Server time is: 2025-05-15 23:01:33
Your offset time is: 2025-05-15 23:01:33