Halo's antialias. I think it's more for static-image antialiasing rather than in-game, maybe for a render preview in a 3d modeller like.. ooh say.. Cartography Shop?
Function AntiAliasBuffer(buffer,passes=1,threshhold=20)
gfxbuffer=GraphicsBuffer()
SetBuffer buffer
LockBuffer buffer
w=BufferWidth(buffer)
h=BufferHeight(buffer)
For p=1 To passes
For x=0 To w-1
For y=0 To h-1
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
count=BottomLeftPixelsAntialiased(buffer,x,y,threshhold)
For n=1 To count
perc#=Float(n)/Float(count)
hue=ReadPixelFast(x-n,y)
lr=Red(hue)*perc+r*(1.0-perc)
lg=Green(hue)*perc+g*(1.0-perc)
lb=Blue(hue)*perc+b*(1.0-perc)
WritePixelFast x-n,y,RGB(lr,lg,lb)
Next
count=BottomRightPixelsAntialiased(buffer,x,y,threshhold)
For n=1 To count
perc#=Float(n)/Float(count)
hue=ReadPixelFast(x+n,y)
lr=Red(hue)*perc+r*(1.0-perc)
lg=Green(hue)*perc+g*(1.0-perc)
lb=Blue(hue)*perc+b*(1.0-perc)
WritePixelFast x+n,y,RGB(lr,lg,lb)
Next
count=VerticalBottomLeftPixelsAntialiased(buffer,x,y,threshhold)
For n=1 To count
perc#=Float(n)/Float(count)
hue=ReadPixelFast(x,y-n)
lr=Red(hue)*perc+r*(1.0-perc)
lg=Green(hue)*perc+g*(1.0-perc)
lb=Blue(hue)*perc+b*(1.0-perc)
WritePixelFast x,y-n,RGB(lr,lg,lb)
Next
count=VerticalBottomRightPixelsAntialiased(buffer,x,y,threshhold)
For n=1 To count
perc#=Float(n)/Float(count)
hue=ReadPixelFast(x,y+n)
lr=Red(hue)*perc+r*(1.0-perc)
lg=Green(hue)*perc+g*(1.0-perc)
lb=Blue(hue)*perc+b*(1.0-perc)
WritePixelFast x,y+n,RGB(lr,lg,lb)
Next
Next
Next
Next
UnlockBuffer buffer
SetBuffer gfxbuffer
End Function
Function BottomLeftPixelsAntialiased(buffer,x,y,threshhold)
If x=0 Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
w=BufferWidth(buffer)
h=BufferHeight(buffer)
Repeat
found=False
hue=ReadPixelFast(x-1,y)
lr=Red(hue)
lg=Green(hue)
lb=Blue(hue)
If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
If y<h
hue=ReadPixelFast(x-1,y+1)
blr=Red(hue)
blg=Green(hue)
blb=Blue(hue)
If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
found=True
EndIf
EndIf
EndIf
If found
count=count+1
Else
Exit
EndIf
If x=0 Exit
x=x-1
Forever
Return count
End Function
Function BottomRightPixelsAntialiased(buffer,x,y,threshhold)
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
w=BufferWidth(buffer)
h=BufferHeight(buffer)
If x=w Return
Repeat
found=False
hue=ReadPixelFast(x+1,y)
lr=Red(hue)
lg=Green(hue)
lb=Blue(hue)
If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
If y<h
hue=ReadPixelFast(x+1,y+1)
blr=Red(hue)
blg=Green(hue)
blb=Blue(hue)
If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
found=True
EndIf
EndIf
EndIf
If found
count=count+1
Else
Exit
EndIf
If x=w-1 Exit
x=x+1
Forever
Return count
End Function
Function VerticalBottomLeftPixelsAntialiased(buffer,x,y,threshhold)
If y=0 Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
w=BufferWidth(buffer)
h=BufferHeight(buffer)
Repeat
found=False
hue=ReadPixelFast(x,y-1)
lr=Red(hue)
lg=Green(hue)
lb=Blue(hue)
If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
If x>0
hue=ReadPixelFast(x-1,y-1)
blr=Red(hue)
blg=Green(hue)
blb=Blue(hue)
If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
found=True
EndIf
EndIf
EndIf
If found
count=count+1
Else
Exit
EndIf
If y=0 Exit
y=y-1
Forever
Return count
End Function
Function VerticalBottomRightPixelsAntialiased(buffer,x,y,threshhold)
If y=h Return
hue=ReadPixelFast(x,y)
r=Red(hue)
g=Green(hue)
b=Blue(hue)
w=BufferWidth(buffer)
h=BufferHeight(buffer)
Repeat
found=False
hue=ReadPixelFast(x,y+1)
lr=Red(hue)
lg=Green(hue)
lb=Blue(hue)
If Abs(lr-r)>threshhold Or Abs(lg-g)>threshhold Or Abs(lb-b)>threshhold
If x>0
hue=ReadPixelFast(x-1,y+1)
blr=Red(hue)
blg=Green(hue)
blb=Blue(hue)
If Abs(blr-r)<threshhold And Abs(blg-g)<threshhold And Abs(blb-b)<threshhold
found=True
EndIf
EndIf
EndIf
If found
count=count+1
Else
Exit
EndIf
If y=h Exit
y=y+1
Forever
Return count
End Function
+BlackD