mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Cleanup.
This commit is contained in:
parent
d79eab89ea
commit
798dd30e9f
7 changed files with 84 additions and 85 deletions
|
@ -7,7 +7,7 @@
|
|||
#include "uniforms.sh"
|
||||
|
||||
BUFFER_WR(prevPositionBuffer, vec4, 0);
|
||||
BUFFER_WR(curPositionBuffer, vec4, 1);
|
||||
BUFFER_WR(currPositionBuffer, vec4, 1);
|
||||
|
||||
uint rotl(uint _x, uint _r)
|
||||
{
|
||||
|
@ -101,5 +101,5 @@ void main()
|
|||
vec3 velocity = u_initialSpeed * randomPointOnSphere(gl_GlobalInvocationID.x, u_baseSeed * 7u + 3u);
|
||||
|
||||
prevPositionBuffer[gl_GlobalInvocationID.x] = vec4(position - velocity * u_timeStep, 0.0);
|
||||
curPositionBuffer[ gl_GlobalInvocationID.x] = vec4(position, 0.0);
|
||||
currPositionBuffer[gl_GlobalInvocationID.x] = vec4(position, 0.0);
|
||||
}
|
||||
|
|
|
@ -7,16 +7,16 @@
|
|||
#include "uniforms.sh"
|
||||
|
||||
BUFFER_RO(prevPositionBuffer, vec4, 0);
|
||||
BUFFER_RO(curPositionBuffer, vec4, 1);
|
||||
BUFFER_RO(currPositionBuffer, vec4, 1);
|
||||
BUFFER_WR(outPrevPositionBuffer, vec4, 2);
|
||||
BUFFER_WR(outCurPositionBuffer, vec4, 3);
|
||||
BUFFER_WR(outCurrPositionBuffer, vec4, 3);
|
||||
|
||||
#define GROUP_SIZE 512
|
||||
SHARED vec3 otherEntries[GROUP_SIZE];
|
||||
|
||||
vec3 calcAcceleration(vec3 _curPosition, vec3 _otherPosition)
|
||||
vec3 calcAcceleration(vec3 _currPosition, vec3 _otherPosition)
|
||||
{
|
||||
vec3 difference = _otherPosition - _curPosition;
|
||||
vec3 difference = _otherPosition - _currPosition;
|
||||
float dist2 = dot(difference, difference);
|
||||
float dist6 = dist2 * dist2 * dist2;
|
||||
float invDist3 = 1.0 / (sqrt(dist6) + 0.1);
|
||||
|
@ -27,22 +27,22 @@ NUM_THREADS(GROUP_SIZE, 1, 1)
|
|||
void main()
|
||||
{
|
||||
vec3 prevPosition = prevPositionBuffer[gl_GlobalInvocationID.x].xyz;
|
||||
vec3 curPosition = curPositionBuffer[ gl_GlobalInvocationID.x].xyz;
|
||||
vec3 currPosition = currPositionBuffer[gl_GlobalInvocationID.x].xyz;
|
||||
|
||||
vec3 newAcceleration = vec3_splat(0.0);
|
||||
|
||||
for (int j = 0; j < int(u_dispatchSize); ++j)
|
||||
{
|
||||
otherEntries[gl_LocalInvocationIndex] = curPositionBuffer[j * GROUP_SIZE + int(gl_LocalInvocationIndex)].xyz;
|
||||
otherEntries[gl_LocalInvocationIndex] = currPositionBuffer[j * GROUP_SIZE + int(gl_LocalInvocationIndex)].xyz;
|
||||
|
||||
barrier();
|
||||
for (int i = 0; i < GROUP_SIZE; ++i)
|
||||
{
|
||||
newAcceleration += calcAcceleration(curPosition, otherEntries[i]);
|
||||
newAcceleration += calcAcceleration(currPosition, otherEntries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
newAcceleration += (prevPosition - curPosition) * u_damping;
|
||||
newAcceleration += (prevPosition - currPosition) * u_damping;
|
||||
float accelerationMagnitude = length(newAcceleration);
|
||||
float color = pow(min(accelerationMagnitude / 3.0, 1.0), 0.25);
|
||||
if (accelerationMagnitude > 0.0)
|
||||
|
@ -50,8 +50,8 @@ void main()
|
|||
newAcceleration = normalize(newAcceleration) * min(accelerationMagnitude, u_maxAcceleration);
|
||||
}
|
||||
|
||||
vec3 newPosition = 2.0 * curPosition - prevPosition + newAcceleration * u_timeStep;
|
||||
vec3 newPosition = 2.0 * currPosition - prevPosition + newAcceleration * u_timeStep;
|
||||
|
||||
outPrevPositionBuffer[gl_GlobalInvocationID.x] = vec4(curPosition, 0.0);
|
||||
outCurPositionBuffer[ gl_GlobalInvocationID.x] = vec4(newPosition, color);
|
||||
outPrevPositionBuffer[gl_GlobalInvocationID.x] = vec4(currPosition, 0.0);
|
||||
outCurrPositionBuffer[gl_GlobalInvocationID.x] = vec4(newPosition, color);
|
||||
}
|
||||
|
|
|
@ -22,67 +22,66 @@ struct u_paramsDataStruct
|
|||
float initialSpeed;
|
||||
int32_t initialShape;
|
||||
float maxAccel;
|
||||
|
||||
};
|
||||
|
||||
void InitializeParams(unsigned mode, u_paramsDataStruct * params)
|
||||
void InitializeParams(unsigned _mode, u_paramsDataStruct* _params)
|
||||
{
|
||||
switch(mode)
|
||||
switch(_mode)
|
||||
{
|
||||
case 0:
|
||||
params->timeStep = 0.0067f;
|
||||
params->dispatchSize = 32;
|
||||
params->gravity = 0.069f;
|
||||
params->damping = 0.0f;
|
||||
params->particleIntensity = 0.35f;
|
||||
params->particleSize = 0.925f;
|
||||
params->baseSeed = 0;
|
||||
params->particlePower = 5.0f;
|
||||
params->initialSpeed = 122.6f;
|
||||
params->initialShape = 0;
|
||||
params->maxAccel = 30.0;
|
||||
_params->timeStep = 0.0067f;
|
||||
_params->dispatchSize = 32;
|
||||
_params->gravity = 0.069f;
|
||||
_params->damping = 0.0f;
|
||||
_params->particleIntensity = 0.35f;
|
||||
_params->particleSize = 0.925f;
|
||||
_params->baseSeed = 0;
|
||||
_params->particlePower = 5.0f;
|
||||
_params->initialSpeed = 122.6f;
|
||||
_params->initialShape = 0;
|
||||
_params->maxAccel = 30.0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
params->timeStep = 0.0157f;
|
||||
params->dispatchSize = 32;
|
||||
params->gravity = 0.109f;
|
||||
params->damping = 0.25f;
|
||||
params->particleIntensity = 0.64f;
|
||||
params->particleSize = 0.279f;
|
||||
params->baseSeed = 57;
|
||||
params->particlePower = 3.5f;
|
||||
params->initialSpeed = 3.2f;
|
||||
params->initialShape = 1;
|
||||
params->maxAccel = 100.0;
|
||||
_params->timeStep = 0.0157f;
|
||||
_params->dispatchSize = 32;
|
||||
_params->gravity = 0.109f;
|
||||
_params->damping = 0.25f;
|
||||
_params->particleIntensity = 0.64f;
|
||||
_params->particleSize = 0.279f;
|
||||
_params->baseSeed = 57;
|
||||
_params->particlePower = 3.5f;
|
||||
_params->initialSpeed = 3.2f;
|
||||
_params->initialShape = 1;
|
||||
_params->maxAccel = 100.0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
params->timeStep = 0.02f;
|
||||
params->dispatchSize = 32;
|
||||
params->gravity = 0.24f;
|
||||
params->damping = 0.12f;
|
||||
params->particleIntensity = 1.0f;
|
||||
params->particleSize = 1.0f;
|
||||
params->baseSeed = 23;
|
||||
params->particlePower = 4.0f;
|
||||
params->initialSpeed = 31.1f;
|
||||
params->initialShape = 2;
|
||||
params->maxAccel = 39.29f;
|
||||
_params->timeStep = 0.02f;
|
||||
_params->dispatchSize = 32;
|
||||
_params->gravity = 0.24f;
|
||||
_params->damping = 0.12f;
|
||||
_params->particleIntensity = 1.0f;
|
||||
_params->particleSize = 1.0f;
|
||||
_params->baseSeed = 23;
|
||||
_params->particlePower = 4.0f;
|
||||
_params->initialSpeed = 31.1f;
|
||||
_params->initialShape = 2;
|
||||
_params->maxAccel = 39.29f;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
params->timeStep = 0.0118f;
|
||||
params->dispatchSize = 32;
|
||||
params->gravity = 0.141f;
|
||||
params->damping = 1.0f;
|
||||
params->particleIntensity = 0.64f;
|
||||
params->particleSize = 0.28f;
|
||||
params->baseSeed = 60;
|
||||
params->particlePower = 1.97f;
|
||||
params->initialSpeed = 69.7f;
|
||||
params->initialShape = 3;
|
||||
params->maxAccel = 3.21f;
|
||||
_params->timeStep = 0.0118f;
|
||||
_params->dispatchSize = 32;
|
||||
_params->gravity = 0.141f;
|
||||
_params->damping = 1.0f;
|
||||
_params->particleIntensity = 0.64f;
|
||||
_params->particleSize = 0.28f;
|
||||
_params->baseSeed = 60;
|
||||
_params->particlePower = 1.97f;
|
||||
_params->initialSpeed = 69.7f;
|
||||
_params->initialShape = 3;
|
||||
_params->maxAccel = 3.21f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue