16 int xSize,
int ySize,
int numXThreads,
int numYThreads)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads)
23 std::uniform_real_distribution<float> unirnd(0.0
f, 1.0
f);
28 for (
unsigned int i = 0; i <
mDensity->GetNumElements(); ++i, ++
data)
39 mStateTm1->SetUsage(Resource::SHADER_OUTPUT);
42 mStateT->SetUsage(Resource::SHADER_OUTPUT);
45 int i = factory->GetAPI();
46 factory->PushDefines();
47 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
48 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
55 cshader->Set(
"stateTm1", mStateTm1);
56 cshader->Set(
"stateT",
mStateT);
58 factory->PopDefines();
68 "layout(r32f) uniform readonly image2D density;\n" 69 "layout(rg32f) uniform readonly image2D velocity;\n" 70 "layout(rgba32f) uniform writeonly image2D stateTm1;\n" 71 "layout(rgba32f) uniform writeonly image2D stateT;\n" 73 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = 1) in;\n" 76 " ivec2 c = ivec2(gl_GlobalInvocationID.xy);\n" 77 " vec4 initial = vec4(imageLoad(velocity, c).xy, 0.0f, imageLoad(density, c).x);\n" 78 " imageStore(stateTm1, c, initial);\n" 79 " imageStore(stateT, c, initial);\n" 83 "Texture2D<float> density;\n" 84 "Texture2D<float2> velocity;\n" 85 "RWTexture2D<float4> stateTm1;\n" 86 "RWTexture2D<float4> stateT;\n" 88 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, 1)]\n" 89 "void CSMain(uint2 c : SV_DispatchThreadID)\n" 91 " float4 initial = float4(velocity[c], 0.0f, density[c]);\n" 92 " stateTm1[c] = initial;\n" 93 " stateT[c] = initial;\n"
static std::string const msHLSLSource
std::shared_ptr< Texture2 > mStateTm1
static std::string const msGLSLSource
std::shared_ptr< Texture2 > mVelocity
std::shared_ptr< Texture2 > mDensity
static std::string const * msSource[ProgramFactory::PF_NUM_API]
std::shared_ptr< ComputeProgram > mInitializeState
GLsizei const GLchar *const * string
std::shared_ptr< Texture2 > mStateT
Fluid2InitializeState(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int numXThreads, int numYThreads)
void Execute(std::shared_ptr< GraphicsEngine > const &engine)