15 int xSize,
int ySize,
int numXThreads,
int numYThreads,
16 std::shared_ptr<ConstantBuffer>
const& parameters)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads)
21 int i = factory->GetAPI();
22 factory->PushDefines();
23 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
24 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
32 factory->PopDefines();
36 std::shared_ptr<Texture2>
const& inState,
37 std::shared_ptr<Texture2>
const& poisson,
38 std::shared_ptr<Texture2>
const& outState)
42 cshader->Set(
"inState", inState);
43 cshader->Set(
"poisson", poisson);
44 cshader->Set(
"outState", outState);
50 "uniform Parameters\n" 52 " vec4 spaceDelta; // (dx, dy, 0, 0)\n" 53 " vec4 halfDivDelta; // (0.5/dx, 0.5/dy, 0, 0)\n" 54 " vec4 timeDelta; // (dt/dx, dt/dy, 0, dt)\n" 55 " vec4 viscosityX; // (velVX, velVX, 0, denVX)\n" 56 " vec4 viscosityY; // (velVX, velVY, 0, denVY)\n" 57 " vec4 epsilon; // (epsilonX, epsilonY, 0, epsilon0)\n" 60 "layout(rgba32f) uniform readonly image2D inState;\n" 61 "layout(r32f) uniform readonly image2D poisson;\n" 62 "layout(rgba32f) uniform writeonly image2D outState;\n" 64 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = 1) in;\n" 67 " ivec2 c = ivec2(gl_GlobalInvocationID.xy);\n" 68 " ivec2 dim = imageSize(inState);\n" 70 " int x = int(c.x);\n" 71 " int y = int(c.y);\n" 72 " int xm = max(x - 1, 0);\n" 73 " int xp = min(x + 1, dim.x - 1);\n" 74 " int ym = max(y - 1, 0);\n" 75 " int yp = min(y + 1, dim.y - 1);\n" 77 " // Sample the state at (x,y).\n" 78 " vec4 state = imageLoad(inState, c);\n" 80 " // Sample Poisson values at immediate neighbors of (x,y).\n" 81 " float poisPZ = imageLoad(poisson, ivec2(xp, y)).x;\n" 82 " float poisMZ = imageLoad(poisson, ivec2(xm, y)).x;\n" 83 " float poisZP = imageLoad(poisson, ivec2(x, yp)).x;\n" 84 " float poisZM = imageLoad(poisson, ivec2(x, ym)).x;\n" 86 " vec4 diff = vec4(poisPZ - poisMZ, poisZP - poisZM, 0.0f, 0.0f);\n" 87 " imageStore(outState, c, state + halfDivDelta*diff);\n" 91 "cbuffer Parameters\n" 93 " float4 spaceDelta; // (dx, dy, 0, 0)\n" 94 " float4 halfDivDelta; // (0.5/dx, 0.5/dy, 0, 0)\n" 95 " float4 timeDelta; // (dt/dx, dt/dy, 0, dt)\n" 96 " float4 viscosityX; // (velVX, velVX, 0, denVX)\n" 97 " float4 viscosityY; // (velVX, velVY, 0, denVY)\n" 98 " float4 epsilon; // (epsilonX, epsilonY, 0, epsilon0)\n" 101 "Texture2D<float4> inState;\n" 102 "Texture2D<float> poisson;\n" 103 "RWTexture2D<float4> outState;\n" 105 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, 1)]\n" 106 "void CSMain(uint2 c : SV_DispatchThreadID)\n" 109 " inState.GetDimensions(dim.x, dim.y);\n" 111 " int x = int(c.x);\n" 112 " int y = int(c.y);\n" 113 " int xm = max(x - 1, 0);\n" 114 " int xp = min(x + 1, dim.x - 1);\n" 115 " int ym = max(y - 1, 0);\n" 116 " int yp = min(y + 1, dim.y - 1);\n" 118 " // Sample the state at (x,y).\n" 119 " float4 state = inState[c];\n" 121 " // Sample Poisson values at immediate neighbors of (x,y).\n" 122 " float poisPZ = poisson[int2(xp, y)];\n" 123 " float poisMZ = poisson[int2(xm, y)];\n" 124 " float poisZP = poisson[int2(x, yp)];\n" 125 " float poisZM = poisson[int2(x, ym)];\n" 127 " float4 diff = float4(poisPZ - poisMZ, poisZP - poisZM, 0.0f, 0.0f);\n" 128 " outState[c] = state + halfDivDelta*diff;\n" Fluid2AdjustVelocity(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int numXThreads, int numYThreads, std::shared_ptr< ConstantBuffer > const ¶meters)
std::shared_ptr< ComputeProgram > mAdjustVelocity
GLsizei const GLchar *const * string
static std::string const msGLSLSource
void Execute(std::shared_ptr< GraphicsEngine > const &engine, std::shared_ptr< Texture2 > const &inState, std::shared_ptr< Texture2 > const &poisson, std::shared_ptr< Texture2 > const &outState)
static std::string const * msSource[ProgramFactory::PF_NUM_API]
static std::string const msHLSLSource