15 int xSize,
int ySize,
int zSize,
int numXThreads,
int numYThreads,
16 int numZThreads, std::shared_ptr<ConstantBuffer>
const& parameters)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads),
20 mNumZGroups(zSize/numZThreads)
25 int i = factory->GetAPI();
26 factory->PushDefines();
27 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
28 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
29 factory->defines.Set(
"NUM_Z_THREADS", numZThreads);
37 factory->PopDefines();
41 std::shared_ptr<Texture3>
const& state)
44 cshader->Set(
"state", state);
50 "uniform Parameters\n" 52 " vec4 spaceDelta; // (dx, dy, dz, 0)\n" 53 " vec4 halfDivDelta; // (0.5/dx, 0.5/dy, 0.5/dz, 0)\n" 54 " vec4 timeDelta; // (dt/dx, dt/dy, dt/dz, dt)\n" 55 " vec4 viscosityX; // (velVX, velVX, velVX, denVX)\n" 56 " vec4 viscosityY; // (velVX, velVY, velVY, denVY)\n" 57 " vec4 viscosityZ; // (velVZ, velVZ, velVZ, denVZ)\n" 58 " vec4 epsilon; // (epsilonX, epsilonY, epsilonZ, epsilon0)\n" 61 "layout(rgba32f) uniform readonly image3D state;\n" 62 "layout(r32f) uniform writeonly image3D divergence;\n" 64 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = NUM_Z_THREADS) in;\n" 67 " ivec3 c = ivec3(gl_GlobalInvocationID.xyz);\n" 68 " ivec3 dim = imageSize(state);\n" 70 " int x = int(c.x);\n" 71 " int y = int(c.y);\n" 72 " int z = int(c.z);\n" 73 " int xm = max(x - 1, 0);\n" 74 " int xp = min(x + 1, dim.x - 1);\n" 75 " int ym = max(y - 1, 0);\n" 76 " int yp = min(y + 1, dim.y - 1);\n" 77 " int zm = max(z - 1, 0);\n" 78 " int zp = min(z + 1, dim.z - 1);\n" 80 " vec3 velocityGradient = vec3\n" 82 " imageLoad(state, ivec3(xp, y, z)).x - imageLoad(state, ivec3(xm, y, z)).x,\n" 83 " imageLoad(state, ivec3(x, yp, z)).y - imageLoad(state, ivec3(x, ym, z)).y,\n" 84 " imageLoad(state, ivec3(x, y, zp)).z - imageLoad(state, ivec3(x, y, zm)).z\n" 87 " float divergenceValue = dot(halfDivDelta.xyz, velocityGradient);\n" 88 " imageStore(divergence, c, vec4(divergenceValue, 0.0f, 0.0f, 0.0f));\n" 92 "cbuffer Parameters\n" 94 " float4 spaceDelta; // (dx, dy, dz, 0)\n" 95 " float4 halfDivDelta; // (0.5/dx, 0.5/dy, 0.5/dz, 0)\n" 96 " float4 timeDelta; // (dt/dx, dt/dy, dt/dz, dt)\n" 97 " float4 viscosityX; // (velVX, velVX, velVX, denVX)\n" 98 " float4 viscosityY; // (velVX, velVY, velVY, denVY)\n" 99 " float4 viscosityZ; // (velVZ, velVZ, velVZ, denVZ)\n" 100 " float4 epsilon; // (epsilonX, epsilonY, epsilonZ, epsilon0)\n" 103 "Texture3D<float4> state;\n" 104 "RWTexture3D<float> divergence;\n" 106 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, NUM_Z_THREADS)]\n" 107 "void CSMain(uint3 c : SV_DispatchThreadID)\n" 110 " state.GetDimensions(dim.x, dim.y, dim.z);\n" 112 " int x = int(c.x);\n" 113 " int y = int(c.y);\n" 114 " int z = int(c.z);\n" 115 " int xm = max(x - 1, 0);\n" 116 " int xp = min(x + 1, dim.x - 1);\n" 117 " int ym = max(y - 1, 0);\n" 118 " int yp = min(y + 1, dim.y - 1);\n" 119 " int zm = max(z - 1, 0);\n" 120 " int zp = min(z + 1, dim.z - 1);\n" 122 " float3 velocityGradient = float3\n" 124 " state[int3(xp, y, z)].x - state[int3(xm, y, z)].x,\n" 125 " state[int3(x, yp, z)].y - state[int3(x, ym, z)].y,\n" 126 " state[int3(x, y, zp)].z - state[int3(x, y, zm)].z\n" 129 " divergence[c] = dot(halfDivDelta.xyz, velocityGradient);\n"
void Execute(std::shared_ptr< GraphicsEngine > const &engine, std::shared_ptr< Texture3 > const &state)
Fluid3ComputeDivergence(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int zSize, int numXThreads, int numYThreads, int numZThreads, std::shared_ptr< ConstantBuffer > const ¶meters)
std::shared_ptr< ComputeProgram > mComputeDivergence
static std::string const * msSource[ProgramFactory::PF_NUM_API]
GLsizei const GLchar *const * string
std::shared_ptr< Texture3 > mDivergence
static std::string const msGLSLSource
static std::string const msHLSLSource