Ooops
January 26, 2021, 06:15:27 AM

Author Topic: [bb] SIMPLE SHADOW SYSTEM by degac [ 1+ years ago ]  (Read 651 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] SIMPLE SHADOW SYSTEM by degac [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : SIMPLE SHADOW SYSTEM
Author : degac
Posted : 1+ years ago

Description : I was thinking of a method of culling and it's jumped out this simple system to create shadow. In this stage it can be used to create shadow of structure on terrain for a strategic game or for indoor in an adventure game.
Probably already created!
Enjoy
You need to add 3 image to work out!


Code :
Code: BlitzBasic
  1. ;lightmap world 01
  2. ;test
  3. ;graphio - degac72 at katamail.com
  4. ;16-04-2004
  5. ;please inform me if the algo is useful!
  6. ; --- good playing ---
  7. ; use linepick code from Tim Fisher (Flynn)
  8. ; probably needs some triks...
  9. Graphics3D 640,480,32,2
  10. SetBuffer BackBuffer()
  11. Dim lm#(129,129),lmap#(129,129)
  12.  
  13. AmbientLight 20,20,20
  14. Global fps=30
  15. Global numeroOggetti=5
  16. Global showMap=CreateImage(64,64)
  17. Global imgbuffer=ImageBuffer(showMap)
  18. Color 255,255,255
  19. For xx=0 To 63
  20. For yy=0 To 63
  21. Plot xx,yy
  22. Next
  23. Next
  24. GrabImage showMap,0,0
  25. Cls
  26. ; --------------
  27.  
  28.  
  29. txtBrick=LoadTexture("gfxgothic3.bmp",1)
  30. txtPillar=LoadTexture("gfxcastlest.bmp",1)
  31.  
  32. Global cuplane=CreateCube()
  33. ScaleMesh cuplane,30,1,30
  34. PositionEntity cuplane,30,-2,30
  35. Global LMbuffer=CreateTexture(256,256,1); 256-->scale texture 4 128-->2  64-->1
  36. ScaleTexture txtBrick,.5,.5
  37. EntityTexture cuplane,txtBrick,0,0
  38.  
  39. cu=CreateCube()
  40. ScaleTexture txtPillar,.5,.5
  41. EntityTexture cu,txtPillar
  42. ;EntityColor cu,200,200,200
  43.  
  44.  
  45. ScaleMesh cu,1,4,1
  46. HideEntity cu
  47. WireFrame 0
  48. SeedRnd(MilliSecs())
  49. Dim oggetti(numeroOggetti)
  50. hh#=1
  51. px=5
  52. py=15
  53. For k=0 To numeroOggetti
  54. oggetti(k)=CopyEntity(cu)
  55. Next
  56.  
  57. For k=0 To numeroOggetti
  58. px=k+5+Rand(0,15)*3
  59. py=k+5+Rand(0,15)*3
  60. PositionEntity oggetti(k),px,0,py
  61. If Rand(1,10)>8 Then ScaleMesh oggetti(k),1.2,1.2,1.2
  62. EntityTexture oggetti(k),txtBrick
  63. Next
  64.  
  65. Global sfera=CreatePivot()
  66. Global sprite=LoadSprite("gfxflare.png",1+2,sfera)
  67. ScaleSprite sprite,2,2
  68. movLight=CreateLight(2,sfera)
  69. LightRange movLight,8
  70. cameraPivot=CreatePivot(cuplane)
  71. camera=CreateCamera(cameraPivot)
  72. PositionEntity camera,30,10,-5
  73. RotateEntity camera,20,90,0
  74.  
  75. CreatePlaceMap()
  76.  
  77.  
  78. Global lightX=16
  79. Global lightY=16
  80.  
  81. CreateMAP()
  82. ;ShowPlaceMap()
  83. CreateShowMap()
  84.  
  85. Repeat
  86. kk=kk+1
  87. timeStart=MilliSecs()
  88. ;TurnEntity sfera,1,0,0
  89. If giro=1 Then
  90.                  TurnEntity cameraPivot,0,.5,0
  91.                 End If
  92. UpdateWorld
  93. RenderWorld
  94. If lightX<>MouseX() Or lightY<>MouseY()
  95.         lightX=MouseX()
  96.         lightY=64-MouseY()
  97.         PositionEntity sfera,lightX,1,lightY
  98.         CreateMap()
  99. End If
  100. If KeyDown(200) Then MoveEntity camera,0,1,0:PointEntity camera,cuplane
  101. If KeyDown(208) Then MoveEntity camera,0,-1,0:PointEntity camera,cuplane
  102. If KeyDown(57) Then giro=1-giro
  103.  
  104.                
  105. timeEnd=MilliSecs()
  106. elapsed=(timeEnd-TimeStart)
  107. Text 0,460,"Time: "+elapsed
  108. Text 0,470,"FPS : "+((1000-elapsed)/FPS)
  109. Flip
  110. Until KeyDown(1)
  111.  
  112. EndGraphics()
  113. End
  114.  
  115. Function CreateMAP()
  116. CreateLightMap(lightX,lightY,10)
  117. CreateShowMap()
  118. CopyRect 0,0,64,64,0,0,imgBuffer,TextureBuffer(LMbuffer)
  119. ScaleTexture LMbuffer,4,4
  120. EntityTexture cuplane,LMbuffer,0,2
  121.  
  122.  
  123. End Function
  124.  
  125.  
  126. Function ShowPlaceMap()
  127. Local stepx=1
  128. Local sizeX=64
  129. Local sizeY=sizex
  130. xx=0
  131. yy=0
  132. For x=0 To sizeX-1
  133. For y=SizeY-1 To 0 Step -1
  134. p=lm(x,y)
  135. alm=255-lmap(x,y)
  136. yy=yy+stepx
  137. If alm>0 Then Color alm,alm,alm:Rect xx,yy,2,2,1
  138. Next
  139. xx=xx+stepx
  140. yy=0
  141. Next
  142. End Function
  143.  
  144.  
  145.  
  146. Function CreateShowMap()
  147. LockBuffer(imgBuffer)
  148. Local stepx=1
  149. Local sizeX=64
  150. Local sizeY=sizex
  151. xx=0
  152. yy=0
  153. cc=128
  154. rgb=cc Or (cc Shl 8) Or (cc Shl 16)
  155. rrgb=255 Or (255 Shl 8) Or (255 Shl 16)
  156.  
  157. For x=0 To sizeX-1
  158. For y=SizeY-1 To 0 Step -1
  159. ;p=lm(x,y)
  160. alm=lmap(x,y)
  161. yy=yy+stepx
  162. ;rrgb=ReadPixelFast(xx,yy,imgBuffer)
  163.  
  164. If alm>0 Then
  165. WritePixelFast(xx,yy,rgb,imgBuffer)
  166. ;WritePixelFast(xx+1,yy,rgb,imgBuffer)
  167. ;WritePixelFast(xx,yy+1,rgb,imgBuffer)
  168. ;WritePixelFast(xx+1,yy+1,rgb,imgBuffer)
  169. Else
  170. WritePixelFast(xx,yy,rrgb,imgBuffer)
  171. ;WritePixelFast(xx+1,yy,rrgb,imgBuffer)
  172. ;WritePixelFast(xx,yy+1,rrgb,imgBuffer)
  173. ;WritePixelFast(xx+1,yy+1,rrgb,imgBuffer)
  174.  
  175. End If
  176. Next
  177. xx=xx+stepx
  178. yy=0
  179. Next
  180. UnlockBuffer(ImgBuffer)
  181.  
  182.  
  183. End Function
  184.  
  185.  
  186.  
  187.  
  188. Function CreateLightMap(sx#,sy#,sz#)
  189. If sz>1060 Then Return
  190. For x=0 To 63
  191. For y=0 To 63
  192. If lockedLine(x,y,lm(x,y),sx,sy,sz) Then lmap(x,y)=100 Else lmap(x,y)=0
  193. Next
  194. Next
  195. End Function
  196.  
  197. Function LockedLine(x1#,y1#,z1#,x2#,y2#,z2#)
  198. Local steps,xi#
  199. x2=x2-x1
  200. y2=y2-y1
  201. z2=z2-z1
  202. If Abs(x2)>Abs(y2) steps=Abs(x2) Else steps=Abs(y2)
  203. xI=x2/steps
  204. y2=y2/steps
  205. z2=z2/steps
  206.  
  207. While (x1<=64) And (y1<=64) And (z1<=64) And (x1=>0) And (y1=>0) And (z1=>0)
  208. If lm(x1,y1)>z1 Then Return True
  209. x1=x1+XI
  210. y1=y1+y2
  211. z1=z1+z2
  212. Wend
  213. Return False
  214. End Function
  215.  
  216.  
  217. Function CreatePlaceMap()
  218. For k=0 To numeroOggetti
  219.  
  220. cu=Oggetti(k)
  221.  
  222. x=EntityX(cu)
  223. z=EntityZ(cu)
  224. w=MeshWidth(cu)
  225. d=MeshDepth(cu)
  226. h=MeshHeight(cu)
  227.  
  228. x1=x+1
  229. y1=z+2
  230. If x1<0 Then x1=0
  231. If y1<0 Then y1=0
  232.  
  233.  
  234. x2=x1+w-1
  235. y2=(y1+d-1)
  236.  
  237. If x2>64 Then x2=64
  238. If y2>64 Then y2=64
  239.  
  240. For xx=x1 To x2
  241. For yy=y1 To y2
  242.  
  243. lm(xx,yy)=h
  244. Next
  245. Next
  246. Next
  247. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal