March 08, 2021, 12:34:04 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Advanced Shadows by Nate the Great [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Advanced Shadows by Nate the Great [ 1+ years ago ] (Read 654 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Advanced Shadows by Nate the Great [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:38 AM »
Title :
Advanced Shadows
Author :
Nate the Great
Posted :
1+ years ago
Description :
Pixel Perfect , but very slow shadows. I don't have any use for this but someone else might.
Code :
Code: BlitzBasic
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 G(Posted 1+ years ago)
Does't work here MAV. You're writeing the pixels outside a locked buffer ... the range is 0 to graphicswidth()-1 etc..
Nate the Great(Posted 1+ years ago)
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).
DareDevil(Posted 1+ years ago)
hi all hi have changed your code with this for fast speedFunction 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 FunctionFunction GetRGBA(r,g,b,a) Return b Or (g Shl
Or (r Shl 16) Or (r Shl 16)End FunctionFunction GetRGB(r,g,b) Return (b Or (g Shl
Or (r Shl 16))End FunctionFunction GetRGB_Monocrome(col) Return col Or (col Shl
Or (col Shl 16)End FunctionFunction GetRGB_R(RGB) Return RGB Shr 16 And %11111111End FunctionFunction GetRGB_G(RGB) Return RGB Shr 8 And %11111111End FunctionFunction GetRGB_B(RGB) Return RGB And %11111111End FunctionFunction GetRGB_A(RGB) Return RGB Shr 24 And %11111111End Function
Nate the Great(Posted 1+ years ago)
Thanks DareDevil. I'm didn't think of doing that. Now I get 5 Frames per second.
DareDevil(Posted 1+ years ago)
the real problem is CameraPick and LinePick this function are very slow.if you use this function set EntityPickMode box,2EntityPickMode box2,2this created real shadow object .bye
Nate the Great(Posted 1+ years ago)
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.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Effects
»
[bb] Advanced Shadows by Nate the Great [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal