16 int xSize,
int ySize,
int zSize,
int numXThreads,
int numYThreads,
int numZThreads)
18 mNumXGroups(xSize/numXThreads),
19 mNumYGroups(ySize/numYThreads),
20 mNumZGroups(zSize/numZThreads)
24 std::uniform_real_distribution<float> unirnd(0.0
f, 1.0
f);
29 for (
unsigned int i = 0; i <
mDensity->GetNumElements(); ++i, ++
data)
36 mVelocity->SetUsage(Resource::SHADER_OUTPUT);
40 mStateTm1->SetUsage(Resource::SHADER_OUTPUT);
43 mStateT->SetUsage(Resource::SHADER_OUTPUT);
46 int i = factory->GetAPI();
47 factory->PushDefines();
48 factory->defines.Set(
"NUM_X_THREADS", numXThreads);
49 factory->defines.Set(
"NUM_Y_THREADS", numYThreads);
50 factory->defines.Set(
"NUM_Z_THREADS", numZThreads);
57 cshader->Set(
"stateTm1", mStateTm1);
58 cshader->Set(
"stateT",
mStateT);
60 factory->PopDefines();
70 "layout(r32f) uniform readonly image3D density;\n" 71 "layout(rgba32f) uniform readonly image3D velocity;\n" 72 "layout(rgba32f) uniform writeonly image3D stateTm1;\n" 73 "layout(rgba32f) uniform writeonly image3D stateT;\n" 75 "layout (local_size_x = NUM_X_THREADS, local_size_y = NUM_Y_THREADS, local_size_z = NUM_Z_THREADS) in;\n" 78 " ivec3 c = ivec3(gl_GlobalInvocationID.xyz);\n" 79 " vec4 initial = vec4(imageLoad(velocity, c).xyz, imageLoad(density, c).x);\n" 80 " imageStore(stateTm1, c, initial);\n" 81 " imageStore(stateT, c, initial);\n" 85 "Texture3D<float> density;\n" 86 "Texture3D<float4> velocity;\n" 87 "RWTexture3D<float4> stateTm1;\n" 88 "RWTexture3D<float4> stateT;\n" 90 "[numthreads(NUM_X_THREADS, NUM_Y_THREADS, NUM_Z_THREADS)]\n" 91 "void CSMain(uint3 c : SV_DispatchThreadID)\n" 93 " float4 initial = float4(velocity[c].xyz, density[c]);\n" 94 " stateTm1[c] = initial;\n" 95 " stateT[c] = initial;\n" static std::string const * msSource[ProgramFactory::PF_NUM_API]
std::shared_ptr< ComputeProgram > mInitializeState
std::shared_ptr< Texture3 > mDensity
GLsizei const GLchar *const * string
std::shared_ptr< Texture3 > mVelocity
static std::string const msGLSLSource
Fluid3InitializeState(std::shared_ptr< ProgramFactory > const &factory, int xSize, int ySize, int zSize, int numXThreads, int numYThreads, int numZThreads)
static std::string const msHLSLSource
std::shared_ptr< Texture3 > mStateTm1
std::shared_ptr< Texture3 > mStateT
void Execute(std::shared_ptr< GraphicsEngine > const &engine)