Fake Edge Shader

Blitz3D Forums/Blitz3D Programming/Fake Edge Shader

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Almost the same with sphere mapping instead, so you haven't got the negative light affecting other stuff:
Graphics3D(800,600,0,2)
SetBuffer(BackBuffer())

bug2 = CreateCylinder(32)
tex = CreateTexture(256,256,1+64)
MakeGradMap(tex)
EntityTexture bug2,tex
EntityFX bug2,1
PositionEntity bug2,2,0,0

cam=CreateCamera()
lig=CreateLight(1,cam)

MoveEntity(cam,0,0,-10)
CameraZoom(cam,2)

Repeat
	TurnEntity(bug2,0.5,0.5,0)
	
	UpdateWorld()
	RenderWorld()

	Flip()

Until KeyDown(1)
End

Function MakeGradMap(tex,a#=0.3,b#=0.8)

	If a<0 		Then a = 0
	If a>0.99	Then a = 0.99

	If b=0.0	Then b = 1.0

	cx = TextureWidth(tex)/2
	cy = TextureHeight(tex)/2

	div# = Sqr(cx*cx + cy*cy)

	For x = 0 To TextureWidth(tex)-1
		For y = 0 To TextureHeight(tex)-1
			g# = Sqr(Float(x-cx)*Float(x-cx) + Float(y-cy)*Float(y-cy))/div
			g = (g-a)/(1.0-a)
			g = g^b
			red = (g*255)-128
			grn = (g*255)
			blu = (g*255)-192
			If red<0 Then red=0
			If grn<0 Then grn=0
			If blu<0 Then blu=0
			If red>255 Then red=255
			If grn>255 Then grn=255
			If blu>255 Then blu=255
			WritePixel x,y,blu + grn*256 + red*65536,TextureBuffer(tex)
		Next
	Next

End Function