15 int xSize,
int ySize,
int numXThreads,
int numYThreads,
16 std::shared_ptr<ConstantBuffer>
const& parameters)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads)
24 int i = factory->GetAPI();
25 factory->PushDefines();
26 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
27 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
35 factory->PopDefines();
39 std::shared_ptr<Texture2>
const& state)
42 cshader->Set(
"state", state);
48 "uniform Parameters\n" 50 " vec4 spaceDelta; // (dx, dy, 0, 0)\n" 51 " vec4 halfDivDelta; // (0.5/dx, 0.5/dy, 0, 0)\n" 52 " vec4 timeDelta; // (dt/dx, dt/dy, 0, dt)\n" 53 " vec4 viscosityX; // (velVX, velVX, 0, denVX)\n" 54 " vec4 viscosityY; // (velVX, velVY, 0, denVY)\n" 55 " vec4 epsilon; // (epsilonX, epsilonY, 0, epsilon0)\n" 58 "layout(rgba32f) uniform readonly image2D state;\n" 59 "layout(r32f) uniform writeonly image2D divergence;\n" 61 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = 1) in;\n" 64 " ivec2 c = ivec2(gl_GlobalInvocationID.xy);\n" 65 " ivec2 dim = imageSize(state);\n" 67 " int x = int(c.x);\n" 68 " int y = int(c.y);\n" 69 " int xm = max(x - 1, 0);\n" 70 " int xp = min(x + 1, dim.x - 1);\n" 71 " int ym = max(y - 1, 0);\n" 72 " int yp = min(y + 1, dim.y - 1);\n" 74 " vec2 velocityGradient = vec2\n" 76 " imageLoad(state, ivec2(xp, y)).x - imageLoad(state, ivec2(xm, y)).x,\n" 77 " imageLoad(state, ivec2(x, yp)).y - imageLoad(state, ivec2(x, ym)).y\n" 80 " float divergenceValue = dot(halfDivDelta.xy, velocityGradient);\n" 81 " imageStore(divergence, c, vec4(divergenceValue, 0.0f, 0.0f, 0.0f));\n" 85 "cbuffer Parameters\n" 87 " float4 spaceDelta; // (dx, dy, 0, 0)\n" 88 " float4 halfDivDelta; // (0.5/dx, 0.5/dy, 0, 0)\n" 89 " float4 timeDelta; // (dt/dx, dt/dy, 0, dt)\n" 90 " float4 viscosityX; // (velVX, velVX, 0, denVX)\n" 91 " float4 viscosityY; // (velVX, velVY, 0, denVY)\n" 92 " float4 epsilon; // (epsilonX, epsilonY, 0, epsilon0)\n" 95 "Texture2D<float4> state;\n" 96 "RWTexture2D<float> divergence;\n" 98 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, 1)]\n" 99 "void CSMain(uint2 c : SV_DispatchThreadID)\n" 102 " state.GetDimensions(dim.x, dim.y);\n" 104 " int x = int(c.x);\n" 105 " int y = int(c.y);\n" 106 " int xm = max(x - 1, 0);\n" 107 " int xp = min(x + 1, dim.x - 1);\n" 108 " int ym = max(y - 1, 0);\n" 109 " int yp = min(y + 1, dim.y - 1);\n" 111 " float2 velocityGradient = float2(\n" 112 " state[int2(xp, y)].x - state[int2(xm, y)].x,\n" 113 " state[int2(x, yp)].y - state[int2(x, ym)].y\n" 116 " divergence[c] = dot(halfDivDelta.xy, velocityGradient);\n"
static std::string const msHLSLSource
static std::string const * msSource[ProgramFactory::PF_NUM_API]
std::shared_ptr< Texture2 > mDivergence
Fluid2ComputeDivergence(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int numXThreads, int numYThreads, std::shared_ptr< ConstantBuffer > const ¶meters)
GLsizei const GLchar *const * string
static std::string const msGLSLSource
void Execute(std::shared_ptr< GraphicsEngine > const &engine, std::shared_ptr< Texture2 > const &state)
std::shared_ptr< ComputeProgram > mComputeDivergence