Ooops
November 30, 2020, 01:57:29 AM

Author Topic: [bb] Advanced Shadows by Nate the Great [ 1+ years ago ]  (Read 612 times)

Offline 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
  1. Graphics3D 320,240,0,2
  2. cam = CreateCamera()
  3. box = CreateCube()
  4. box2 = CreateCube()
  5.  
  6. tex = CreateTexture(64,64)
  7. SetBuffer TextureBuffer(tex)
  8. ClsColor 255,255,255
  9. Color 0,0,0
  10. Cls
  11. Text 1,1,"SHADOW"
  12. Text 1,16,"SHADOW"
  13. Text 1,32,"SHADOW"
  14. ClsColor 0,0,0
  15.  
  16. EntityTexture box2,tex
  17.  
  18. lit = CreateLight()
  19. RotateEntity lit,90,45,0
  20. EntityPickMode box,3
  21. EntityPickMode box2,2
  22. MoveEntity box2,-2.5,-.5,0
  23. TurnEntity box2,0,45,0
  24. ScaleEntity  box2,.5,.5,.5
  25.  
  26. plane = CreatePlane()
  27. EntityPickMode plane,2
  28. MoveEntity plane,0,-.5,0
  29.  
  30. EntityColor box,255,0,0
  31. EntityColor plane,0,0,255
  32.  
  33. TurnEntity cam,45,0,0
  34. MoveEntity cam,0,0,-5
  35.  
  36. SetBuffer BackBuffer()
  37.  
  38. Cls
  39.  
  40. UpdateWorld()
  41. RenderWorld2(cam,10,10,0)
  42. Flip
  43. WaitKey()
  44. End
  45.  
  46. Function renderworld2(cam,x1#,y1#,z1#)
  47.  
  48. RenderWorld()
  49. For x = 1 To GraphicsWidth()-1
  50.         For y = 1 To GraphicsHeight()-1
  51.                 ent = CameraPick(cam,x,y)
  52.                 If ent <> LinePick(x1#,y1#,z1#,(PickedX#()-x1#),(PickedY#()-y1#),(PickedZ#()-z1#)) Then
  53.                        
  54.                         ;Plot x,y      
  55.                         LockBuffer BackBuffer()
  56.                                
  57.                                 rgb = ReadPixelFast(x,y)
  58.                                 Color (getred(rgb)/2),(getgreen(rgb)/2),(getblue(rgb)/2)
  59.                                
  60.                         UnlockBuffer BackBuffer()
  61.                                 Plot x,y
  62.                 EndIf
  63.         Next
  64. Next
  65.  
  66. End Function
  67.  
  68.  
  69.  
  70.  
  71.  
  72. Function GetRed(rgb)
  73.         Return rgb Shr 16 And %11111111
  74. End Function
  75. Function GetGreen(rgb)
  76.         Return rgb Shr 8 And %11111111
  77. End Function
  78. Function GetBlue(rgb)
  79.         Return rgb And %11111111
  80. 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 8) Or (r Shl 16) Or (r Shl 16)End FunctionFunction GetRGB(r,g,b)   Return (b Or (g Shl 8) Or (r Shl 16))End FunctionFunction GetRGB_Monocrome(col)   Return col Or (col Shl 8) 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal