Antialiasing

Blitz3D Forums/Blitz3D Beginners Area/Antialiasing

fox95871(Posted 2008) [#1]
I hate to be picky when there's so much I like about Blitz, but does anyone know a way to get rid of jaggies on the edges of meshes besides Antialias? I remember in The Sims 1 they did it perfectly, and you could turn it on or off. Has anyone ever tried to do the same thing with Blitz?


Naughty Alien(Posted 2008) [#2]
I do that with nicely set blur..


GIB3D(Posted 2008) [#3]
how would you do that?


Nate the Great(Posted 2008) [#4]
hmm... I wouldnt recommend blur... it hurts my eyes and im sure im not the only one but a nicely set blur that isnt noticable might help. How would u do blur in b3d?


Zethrax(Posted 2008) [#5]
The simplest way to reduce the edge jaggies is to increase the graphics resolution. I'd recommend that you give the user the option to select the resolution from a list of available resolutions for their system, in any case.


Gabriel(Posted 2008) [#6]
Do any of these add-on libraries for Blitz3D permit render to texture? If so, could you not render your scene to a texture which is bigger than the screen and then blit that texture to the screen? That's essentially what fullscreen anti-aliasing is doing.


Ross C(Posted 2008) [#7]
Yeah, the fastextend lib allows you to render to texture. Although, i've often though, like Bill, increasing the resolution is a better way to go if you can.


fox95871(Posted 2008) [#8]
What about doing a screen capture of each frame, isolating just the image of the mesh by unhiding a black panel that's always behind it, then before rendering the final frame, make the actual mesh alpha 0, and show the image instead, masked so the black is invisible. The last part, softening the edges, is the part I have no idea how to do. But at least it takes solving the problem out of the 3d realm, right?

If someone could - programmatically - find a way to remove just the corner pixels of the image, the jaggies, and make them alpha .5, and rest as alpha 1, I think that would work. It would have to be fake 2D so it could be alpha, like this:

(Link removed. Please see post 19.)

I have an hour on this computer, but I'm going to try to do a quick picture of what I described. Hang on...

(Link removed. Please see post 19.)


Ross C(Posted 2008) [#9]
That would probably be pain-stakingly slow. Pixel read and write operations are pretty slow, that's why most folks tend to do things on a screen basis. Like copyrect etc. It takes a while for instance (in computer time) to lock and unlock buffers, to access textures to read and write, so add that onto the execution time of the code, the time it takes to tranfer textures to and from memory etc.

Your best bet is some sort of full screen, or rectangle chunk of the screen effect.


Nate the Great(Posted 2008) [#10]
Here is some basic code to use if the object that needs blurring is small and doesnt have a complex texture :)
I know this is ridiculously pixelated but thats the point right?




Kryzon(Posted 2008) [#11]
Further reading:
http://www.eggheadcafe.com/software/aspnet/32931865/direct3d-7-antialiasing-t.aspx


Nate the Great(Posted 2008) [#12]
this code uses a function to keep the blur equal as the cube changes distances from the camera

Graphics3D 640,480,0,2
;Graphics3D 320,240,0,3
tex = CreateTexture(128,128)
SetBuffer TextureBuffer(tex)
Color 200,200,200
Rect 0,0,257,257,1
Color 0,0,255
Text 1,1, "Test Texture"
Text 1,20, "Test Texture"
Text 1,40, "Test Texture"
Text 1,80, "Test Texture"
Color 255,255,255
SetBuffer BackBuffer()

cam = CreateCamera()
MoveEntity cam, 0,0,-6

cube = CreateCube()
EntityTexture cube,tex
cube2 = CopyMesh(cube)
EntityTexture cube2,tex
cube3 = CopyMesh(cube)
EntityTexture cube2,tex
EntityParent cube2, cube
EntityParent cube3, cube
EntityAlpha cube2,.5
EntityAlpha cube3,.25
ScaleEntity cube2,1.01,1.01,1.01
ScaleEntity cube3,1.02,1.02,1.02


lit = CreateLight()
TurnEntity lit, 90,0,0

hide = True
cnt# = 0
While Not KeyDown(1)
Cls
cnt = cnt + 2
TurnEntity cube,1,1,0

PositionEntity cam,0,0,-7+ 4*Sin(cnt#/4)

If KeyHit(57) Then hide = Not hide

calcscale(cube2,cam,1)
calcscale(cube3,cam,2)

If hide = True Then
HideEntity cube3
HideEntity cube2
Else
ShowEntity cube2
ShowEntity cube3
EndIf


UpdateWorld()
RenderWorld()

Text 1,1, "PRESS THE SPACEBAR TO TOGGLE BETWEEN SHARP EDGES AND BLURRY EDGES."

If HIDE Then Text 1,20,"Sharp Edges"
If Not hide Then Text 1,20,"Blurry Edges"
Delay 20
Flip
Wend

Function calcscale(obj,camera,layer)

dist# = EntityDistance(camera,obj)
scl# = dist#/500
scl# = scl# * layer
scl# = scl# + 1

ScaleEntity obj,scl#,scl#,scl#

End Function



fox95871(Posted 2008) [#13]
Solved. Thanks Nate!

(Link removed. Please see post 19.)

I'm really excited about this. I don't know what big game companies are doing, but I bet it's very processor dependant. This has the same effect, and Blitz can easily handle a few extra meshes. I'd recommend this code to anyone. The only drawback - which you can see in the example - is that with characters, the extremities of the antialiasing meshes tend to go out too far. But that's not a problem at all I realized! All you have to do is load each moving part separately (prepared ahead of time in Maya for just that purpose) so it looks like one animated mesh, even though it's actually 16, all moving together - and each with it's own blur code! For that matter, you could ditch the code and just make the antialiasing meshes in Maya. Actually, that would work out better anyway because you could expand each part from it's own centerpoint, not the centerpoint of the mesh. I've also noticed there's a lot of room for tweaking of the antialiasing mesh's size and transparency depending on their distance from the camera. Close meshes look better with close antialiasing, and distant meshes look better with more expanded ones. You can see that's true in the above link because when the character is very far away, it's no longer the legs that look best, it's the arms. Maybe about 3 sets of antialiasing meshes depending on the distance from the camera. Anyway, I'm looking forward to working on all this. Thanks again.


fox95871(Posted 2008) [#14]
Oh, I didn't see your second post yesterday. I'll look at that tonight. That's funny it's exactly what I was talking about. I'm starting to get the feeling your idea's going to become extremely popular :)


Nate the Great(Posted 2008) [#15]
ok thanks... glad to know this helped and yeah you only need 2 or 3 meshes not 16! haha well I guess it all depends on your game but good luck with whatever you are trying to do :)


Gabriel(Posted 2008) [#16]
I'm really excited about this. I don't know what big game companies are doing, but I bet it's very processor dependant.

They're using the graphics card's inbuilt anti-aliasing, and no, it doesn't affect the CPU at all. Even on the graphics card it's much, much faster than rendering everything three times. But hey, it works and you're happy with it, and that's all that matters.


fox95871(Posted 2008) [#17]
Well, I'm just starting out, and I can understand it. I also really like how it looks. Just like a soft edge in Photoshop, but in Blitz on a mesh. Amazing. Last night I implemented EntityAutoFade to transition between the near and far antialiasing meshes, and it worked out perfectly. So just 2 sets should be fine. As for the 16 major moving parts of the body, I realized while they would need to be separated initially in Maya, that's just to expand each from it's own centerpoint before fusing them together for each animation frame. 5 meshes will be loaded into Blitz after that: The main mesh, 2 slightly larger close meshes, and 2 much larger far meshes. I don't have Maya up and running now, but I should be able to post at least a partial example tomorrow.


Nate the Great(Posted 2008) [#18]
oh ok... just dont go too out of your way for this. but as long as your happy with this effect then its fine and as gabriel said thats all that matters :)


fox95871(Posted 2008) [#19]
It's no big deal. Just what I always do.

http://www.mediafire.com/?11caw611d7ot1e7

This uses my new EntityAutoFade idea. I also decided to add a third set of antialiasing meshes afterall because in extremely distant shots the character looked like a stick figure.