Code archives/3D Graphics - Effects/Advanced Shadows

This code has been declared by its author to be Public Domain code.

Download source code

Advanced Shadows by Nate the Great2008
Pixel Perfect , but very slow shadows. I don't have any use for this but someone else might.
Graphics3D 320,240,0,2
cam = CreateCamera()
box = CreateCube()
box2 = CreateCube()

tex = CreateTexture(64,64)
SetBuffer TextureBuffer(tex)
ClsColor 255,255,255
Color 0,0,0
Cls
Text 1,1,"SHADOW"
Text 1,16,"SHADOW"
Text 1,32,"SHADOW"
ClsColor 0,0,0

EntityTexture box2,tex

lit = CreateLight()
RotateEntity lit,90,45,0
EntityPickMode box,3
EntityPickMode box2,2
MoveEntity box2,-2.5,-.5,0
TurnEntity box2,0,45,0
ScaleEntity  box2,.5,.5,.5

plane = CreatePlane()
EntityPickMode plane,2
MoveEntity plane,0,-.5,0

EntityColor box,255,0,0
EntityColor plane,0,0,255

TurnEntity cam,45,0,0
MoveEntity cam,0,0,-5

SetBuffer BackBuffer()

Cls

UpdateWorld()
RenderWorld2(cam,10,10,0)
Flip
WaitKey()
End

Function renderworld2(cam,x1#,y1#,z1#)

RenderWorld()
For x = 1 To GraphicsWidth()-1
	For y = 1 To GraphicsHeight()-1
		ent = CameraPick(cam,x,y)
		If ent <> LinePick(x1#,y1#,z1#,(PickedX#()-x1#),(PickedY#()-y1#),(PickedZ#()-z1#)) Then
			
			;Plot x,y	
			LockBuffer BackBuffer()
				
				rgb = ReadPixelFast(x,y)
				Color (getred(rgb)/2),(getgreen(rgb)/2),(getblue(rgb)/2)
				
			UnlockBuffer BackBuffer()
				Plot x,y
		EndIf
	Next
Next

End Function





Function GetRed(rgb)
	Return rgb Shr 16 And %11111111
End Function
Function GetGreen(rgb)
	Return rgb Shr 8 And %11111111
End Function
Function GetBlue(rgb)
	Return rgb And %11111111
End Function

Comments

Stevie G2008
Does't work here MAV. You're writeing the pixels outside a locked buffer ... the range is 0 to graphicswidth()-1 etc..


Nate the Great2008
Oh sorry does it work now? For some reason my computer lets me draw outside the locked buffer.

p.s. sorry it's so slow it's .2 frames per second on my computer so it might be very slow if you have an older computer. (I have a Lenovo Dual Core).


DareDevil2008
hi all
hi have changed your code with this for fast speed

Function renderworld2(cam,x1#,y1#,z1#)

RenderWorld()
LockBuffer BackBuffer()
For x = 1 To GraphicsWidth()-1
For y = 1 To GraphicsHeight()-1
ent = CameraPick(cam,x,y)
If ent <> LinePick(x1#,y1#,z1#,(PickedX#()-x1#),(PickedY#()-y1#),(PickedZ#()-z1#)) Then

rgb = ReadPixelFast(x,y)

WritePixelFast x,y,GetRGB((GetRGB_R(rgb)/2),(GetRGB_G(rgb)/2),(GetRGB_B(rgb)/2))
EndIf
Next
Next
UnlockBuffer BackBuffer()

End Function

Function GetRGBA(r,g,b,a)
Return b Or (g Shl 8) Or (r Shl 16) Or (r Shl 16)
End Function

Function GetRGB(r,g,b)
Return (b Or (g Shl 8) Or (r Shl 16))
End Function
Function GetRGB_Monocrome(col)
Return col Or (col Shl 8) Or (col Shl 16)
End Function

Function GetRGB_R(RGB)
Return RGB Shr 16 And %11111111
End Function

Function GetRGB_G(RGB)
Return RGB Shr 8 And %11111111
End Function

Function GetRGB_B(RGB)
Return RGB And %11111111
End Function

Function GetRGB_A(RGB)
Return RGB Shr 24 And %11111111
End Function


Nate the Great2008
Thanks DareDevil. I'm didn't think of doing that. Now I get 5 Frames per second.


DareDevil2008
the real problem is CameraPick and LinePick this function are very slow.

if you use this function set

EntityPickMode box,2
EntityPickMode box2,2

this created real shadow object .

bye


Nate the Great2008
Well, I was just messing around with linepick and readpixelfast. I did this in a matter of minutes. As I said, I have no use for it but someone else might benifit from it.


Code Archives Forum