15 int xSize,
int ySize,
int zSize,
int numXThreads,
int numYThreads,
int numZThreads,
16 std::shared_ptr<ConstantBuffer>
const& parameters)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads),
20 mNumZGroups(zSize/numZThreads)
22 int i = factory->GetAPI();
23 factory->PushDefines();
24 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
25 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
26 factory->defines.Set(
"NUM_Z_THREADS", numZThreads);
34 factory->PopDefines();
38 std::shared_ptr<Texture3>
const& inState,
39 std::shared_ptr<Texture3>
const& poisson,
40 std::shared_ptr<Texture3>
const& outState)
43 cshader->Set(
"inState", inState);
44 cshader->Set(
"poisson", poisson);
45 cshader->Set(
"outState", outState);
51 "uniform Parameters\n" 53 " vec4 spaceDelta; // (dx, dy, dz, 0)\n" 54 " vec4 halfDivDelta; // (0.5/dx, 0.5/dy, 0.5/dz, 0)\n" 55 " vec4 timeDelta; // (dt/dx, dt/dy, dt/dz, dt)\n" 56 " vec4 viscosityX; // (velVX, velVX, velVX, denVX)\n" 57 " vec4 viscosityY; // (velVX, velVY, velVY, denVY)\n" 58 " vec4 viscosityZ; // (velVZ, velVZ, velVZ, denVZ)\n" 59 " vec4 epsilon; // (epsilonX, epsilonY, epsilonZ, epsilon0)\n" 62 "layout(rgba32f) uniform readonly image3D inState;\n" 63 "layout(r32f) uniform readonly image3D poisson;\n" 64 "layout(rgba32f) uniform writeonly image3D outState;\n" 66 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = NUM_Z_THREADS) in;\n" 69 " ivec3 c = ivec3(gl_GlobalInvocationID.xyz);\n" 70 " ivec3 dim = imageSize(inState);\n" 72 " int x = int(c.x);\n" 73 " int y = int(c.y);\n" 74 " int z = int(c.z);\n" 75 " int xm = max(x - 1, 0);\n" 76 " int xp = min(x + 1, dim.x - 1);\n" 77 " int ym = max(y - 1, 0);\n" 78 " int yp = min(y + 1, dim.y - 1);\n" 79 " int zm = max(z - 1, 0);\n" 80 " int zp = min(z + 1, dim.z - 1);\n" 82 " // Sample the state at (x,y,z).\n" 83 " vec4 state = imageLoad(inState, c);\n" 85 " // Sample Poisson values at immediate neighbors of (x,y,z).\n" 86 " float poisPZZ = imageLoad(poisson, ivec3(xp, y, z)).x;\n" 87 " float poisMZZ = imageLoad(poisson, ivec3(xm, y, z)).x;\n" 88 " float poisZPZ = imageLoad(poisson, ivec3(x, yp, z)).x;\n" 89 " float poisZMZ = imageLoad(poisson, ivec3(x, ym, z)).x;\n" 90 " float poisZZP = imageLoad(poisson, ivec3(x, y, zp)).x;\n" 91 " float poisZZM = imageLoad(poisson, ivec3(x, y, zm)).x;\n" 93 " vec4 diff = vec4(poisPZZ - poisMZZ, poisZPZ - poisZMZ, poisZZP - poisZZM, 0.0f);\n" 94 " imageStore(outState, c, state + halfDivDelta*diff);\n" 98 "cbuffer Parameters\n" 100 " float4 spaceDelta; // (dx, dy, dz, 0)\n" 101 " float4 halfDivDelta; // (0.5/dx, 0.5/dy, 0.5/dz, 0)\n" 102 " float4 timeDelta; // (dt/dx, dt/dy, dt/dz, dt)\n" 103 " float4 viscosityX; // (velVX, velVX, velVX, denVX)\n" 104 " float4 viscosityY; // (velVX, velVY, velVY, denVY)\n" 105 " float4 viscosityZ; // (velVZ, velVZ, velVZ, denVZ)\n" 106 " float4 epsilon; // (epsilonX, epsilonY, epsilonZ, epsilon0)\n" 109 "Texture3D<float4> inState;\n" 110 "Texture3D<float> poisson;\n" 111 "RWTexture3D<float4> outState;\n" 113 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, NUM_Z_THREADS)]\n" 114 "void CSMain(uint3 c : SV_DispatchThreadID)\n" 117 " inState.GetDimensions(dim.x, dim.y, dim.z);\n" 119 " int x = int(c.x);\n" 120 " int y = int(c.y);\n" 121 " int z = int(c.z);\n" 122 " int xm = max(x - 1, 0);\n" 123 " int xp = min(x + 1, dim.x - 1);\n" 124 " int ym = max(y - 1, 0);\n" 125 " int yp = min(y + 1, dim.y - 1);\n" 126 " int zm = max(z - 1, 0);\n" 127 " int zp = min(z + 1, dim.z - 1);\n" 129 " // Sample the state at (x,y,z).\n" 130 " float4 state = inState[c];\n" 132 " // Sample Poisson values at immediate neighbors of (x,y,z).\n" 133 " float poisPZZ = poisson[int3(xp, y, z)];\n" 134 " float poisMZZ = poisson[int3(xm, y, z)];\n" 135 " float poisZPZ = poisson[int3(x, yp, z)];\n" 136 " float poisZMZ = poisson[int3(x, ym, z)];\n" 137 " float poisZZP = poisson[int3(x, y, zp)];\n" 138 " float poisZZM = poisson[int3(x, y, zm)];\n" 140 " float4 diff = float4(poisPZZ - poisMZZ, poisZPZ - poisZMZ, poisZZP - poisZZM, 0.0f);\n" 141 " outState[c] = state + halfDivDelta*diff;\n"
void Execute(std::shared_ptr< GraphicsEngine > const &engine, std::shared_ptr< Texture3 > const &inState, std::shared_ptr< Texture3 > const &poisson, std::shared_ptr< Texture3 > const &outState)
static std::string const msGLSLSource
std::shared_ptr< ComputeProgram > mAdjustVelocity
GLsizei const GLchar *const * string
static std::string const msHLSLSource
static std::string const * msSource[ProgramFactory::PF_NUM_API]
Fluid3AdjustVelocity(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int zSize, int numXThreads, int numYThreads, int numZThreads, std::shared_ptr< ConstantBuffer > const ¶meters)