GteFluid2.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
9 #include <Physics/GteFluid2.h>
10 using namespace gte;
11 
12 Fluid2::Fluid2(std::shared_ptr<GraphicsEngine> const& engine,
13  std::shared_ptr<ProgramFactory> const& factory,
14  int xSize, int ySize, float dt, float densityViscosity, float velocityViscosity)
15  :
16  mEngine(engine),
17  mXSize(xSize),
18  mYSize(ySize),
19  mDt(dt),
20  mTime(0.0f)
21 {
22  // Create the shared parameters for many of the simulation shaders.
23  float dx = 1.0f/static_cast<float>(mXSize);
24  float dy = 1.0f/static_cast<float>(mYSize);
25  float dtDivDxDx = (dt/dx)/dx;
26  float dtDivDyDy = (dt/dy)/dy;
27  float ratio = dx/dy;
28  float ratioSqr = ratio*ratio;
29  float factor = 0.5f/(1.0f + ratioSqr);
30  float epsilonX = factor;
31  float epsilonY = ratioSqr*factor;
32  float epsilon0 = dx*dx*factor;
33  float denVX = densityViscosity*dtDivDxDx;
34  float denVY = densityViscosity*dtDivDyDy;
35  float velVX = velocityViscosity*dtDivDxDx;
36  float velVY = velocityViscosity*dtDivDyDy;
37 
38  mParameters = std::make_shared<ConstantBuffer>(sizeof(Fluid2Parameters), false);
40  p.spaceDelta = { dx, dy, 0.0f, 0.0f };
41  p.halfDivDelta = { 0.5f / dx, 0.5f / dy, 0.0f, 0.0f };
42  p.timeDelta = { dt / dx, dt / dy, 0.0f, dt };
43  p.viscosityX = { velVX, velVX, 0.0f, denVX };
44  p.viscosityY = { velVY, velVY, 0.0f, denVY };
45  p.epsilon = { epsilonX, epsilonY, 0.0f, epsilon0 };
46 
47  // Create the compute shaders and textures for the simulation.
48  mInitializeSource = std::make_shared<Fluid2InitializeSource>(factory,
49  mXSize, mYSize, 16, 16, mParameters);
50  mSourceTexture = mInitializeSource->GetSource();
51 
52  mInitializeState = std::make_shared<Fluid2InitializeState>(factory,
53  mXSize, mYSize, 16, 16);
54  mStateTm1Texture = mInitializeState->GetStateTm1();
55  mStateTTexture = mInitializeState->GetStateT();
56 
57  mEnforceStateBoundary = std::make_shared<Fluid2EnforceStateBoundary>(
58  factory, mXSize, mYSize, 16, 16);
59 
60  mUpdateState = std::make_shared<Fluid2UpdateState>(factory, mXSize,
61  mYSize, 16, 16, mParameters);
62  mStateTp1Texture = mUpdateState->GetUpdateState();
63 
64  mComputeDivergence = std::make_shared<Fluid2ComputeDivergence>(factory,
65  mXSize, mYSize, 16, 16, mParameters);
66  mDivergenceTexture = mComputeDivergence->GetDivergence();
67 
68  mSolvePoisson = std::make_shared<Fluid2SolvePoisson>(factory, mXSize,
69  mYSize, 16, 16, mParameters, 32);
70  mPoissonTexture = mSolvePoisson->GetPoisson();
71 
72  mAdjustVelocity = std::make_shared<Fluid2AdjustVelocity>(factory, mXSize,
73  mYSize, 16, 16, mParameters);
74 }
75 
77 {
78  mInitializeSource->Execute(mEngine);
79  mInitializeState->Execute(mEngine);
82 }
83 
85 {
92  std::swap(mStateTm1Texture, mStateTTexture);
93 
94  mTime += mDt;
95 }
96 
std::shared_ptr< Texture2 > mStateTp1Texture
Definition: GteFluid2.h:57
void DoSimulationStep()
Definition: GteFluid2.cpp:84
int mXSize
Definition: GteFluid2.h:39
Vector4< float > viscosityY
float mTime
Definition: GteFluid2.h:43
Vector4< float > spaceDelta
std::shared_ptr< Fluid2ComputeDivergence > mComputeDivergence
Definition: GteFluid2.h:50
std::shared_ptr< Fluid2UpdateState > mUpdateState
Definition: GteFluid2.h:49
std::shared_ptr< Texture2 > mStateTTexture
Definition: GteFluid2.h:56
Fluid2(std::shared_ptr< GraphicsEngine > const &engine, std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, float dt, float densityViscosity, float velocityViscosity)
Definition: GteFluid2.cpp:12
void Initialize()
Definition: GteFluid2.cpp:76
std::shared_ptr< Fluid2SolvePoisson > mSolvePoisson
Definition: GteFluid2.h:51
std::shared_ptr< Texture2 > mDivergenceTexture
Definition: GteFluid2.h:58
float mDt
Definition: GteFluid2.h:40
Vector4< float > halfDivDelta
std::shared_ptr< Fluid2InitializeState > mInitializeState
Definition: GteFluid2.h:47
std::shared_ptr< Texture2 > mSourceTexture
Definition: GteFluid2.h:54
Vector4< float > epsilon
int mYSize
Definition: GteFluid2.h:39
std::shared_ptr< Fluid2AdjustVelocity > mAdjustVelocity
Definition: GteFluid2.h:52
std::shared_ptr< Texture2 > mPoissonTexture
Definition: GteFluid2.h:59
Vector4< float > viscosityX
std::shared_ptr< Fluid2InitializeSource > mInitializeSource
Definition: GteFluid2.h:46
std::shared_ptr< GraphicsEngine > mEngine
Definition: GteFluid2.h:38
GLfloat f
Definition: glcorearb.h:1921
std::shared_ptr< Fluid2EnforceStateBoundary > mEnforceStateBoundary
Definition: GteFluid2.h:48
std::shared_ptr< Texture2 > mStateTm1Texture
Definition: GteFluid2.h:55
GLfloat GLfloat p
Definition: glext.h:11668
std::shared_ptr< ConstantBuffer > mParameters
Definition: GteFluid2.h:45
Vector4< float > timeDelta


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59