[B3D] Real-Time Fluid Dynamics for Games ala Jos Stam
Übersicht

KrümelBetreff: [B3D] Real-Time Fluid Dynamics for Games ala Jos Stam |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo!
Ich habe mit hilfe der Pdf-datei "Real-Time Fluid Dynamics for Games" von Jos Stam folgenden Code zusamengebastelt. (läuft auf meinem Rechner mit ca. 110 fps) *EDIT* um den Effekt zu sehen Mausteste drücken und Maus bewegen Code: [AUSKLAPPEN] ;REAL-TIME FLUID DYNAMICS FOR GAMES (Jos Stam) ;----------------------------------------------------------------- ;instructions: press mousebutton , move mouse Const FLOWSPEED# = 0.3 Const PRECISION% = 15 Const SIZE = 10 Const GRW = 800 , GRH = 600 Const GRX = (GRW / SIZE) Const GRY = (GRH / SIZE) Graphics3D GRW , GRH , 16 , 0 SetBuffer BackBuffer() Global Camera = CreateCamera() PositionEntity Camera , 0 , 0 , - (GRW * 0.5) / (SIZE + 1) Dim VelX#(GRX , GRY , 2) Dim VelY#(GRX , GRY , 2) Dim Red#(GRX , GRY , 2) Dim Grn#(GRX , GRY , 2) Dim Blu#(GRX , GRY , 2) Dim Vertex%(GRX , GRY) Global Mesh = makeMesh() Function AddVelocity(x , y , vx# , vy#) Local xx,yy For yy = y - 1 To y + 1 For xx = x - 1 To x + 1 If xx >= 0 And xx < grx - 1 And yy >= 0 And yy < gry - 1 VelX(xx , yy , 0) = VelX(xx , yy , 0) + vx VelY(xx , yy , 0) = VelY(xx , yy , 0) + vy EndIf Next Next End Function Function AddColor(x , y , r , g , b) Local xx,yy For yy = y - 1 To y + 1 For xx = x - 1 To x + 1 If xx >= 0 And xx < grx - 1 And yy >= 0 And yy < gry - 1 Red(xx , yy , 0) = r Grn(xx , yy , 0) = g Blu(xx , yy , 0) = b EndIf Next Next End Function Function Animation( d# ) Local h = (GRX-1) * (GRY-1) , hh# = 1.0 / h Local speed# = d * h * FLOWSPEED Local k , x , y , x0 , y0 , x1 , y1 Local xx# , yy# , s0# , s1# , t0# , t1# ;Advect For y = 0 To GRY - 1 For x = 0 To GRX - 1 xx# = x - speed * VelX(x , y , 1) yy# = y - speed * VelY(x , y , 1) If xx < 0 xx = 0 Else If xx > GRX-1 xx = GRX-1 If yy < 0 yy = 0 Else If yy > GRY-1 yy = GRY-1 x0 = Floor(xx) : x1 = x0 + 1 y0 = Floor(yy) : y1 = y0 + 1 s1# = xx - x0 : s0# = 1.0 - s1 t1# = yy - y0 : t0# = 1.0 - t1 VelX(x , y , 1) = s0 * (t0 * VelX(x0 , y0 , 0) + t1 * VelX(x0 , y1 , 0)) + s1 * (t0 * VelX(x1 , y0 , 0) + t1 * VelX(x1 , y1 , 0)) VelY(x , y , 1) = s0 * (t0 * VelY(x0 , y0 , 0) + t1 * VelY(x0 , y1 , 0)) + s1 * (t0 * VelY(x1 , y0 , 0) + t1 * VelY(x1 , y1 , 0)) Red(x , y , 1) = s0 * (t0 * Red(x0 , y0 , 0) + t1 * Red(x0 , y1 , 0)) + s1 * (t0 * Red(x1 , y0 , 0) + t1 * Red(x1 , y1 , 0)) Grn(x , y , 1) = s0 * (t0 * Grn(x0 , y0 , 0) + t1 * Grn(x0 , y1 , 0)) + s1 * (t0 * Grn(x1 , y0 , 0) + t1 * Grn(x1 , y1 , 0)) Blu(x , y , 1) = s0 * (t0 * Blu(x0 , y0 , 0) + t1 * Blu(x0 , y1 , 0)) + s1 * (t0 * Blu(x1 , y0 , 0) + t1 * Blu(x1 , y1 , 0)) Next Next ;Project For y = 1 To GRY - 2 For x = 1 To GRX - 2 VelY(x , y , 0) = - 0.5 * h * (VelX(x + 1 , y , 1) - VelX(x - 1 , y , 1) + VelY(x , y + 1 , 1) - VelY(x , y - 1 , 1)) VelX(x , y , 0) = 0 Next Next For k = 1 To PRECISION For y = 1 To GRY - 2 For x = 1 To GRX - 2 VelX(x , y , 0) = (VelY(x , y , 0) + VelX(x - 1 , y , 0) + VelX(x + 1 , y , 0) + VelX(x , y - 1 , 0) + VelX(x , y + 1 , 0)) * 0.25 Next Next Next For y = 1 To GRY - 2 For x = 1 To GRX - 2 VelX(x , y , 1) = VelX(x , y , 1) - 0.5 * (VelX(x + 1 , y , 0) - VelX(x - 1 , y , 0)) * hh VelY(x , y , 1) = VelY(x , y , 1) - 0.5 * (VelX(x , y + 1 , 0) - VelX(x , y - 1 , 0)) * hh Next Next ;Diffuse For y = 1 To GRY - 2 For x = 1 To GRX - 2 VelX(x , y , 0) = VelX(x , y , 1);* 0.98 + (VelX(x - 1 , y , 1) + VelX(x + 1 , y , 1) + VelX(x , y - 1 , 1) + VelX(x , y + 1 , 1)) * (0.25 * 0.02) VelY(x , y , 0) = VelY(x , y , 1);* 0.98 + (VelY(x - 1 , y , 1) + VelY(x + 1 , y , 1) + VelY(x , y - 1 , 1) + VelY(x , y + 1 , 1)) * (0.25 * 0.02) Red(x , y , 0) = Red(x , y , 1) Grn(x , y , 0) = Grn(x , y , 1) Blu(x , y , 0) = Blu(x , y , 1) Next Next ;Test bounds For x = 1 To GRX-2 VelY(x , 1 , 1) = Abs(VelY(x , 2 , 1)) VelY(x , GRY - 2 , 1) = -Abs(VelY(x , GRY - 3 , 1)) Next For y = 1 To GRY-2 VelX(1 , y , 1) = Abs(VelX(2 , y , 1)) VelX(GRX - 2 , y , 1) = -Abs(VelX(GRX - 3 , y , 1)) Next End Function Function MakeMesh() Local x , y Local mesh = CreateMesh() Local surf = CreateSurface(Mesh) EntityFX mesh , 1 + 2 PositionEntity mesh , 0.5 - GRX * 0.5 , 0.5 - GRY * 0.5, 0 For y = 0 To GRY - 1 For x = 0 To GRX - 1 Vertex(x , y) = AddVertex(surf , x , GRY - y - 1 , 0 , x / Float(GRX) , 1.0 - y / Float(GRY)) VertexColor surf , Vertex(x , y) , 255 , 0 , 0 Next Next For y = 0 To GRY - 2 For x = 0 To GRX - 2 AddTriangle surf , Vertex(x , y) , Vertex(x + 1 , y) , Vertex(x + 1 , y + 1) AddTriangle surf , Vertex(x , y) , Vertex(x + 1 , y + 1) , Vertex(x , y + 1) Next Next Return mesh End Function Function DrawMesh() Local surface = GetSurface(Mesh , 1) Local x , y For y = 0 To GRY - 1 For x = 0 To GRX - 1 VertexColor surface , Vertex(x , y) , Red(x , y , 0) , Grn(x , y , 0) , Blu(x , y , 0) Next Next End Function Function Clear() Local x , y For y = 0 To GRY - 1 For x = 0 To GRX - 1 VelX(x , y , 0) = 0 VelY(x , y , 0) = 0 Red(x , y , 0) = 0 Grn(x , y , 0) = 0 Blu(x , y , 0) = 0 Next Next End Function MoveMouse GRW * 0.5 , GRH * 0.5 While (GetKey() = 0) timeStep# = (MilliSecs() - oldTime) / 1000.0 oldTime = MilliSecs() x = MouseX() / SIZE y = MouseY() / SIZE mxs# = MouseXSpeed() * timeStep mys# = MouseYSpeed() * timeStep If mxs <> 0 Or mys <> 0 AddVelocity(x , y , mxs , mys) If MouseHit(1) Color Rnd(255) , Rnd(255) , Rnd(255) If MouseDown(1) AddColor (x , y , ColorRed() * 2 , ColorGreen() * 2 , ColorBlue() * 2) If MouseDown(2) Clear() Animation(timeStep) drawMesh() RenderWorld fps = fps + 1 : If (oldTime - fpst) > 1000 fpst = oldTime : f = fps : fps = 0 Text 0 , 0 , "fps: " + f Flip 0 Wend |
||
- Zuletzt bearbeitet von Krümel am So, Jan 21, 2007 17:39, insgesamt einmal bearbeitet
![]() |
NightPhoenix |
![]() Antworten mit Zitat ![]() |
---|---|---|
öhm... bei mir ist alles schwarz... passiert garnix... lediglich ne fps anzeige kommt | ||
Combine |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Beweg ma die Maus und drück Linke und rechte Maustaste^^ | ||
![]() |
FireballFlame |
![]() Antworten mit Zitat ![]() |
---|---|---|
Is ne coole Sache... darauf basierend gibts sogar ein Spiel namens "Plasma Pong" ![]() |
||
PC: Intel Core i7 @ 4x2.93GHz | 6 GB RAM | Nvidia GeForce GT 440 | Desktop 2x1280x1024px | Windows 7 Professional 64bit
Laptop: Intel Core i7 @ 4x2.00GHz | 8 GB RAM | Nvidia GeForce GT 540M | Desktop 1366x768px | Windows 7 Home Premium 64bit |
![]() |
NightPhoenix |
![]() Antworten mit Zitat ![]() |
---|---|---|
krass.... endkrass.... heftig... das sieht aus wie echter rauch wenn man mit der maus durch so ne wolke durchfährt... gibts das auch für 3d? ![]() eher nicht oder?... ^^ |
||
![]() |
hecticSieger des IS Talentwettbewerb 2006 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Sehr geil! Mal sehen ob man es in irgend einer weise in eine Partikelengine unter bringen kann die dann nicht an soviel FPS zert. | ||
Krümel |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Das lässt sich relativ einfach auch in 3D umsetzen. Natürlich ist es dann je nach Auflösung wesentlich langsamer und nicht mehr echtzeittauglich.
Ich werde es demnächst mal ausprobieren. Mich würde mal interessieren wieviel fps ihr habt ? |
||
![]() |
StepTiger |
![]() Antworten mit Zitat ![]() |
---|---|---|
zwischen 103 und 105
sieht ganz nett aus! |
||
Noch gestern standen wir am Abgrund, doch heute sind wir schon einen Schritt weiter.
Computer: AMD Sempron 3000+; ATI Radeon 9800 Pro; 512 MB DDR RAM 400Mhz; Asus E7N8X-E Deluxe; Samsung 200GB HD 5.4ns acces t Gewinner: BP Code Compo #2 Π=3.141592653589793238...<--- und das aus dem kopf ![]() Seit der Earthlings-Diskussion überzeugter Fleisch(fr)esser. |
![]() |
TheProgrammer |
![]() Antworten mit Zitat ![]() |
---|---|---|
Der Effekt sieht geil aus.. ![]() ![]() edit: ohne Debugger läuft es bei 160 Fps, sogar ohne Bugs ^^ |
||
aktuelles Projekt: The last day of human being |
flashmaxel |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Wirklich schicker Effekt ! Aber dank meines recht schlechten PCs nur 55-56 fps. | ||
Real C programmers never die; they cast to void. |
![]() |
Horst der Biber |
![]() Antworten mit Zitat ![]() |
---|---|---|
17-25 fps
Nach 5 min ist er überhitzt und abgestürzt. :C Aber das macht er schon bei fast jedem 3D Spiel. Effekt ist ganz schick. ^^ Fand den aber in Plasma Pong schöner Oo. |
||
FWeinbehemals "ich" |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Also der Effekt ich Geil ich habe das mal an gemacht und auf meien Laptop leuft das mit 80 Fps und der ist nicht so gut auf meien normalen leuft das mit 190 fps als das ist schon nicht schlecht für so nen schicken effekt
[Edit] ohne Dubugger bekomme ich mit meim PC 290FPS |
||
"Wenn die Menschen nur über das sprächen, was sie begreifen, dann würde es sehr still auf der Welt sein." Albert Einstein (1879-1955)
"If you live each day as if it was your last, someday you'll most certainly be right." Steve Jobs |
- Zuletzt bearbeitet von FWeinb am Mo, Jan 22, 2007 19:28, insgesamt einmal bearbeitet
![]() |
FreetimeCoder |
![]() Antworten mit Zitat ![]() |
---|---|---|
242 FPS ![]() ohne Debugger Geiler Effeckt! Dickes Lob. |
||
"Wir haben keine Chance, aber wir werden sie nutzen!"
Projekte: Dexterity Ball (100%) Aquatic Atmosfear (22 % ca 4700 Zeilen) eingefrohren mangels OOP Fähigkeiten von Blitz (ehemals Uboot) PC: Intel D 3 GHz | NVidiaGforce 6700 256 Mb | 1024 Mb DDR RAM 400 Mhz | 2x160 GB S-ATA |
![]() |
d-bug |
![]() Antworten mit Zitat ![]() |
---|---|---|
Schick!
FPS m. Debugger : 25 FPS o. Debugger : 97 Specs siehe Signatur. |
||
![]() |
AraneA |
![]() Antworten mit Zitat ![]() |
---|---|---|
150 auf laptop
dickes Lob sehr schick ich glaub ich mach mir n Screensaver daraus... ![]() |
||
![]() |
Dante |
![]() Antworten mit Zitat ![]() |
---|---|---|
Wow echt super =)
bestimmt cool für ein paar Spiele ![]() FPS mit Debugger: 45 FPS ohne Debugger: 149-150 |
||
![]() |
FireballFlame |
![]() Antworten mit Zitat ![]() |
---|---|---|
Na klar! Googelt doch einfach mal nach "Plasma Pong" ![]() Ich hab mit Debugger 45 und ohne 130. |
||
PC: Intel Core i7 @ 4x2.93GHz | 6 GB RAM | Nvidia GeForce GT 440 | Desktop 2x1280x1024px | Windows 7 Professional 64bit
Laptop: Intel Core i7 @ 4x2.00GHz | 8 GB RAM | Nvidia GeForce GT 540M | Desktop 1366x768px | Windows 7 Home Premium 64bit |
![]() |
rctuner |
![]() Antworten mit Zitat ![]() |
---|---|---|
echt cool geworden!
ist was aus deiner 3d Version geworden? zu meiner eigendlichen Frage: Kann ich den Effekt auch so einsetzten dass er die 3d Objekte überdecken würde? Hab jetzt nämlich mal einfach ein cube in die Szene gesetzt. Der scheint aber einfach durch den Effekt durch und wird nicht beeinträchtigt vom Fluid. |
||
[Y[our Film, Game ]M[akers and more [F]un!
www.Master-Entertainment.de.vu [AMD 6000+ X2 @ 6400+][2GB RAM][NVidia 8800GT 512 MB] |
![]() |
Goodjee |
![]() Antworten mit Zitat ![]() |
---|---|---|
du kannst doch einfach die position des effektmesh( global mesh) verändern, oda? | ||
Krümel |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
hi, rctuner!
Naja, die 3d-Version ist schon was geworden, wie erwartet läuft das aber sehr langsam und speicherintensiv weil ich nicht weiss, wie ich 3d-Fluid rendern soll. Was genau meinst du mit "3d-objekte überdecken" ? Meinst Du, dass der "Rauch" um die Objekte herumwirbeln soll? |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group