Ooops
January 19, 2021, 05:56:36 AM

Author Topic: [bb] 3D Motion Blur Starfield by AntonyWells [ 1+ years ago ]  (Read 615 times)

BlitzBot

• Jr. Member
• Posts: 1
[bb] 3D Motion Blur Starfield by AntonyWells [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : 3D Motion Blur Starfield
Author : AntonyWells
Posted : 1+ years ago

Description : Using custom Matrice functions, to render an interactive 3D starfield with per-pixel motion blur.
Change Stars =5000 to lower/increase the starcount.
Move the mouse to alter the pitch and yaw of the camera.

Press Lmb/Rmb to move camera along Z. (Use cX,cY vars to move along other axis)

-Edit-> Should have put this in the 2D section.

Code :
Code: BlitzBasic
1. Graphics 640,480,32,1
2. SetBuffer BackBuffer()
3.
4. ;--
5. Function Line(x#,y#,x1#,y1#,cv#)
6.         xd=x1-x
7.         yd=y1-y
8.         If Abs(xd)>Abs(yd) steps=Abs(xd) Else steps=Abs(yd)
9.         If steps<2 steps=2
10.         xi#=xd/Float(steps)
11.         yi#=yd/Float(steps)
12.         ci#=cv/Float(steps)
13.         av#=0
14.         For steps=steps To 1 Step -1
15.                 WritePixelFast x,y,av Or (av Shl 8) Or (av Shl 16)
16.                 av=av+ci
17.                 x=x+xi
18.                 y=y+yi
19.         Next
20.
21. End Function
22.
23.
24. ;--Star
25.
26. Dim mt#(4,4,8) ;Eight matrix buffers
27.
28. Global sCount
29.
30. Type vector
31.
32. Field x#,y#,z#
33.
34. End Type
35.
36. Type star
37.     Field ox,oy,oz
38.     Field loc.vector,oT,reset
39. End Type
40.
41. ;-Cam
42.
43. Global cX#,cY#,cZ#
44.
45. Global cP#,cT#,cR# ;cT = CYaw.
46.
47.
48. initStars(5000)
49.
50. Repeat:Cls
51.         cR=cR+1
52.         cP = cP+ MouseXSpeed()*0.2
53.         cT = cT+ MouseYSpeed()*0.2
54.         cZ=cZ+MouseDown(1)*6
55.         cZ=cZ-MouseDown(2)*6
56.
57.         MoveMouse 320,240
58.         FlushMouse
59.         starCycle()
60. Flip:Until KeyDown(1)
61.
62. EndGraphics
63. End
64.
65. ;-Star Functions
66.
67.
68. Function initStars(starCount = 1000)
69.    Local star.star
70.    For j = 1 To starCount
71.       star = New star
72.       starloc = vector( Rnd(-3000,3000),Rnd(-3000,3000),          Rnd(-4000,4000) )
73.    Next
74. End Function
75.
76. Const s1# = 255*256
77.
78. Function starCycle()
79.
80. Local star.star,dp.vector,oz
81.
82. dp = New vector
83.
84. gen_x_mat(1,cP)
85.
86. gen_y_mat(2,cT)
87.
88. multi_mat(1,2,3)
89.
90. gen_z_mat(2,cR)
91.
92. gen_t_mat(5, cX,cY,cZ)
93.
94. multi_mat(3,2,1)
95.
96. multi_mat(1,5,2)
97.
98. i=2
99.
100. LockBuffer
101.
102. For star = Each star
103.
104.
105.
106. oz = ((mt(1,3,i) * starlocx) + (mt(2,3,i) * starlocy) + (mt(3,3,i) * starlocz) + mt(4,3,i) ) + 256
107.
108. cV = ((s1) / ( oz))
109.
110.
111.
112. nX=320+ ( ((mt(1,1,i) * starlocx) + (mt(2,1,i) * starlocy) + (mt(3,1,i) * starlocz) + mt(4,1,i))   *256) / (oz)
113.
114.
115.
116. nY=200+ ((  (mt(1,2,i) * starlocx) + (mt(2,2,i) * starlocy) + (mt(3,2,i) * starlocz) + mt(4,2,i))  *256) / (oz)
117.
118. If cv<0 cv=0
119. If cv>255 cv=255
120.
121. If ny>0 And  ny<480 And nx>0 And nx<640
122.
123.         If star
124. eset=True
125.                 starox=nx
126.                 staroy=ny
127.                 star
128. eset=False
129.         EndIf
130.
131.         Line starox,staroy,nx,ny,cv
132. Else
133.         star
134. eset=True
135. EndIf
136.
137. starox=starox+(nx-starox)*0.25
138. staroy=staroy+(ny-staroy)*0.25
139.
140.
141. Next
142.
143. UnlockBuffer
144.
145. Delete dp
146.
147. Return sRen
148.
149. End Function
150.
151.
152.
153. ;--Music
154.
155.
156. Function playTrack(num=1)
157.
158. PlayMusic("t"+num+".mid")
159.
160. End Function
161.
162.
163. Function gen_x_mat(i,a#)
164.
165.         mt(1,1,i)=1:mt(2,1,i)=0:mt(3,1,i)=0:mt(4,1,i)=0
166.
167.         mt(1,2,i)=0:mt(2,2,i)=Cos(a):mt(3,2,i)=Sin(a):mt(4,2,i)=0
168.
169.         mt(1,3,i)=0:mt(2,3,i)=-Sin(a):mt(3,3,i)=Cos(a):mt(4,3,i)=0
170.
171.         mt(1,4,i)=0:mt(2,4,i)=0:mt(3,4,i)=0:mt(4,4,i)=1
172.
173. End Function
174.
175. Function gen_y_mat(i,a#)
176.
177.         mt(1,1,i)=Cos(a):mt(2,1,i)=0:mt(3,1,i)=-Sin(a):mt(4,1,i)=0
178.
179.         mt(1,2,i)=0:mt(2,2,i)=1:mt(3,2,i)=0:mt(4,2,i)=0
180.
181.         mt(1,3,i)=Sin(a):mt(2,3,i)=0:mt(3,3,i)=Cos(a):mt(4,3,i)=0
182.
183.         mt(1,4,i)=0:mt(2,4,i)=0:mt(3,4,i)=0:mt(4,4,i)=0
184.
185. End Function
186.
187. Function gen_z_mat(i,a#)
188.
189.         mt(1,1,i)=Cos(a):mt(2,1,i)=Sin(a):mt(3,1,i)=0:mt(4,1,i)=0
190.
191.         mt(1,2,i)=-Sin(a):mt(2,2,i)=Cos(a):mt(3,2,i)=0:mt(4,2,i)=0
192.
193.         mt(1,3,i)=0:mt(2,3,i)=0:mt(3,3,i)=1:mt(4,3,i)=0
194.
195.         mt(1,4,i)=0:mt(2,4,i)=0:mt(3,4,i)=0:mt(4,4,i)=0
196.
197. End Function
198.
199.
200. Function gen_t_mat(i,x#,y#,z#)
201.
202.         mt(1,1,i)=1:mt(2,1,i)=0:mt(3,1,i)=0:mt(4,1,i)=x
203.
204.         mt(1,2,i)=0:mt(2,2,i)=1:mt(3,2,i)=0:mt(4,2,i)=y
205.
206.         mt(1,3,i)=0:mt(2,3,i)=0:mt(3,3,i)=1:mt(4,3,i)=z
207.
208.         mt(1,4,i)=0:mt(2,4,i)=0:mt(3,4,i)=0:mt(4,4,i)=1
209.
210. End Function
211.
212. Function multi_mat(i1,i2,i3) ;Takes matrices i1 and i2 and combines them, resulting in i3
213.
214.         For m=1 To 4
215.         For m1=1 To 4
216.                 mt(m,m1,i3)=0
217.         For m2=1 To 4
218.                 mt(m,m1,i3)=mt(m,m1,i3)+mt(m,m2,i2)*mt(m2,m1,i1)
219.         Next
220.         Next
221.         Next
222.
223. End Function
224.
225.
226. Function vector.vector(x#=0,y#=0,z#=0)
227.         v.vector=New vector:vx=x:vy=y:vz=z
228.         Return v
229. End Function
230.
231.
232. ;------------------

churchaxe(Posted 1+ years ago)

cool stuff!

Clyde(Posted 1+ years ago)

Nice one and like the Spiralling!