struct SimulationParams_std140_0
{
@align(16) gravity_0 : vec2<f32>,
@align(8) padding_0 : f32,
@align(4) dt_0 : f32,
};
@binding(0) @group(0) var<uniform> entryPointParams_params_0 : SimulationParams_std140_0;
struct GridGeneric_std430_0
{
@align(4) num_active_blocks_0 : u32,
@align(4) cell_width_0 : f32,
@align(4) hmap_capacity_0 : u32,
@align(4) capacity_0 : u32,
};
@binding(1) @group(0) var<storage, read> entryPointParams_grid_0 : array<GridGeneric_std430_0>;
struct DruckerPragerPlasticity_std430_0
{
@align(4) ha_0 : f32,
@align(4) hb_0 : f32,
@align(4) hc_0 : f32,
@align(4) hd_0 : f32,
@align(4) lambda_0 : f32,
@align(4) mu_0 : f32,
};
@binding(2) @group(0) var<storage, read> entryPointParams_plasticity_0 : array<DruckerPragerPlasticity_std430_0>;
struct LinearElasticCoefficients_std430_0
{
@align(4) lambda_1 : f32,
@align(4) mu_1 : f32,
};
@binding(3) @group(0) var<storage, read> entryPointParams_constitutive_model_0 : array<LinearElasticCoefficients_std430_0>;
struct DruckerPragerPlasticState_std430_0
{
@align(4) plastic_deformation_gradient_det_0 : f32,
@align(4) plastic_hardening_0 : f32,
@align(4) log_vol_gain_0 : f32,
};
@binding(4) @group(0) var<storage, read_write> entryPointParams_plastic_state_0 : array<DruckerPragerPlasticState_std430_0>;
struct Position_std430_0
{
@align(8) pt_0 : vec2<f32>,
};
@binding(5) @group(0) var<storage, read_write> entryPointParams_particles_pos_0 : array<Position_std430_0>;
struct _MatrixStorage_float2x2std430_0
{
@align(8) data_0 : array<vec2<f32>, i32(2)>,
};
struct Cdf_std430_0
{
@align(8) normal_0 : vec2<f32>,
@align(8) rigid_vel_0 : vec2<f32>,
@align(8) signed_distance_0 : f32,
@align(4) affinity_0 : u32,
};
struct Dynamics_std430_0
{
@align(8) velocity_0 : vec2<f32>,
@align(8) def_grad_0 : _MatrixStorage_float2x2std430_0,
@align(8) affine_0 : _MatrixStorage_float2x2std430_0,
@align(8) cdf_0 : Cdf_std430_0,
@align(8) init_volume_0 : f32,
@align(4) init_radius_0 : f32,
@align(8) mass_0 : f32,
};
@binding(6) @group(0) var<storage, read_write> entryPointParams_particles_dyn_0 : array<Dynamics_std430_0>;
struct Phase_std430_0
{
@align(4) phase_0 : f32,
@align(4) max_stretch_0 : f32,
};
@binding(7) @group(0) var<storage, read_write> entryPointParams_phases_0 : array<Phase_std430_0>;
fn project_velocity_0( vel_0 : vec2<f32>, n_0 : vec2<f32>) -> vec2<f32>
{
var _S1 : f32 = dot(vel_0, n_0);
if(_S1 < 0.0f)
{
var _S2 : vec2<f32> = vel_0 - n_0 * vec2<f32>(_S1);
var _S3 : f32 = length(_S2);
return select(vec2<f32>(0.0f), _S2 / vec2<f32>(_S3), _S3 > 9.99999993922529029e-09f) * vec2<f32>(max(0.0f, _S3 + 20.0f * _S1));
}
else
{
return vel_0;
}
}
fn stable_atan2_0( y_0 : f32, x_0 : f32) -> f32
{
var _S4 : f32 = atan(y_0 / x_0);
if(x_0 > 0.0f)
{
return _S4;
}
var _S5 : bool = x_0 < 0.0f;
var _S6 : bool;
if(_S5)
{
_S6 = y_0 > 0.0f;
}
else
{
_S6 = false;
}
if(_S6)
{
return _S4 + 3.14159274101257324f;
}
if(_S5)
{
_S6 = y_0 < 0.0f;
}
else
{
_S6 = false;
}
if(_S6)
{
return _S4 - 3.14159274101257324f;
}
return 0.0f;
}
struct Svd2_0
{
U_0 : mat2x2<f32>,
S_0 : vec2<f32>,
Vt_0 : mat2x2<f32>,
};
fn Svd2_x24init_0( U_1 : mat2x2<f32>, S_1 : vec2<f32>, Vt_1 : mat2x2<f32>) -> Svd2_0
{
var _S7 : Svd2_0;
_S7.U_0 = U_1;
_S7.S_0 = S_1;
_S7.Vt_0 = Vt_1;
return _S7;
}
fn Svd2_x24init_1( m_0 : mat2x2<f32>) -> Svd2_0
{
var _S8 : f32 = m_0[i32(0)].x;
var _S9 : f32 = m_0[i32(1)].y;
var _S10 : f32 = (_S8 + _S9) * 0.5f;
var _S11 : f32 = (_S8 - _S9) * 0.5f;
var _S12 : f32 = m_0[i32(0)].y;
var _S13 : f32 = m_0[i32(1)].x;
var _S14 : f32 = (_S12 + _S13) * 0.5f;
var _S15 : f32 = (_S12 - _S13) * 0.5f;
var _S16 : f32 = sqrt(_S10 * _S10 + _S15 * _S15);
var _S17 : f32 = sqrt(_S11 * _S11 + _S14 * _S14);
var _S18 : f32 = _S16 - _S17;
var _S19 : f32 = select(1.0f, -1.0f, _S18 < 0.0f);
var _S20 : vec2<f32> = vec2<f32>(_S16 + _S17, _S18 * _S19);
var _S21 : f32 = stable_atan2_0(_S14, _S11);
var _S22 : f32 = stable_atan2_0(_S15, _S10);
var _S23 : f32 = (_S22 - _S21) * 0.5f;
var _S24 : f32 = (_S22 + _S21) * 0.5f;
var _S25 : f32 = sin(_S23);
var _S26 : f32 = cos(_S23);
var _S27 : f32 = sin(_S24);
var _S28 : f32 = cos(_S24);
var _S29 : mat2x2<f32> = mat2x2<f32>(vec2<f32>(_S28, _S27), vec2<f32>(- _S27, _S28));
var _S30 : mat2x2<f32> = mat2x2<f32>(vec2<f32>(_S26, _S25 * _S19), vec2<f32>(- _S25, _S26 * _S19));
var _S31 : Svd2_0;
_S31.U_0 = _S29;
_S31.S_0 = _S20;
_S31.Vt_0 = _S30;
var _S32 : Svd2_0 = Svd2_x24init_0(_S29, _S20, _S30);
_S31 = _S32;
return _S32;
}
struct DruckerPragerPlasticState_0
{
@align(4) plastic_deformation_gradient_det_0 : f32,
@align(4) plastic_hardening_0 : f32,
@align(4) log_vol_gain_0 : f32,
};
struct DruckerPragerResult_0
{
state_0 : DruckerPragerPlasticState_0,
deformation_gradient_0 : mat2x2<f32>,
};
fn DruckerPragerResult_x24init_0( state_1 : DruckerPragerPlasticState_0, deformation_gradient_1 : mat2x2<f32>) -> DruckerPragerResult_0
{
var _S33 : DruckerPragerResult_0;
_S33.state_0 = state_1;
_S33.deformation_gradient_0 = deformation_gradient_1;
return _S33;
}
struct DruckerPragerPlasticity_0
{
@align(4) ha_0 : f32,
@align(4) hb_0 : f32,
@align(4) hc_0 : f32,
@align(4) hd_0 : f32,
@align(4) lambda_0 : f32,
@align(4) mu_0 : f32,
};
fn DruckerPragerPlasticity_alpha_0( this_0 : DruckerPragerPlasticity_0, q_0 : f32) -> f32
{
var _S34 : f32 = sin(this_0.ha_0 + (this_0.hb_0 * q_0 - this_0.hd_0) * exp(- this_0.hc_0 * q_0));
return sqrt(0.66666668653488159f) * (2.0f * _S34) / (3.0f - _S34);
}
struct DruckerPragerProjectionResult_0
{
singular_values_0 : vec2<f32>,
plastic_hardening_1 : f32,
valid_0 : bool,
};
fn DruckerPragerProjectionResult_x24init_0( singular_values_1 : vec2<f32>, plastic_hardening_2 : f32, valid_1 : bool) -> DruckerPragerProjectionResult_0
{
var _S35 : DruckerPragerProjectionResult_0;
_S35.singular_values_0 = singular_values_1;
_S35.plastic_hardening_1 = plastic_hardening_2;
_S35.valid_0 = valid_1;
return _S35;
}
fn DruckerPragerPlasticity_project_deformation_gradient_0( this_1 : DruckerPragerPlasticity_0, singular_values_2 : vec2<f32>, log_vol_gain_1 : f32, alpha_0 : f32) -> DruckerPragerProjectionResult_0
{
var _S36 : vec2<f32> = log(singular_values_2) + vec2<f32>((log_vol_gain_1 / 2.0f));
var _S37 : f32 = _S36.x + _S36.y;
var _S38 : vec2<f32> = _S36 - vec2<f32>((_S37 / 2.0f));
var _S39 : bool;
if(_S37 > 0.0f)
{
_S39 = true;
}
else
{
_S39 = all(_S38 == vec2<f32>(0.0f));
}
if(_S39)
{
return DruckerPragerProjectionResult_x24init_0(vec2<f32>(1.0f), length(_S36), true);
}
var _S40 : f32 = length(_S38);
var _S41 : f32 = 2.0f * this_1.mu_0;
var _S42 : f32 = _S40 + (2.0f * this_1.lambda_0 + _S41) / _S41 * _S37 * alpha_0;
if(_S42 <= 0.0f)
{
return DruckerPragerProjectionResult_x24init_0(vec2<f32>(0.0f), 0.0f, false);
}
return DruckerPragerProjectionResult_x24init_0(exp(_S36 - _S38 * vec2<f32>((_S42 / _S40))), _S42, true);
}
fn Svd2_recompose_0( this_2 : Svd2_0) -> mat2x2<f32>
{
return (((mat2x2<f32>(this_2.U_0[i32(0)] * vec2<f32>(this_2.S_0.x), this_2.U_0[i32(1)] * vec2<f32>(this_2.S_0.y))) * (this_2.Vt_0)));
}
fn DruckerPragerPlasticState_x24init_0( plastic_deformation_gradient_det_1 : f32, plastic_hardening_3 : f32, log_vol_gain_2 : f32) -> DruckerPragerPlasticState_0
{
var _S43 : DruckerPragerPlasticState_0;
_S43.plastic_deformation_gradient_det_0 = plastic_deformation_gradient_det_1;
_S43.plastic_hardening_0 = plastic_hardening_3;
_S43.log_vol_gain_0 = log_vol_gain_2;
return _S43;
}
fn DruckerPragerPlasticity_project_0( this_3 : DruckerPragerPlasticity_0, state_2 : DruckerPragerPlasticState_0, deformation_gradient_2 : mat2x2<f32>) -> DruckerPragerResult_0
{
if((this_3.lambda_0) == 0.0f)
{
return DruckerPragerResult_x24init_0(state_2, deformation_gradient_2);
}
var _S44 : Svd2_0 = Svd2_x24init_1(deformation_gradient_2);
var _S45 : DruckerPragerProjectionResult_0 = DruckerPragerPlasticity_project_deformation_gradient_0(this_3, _S44.S_0, state_2.log_vol_gain_0, DruckerPragerPlasticity_alpha_0(this_3, state_2.plastic_hardening_0));
if(_S45.valid_0)
{
var _S46 : f32 = _S44.S_0.x * _S44.S_0.y;
var _S47 : f32 = _S45.singular_values_0.x * _S45.singular_values_0.y;
return DruckerPragerResult_x24init_0(DruckerPragerPlasticState_x24init_0(state_2.plastic_deformation_gradient_det_0 * _S46 / _S47, state_2.plastic_hardening_0 + _S45.plastic_hardening_1, state_2.log_vol_gain_0 + log(_S46) - log(_S47)), Svd2_recompose_0(Svd2_x24init_0(_S44.U_0, _S45.singular_values_0, _S44.Vt_0)));
}
else
{
return DruckerPragerResult_x24init_0(state_2, deformation_gradient_2);
}
}
struct LinearElasticCoefficients_0
{
@align(4) lambda_1 : f32,
@align(4) mu_1 : f32,
};
fn LinearElasticCoefficients_kirchoff_stress_0( this_4 : LinearElasticCoefficients_0, deformation_gradient_3 : mat2x2<f32>) -> mat2x2<f32>
{
var svd_0 : Svd2_0 = Svd2_x24init_1(deformation_gradient_3);
var _S48 : f32 = svd_0.S_0.x * svd_0.S_0.y;
svd_0.S_0 = svd_0.S_0 - vec2<f32>(1.0f);
var _S49 : f32 = this_4.lambda_1 * (_S48 - 1.0f) * _S48;
var _S50 : mat2x2<f32> = (((Svd2_recompose_0(svd_0)) * (transpose(deformation_gradient_3))));
var _S51 : mat2x2<f32> = mat2x2<f32>(2.0f * this_4.mu_1, 2.0f * this_4.mu_1, 2.0f * this_4.mu_1, 2.0f * this_4.mu_1);
var result_0 : mat2x2<f32> = mat2x2<f32>(_S50[0] * _S51[0], _S50[1] * _S51[1]);
result_0[i32(0)][i32(0)] = result_0[i32(0)][i32(0)] + _S49;
result_0[i32(1)][i32(1)] = result_0[i32(1)][i32(1)] + _S49;
return result_0;
}
fn QuadraticKernel_inv_d_0( cell_width_1 : f32) -> f32
{
return 4.0f / (cell_width_1 * cell_width_1);
}
fn getCount_0() -> i32
{
var _S52 : vec2<u32> = vec2<u32>(arrayLength(&entryPointParams_particles_pos_0), 8);
return i32(_S52.x);
}
@compute
@workgroup_size(64, 1, 1)
fn particle_update(@builtin(global_invocation_id) invocation_id_0 : vec3<u32>)
{
var _S53 : u32 = invocation_id_0.x;
var _S54 : i32 = getCount_0();
if(_S53 >= u32(_S54))
{
return;
}
var _S55 : f32 = entryPointParams_params_0.dt_0;
var _S56 : f32 = entryPointParams_grid_0[i32(0)].cell_width_0;
var _S57 : vec2<f32> = entryPointParams_particles_dyn_0[_S53].velocity_0;
var _S58 : mat2x2<f32> = mat2x2<f32>(entryPointParams_particles_dyn_0[_S53].def_grad_0.data_0[i32(0)][i32(0)], entryPointParams_particles_dyn_0[_S53].def_grad_0.data_0[i32(0)][i32(1)], entryPointParams_particles_dyn_0[_S53].def_grad_0.data_0[i32(1)][i32(0)], entryPointParams_particles_dyn_0[_S53].def_grad_0.data_0[i32(1)][i32(1)]);
var _S59 : mat2x2<f32> = mat2x2<f32>(entryPointParams_particles_dyn_0[_S53].affine_0.data_0[i32(0)][i32(0)], entryPointParams_particles_dyn_0[_S53].affine_0.data_0[i32(0)][i32(1)], entryPointParams_particles_dyn_0[_S53].affine_0.data_0[i32(1)][i32(0)], entryPointParams_particles_dyn_0[_S53].affine_0.data_0[i32(1)][i32(1)]);
var _S60 : vec2<f32> = entryPointParams_particles_dyn_0[_S53].cdf_0.normal_0;
var _S61 : vec2<f32> = entryPointParams_particles_dyn_0[_S53].cdf_0.rigid_vel_0;
var _S62 : f32 = entryPointParams_particles_dyn_0[_S53].cdf_0.signed_distance_0;
var _S63 : f32 = entryPointParams_particles_dyn_0[_S53].init_volume_0;
var _S64 : f32 = entryPointParams_particles_dyn_0[_S53].mass_0;
var _S65 : vec2<f32> = entryPointParams_particles_pos_0[_S53].pt_0;
var _S66 : bool = (entryPointParams_particles_dyn_0[_S53].cdf_0.signed_distance_0) < (-0.05000000074505806f * entryPointParams_grid_0[i32(0)].cell_width_0);
var new_particle_vel_0 : vec2<f32>;
if(_S66)
{
new_particle_vel_0 = _S61 + project_velocity_0(_S57 - _S61, _S60);
}
else
{
new_particle_vel_0 = _S57;
}
var _S67 : f32 = length(new_particle_vel_0);
if(_S67 > (_S56 / _S55))
{
new_particle_vel_0 = new_particle_vel_0 / vec2<f32>(_S67) * vec2<f32>(_S56) / vec2<f32>(_S55);
}
else
{
}
var _S68 : vec2<f32> = _S65 + new_particle_vel_0 * vec2<f32>(_S55);
if(_S66)
{
new_particle_vel_0 = new_particle_vel_0 + vec2<f32>((_S55 * - max(_S62, -0.30000001192092896f * _S56) * 1000.0f)) * _S60;
}
else
{
}
var _S69 : mat2x2<f32> = mat2x2<f32>(_S55, _S55, _S55, _S55);
var _S70 : mat2x2<f32> = _S58 + (((mat2x2<f32>(_S59[0] * _S69[0], _S59[1] * _S69[1])) * (_S58)));
var phase_1 : f32 = entryPointParams_phases_0[_S53].phase_0;
var _S71 : f32 = entryPointParams_phases_0[_S53].max_stretch_0;
var _S72 : bool;
if((entryPointParams_phases_0[_S53].phase_0) > 0.0f)
{
_S72 = _S71 > 0.0f;
}
else
{
_S72 = false;
}
var phase_2 : f32;
if(_S72)
{
var _S73 : Svd2_0 = Svd2_x24init_1(_S70);
if((_S73.S_0.x) > _S71)
{
_S72 = true;
}
else
{
_S72 = (_S73.S_0.y) > _S71;
}
if(_S72)
{
entryPointParams_phases_0[_S53].phase_0 = 0.0f;
phase_2 = 0.0f;
}
else
{
phase_2 = phase_1;
}
}
else
{
phase_2 = phase_1;
}
var new_deformation_gradient_0 : mat2x2<f32>;
if(phase_2 == 0.0f)
{
var _S74 : DruckerPragerPlasticity_0 = DruckerPragerPlasticity_0( entryPointParams_plasticity_0[_S53].ha_0, entryPointParams_plasticity_0[_S53].hb_0, entryPointParams_plasticity_0[_S53].hc_0, entryPointParams_plasticity_0[_S53].hd_0, entryPointParams_plasticity_0[_S53].lambda_0, entryPointParams_plasticity_0[_S53].mu_0 );
var _S75 : DruckerPragerPlasticState_0 = DruckerPragerPlasticState_0( entryPointParams_plastic_state_0[_S53].plastic_deformation_gradient_det_0, entryPointParams_plastic_state_0[_S53].plastic_hardening_0, entryPointParams_plastic_state_0[_S53].log_vol_gain_0 );
var _S76 : DruckerPragerResult_0 = DruckerPragerPlasticity_project_0(_S74, _S75, _S70);
entryPointParams_plastic_state_0[_S53].plastic_deformation_gradient_det_0 = _S76.state_0.plastic_deformation_gradient_det_0;
entryPointParams_plastic_state_0[_S53].plastic_hardening_0 = _S76.state_0.plastic_hardening_0;
entryPointParams_plastic_state_0[_S53].log_vol_gain_0 = _S76.state_0.log_vol_gain_0;
new_deformation_gradient_0 = _S76.deformation_gradient_0;
}
else
{
new_deformation_gradient_0 = _S70;
}
var _S77 : LinearElasticCoefficients_0 = LinearElasticCoefficients_0( entryPointParams_constitutive_model_0[_S53].lambda_1, entryPointParams_constitutive_model_0[_S53].mu_1 );
var _S78 : mat2x2<f32> = LinearElasticCoefficients_kirchoff_stress_0(_S77, new_deformation_gradient_0);
var _S79 : mat2x2<f32> = mat2x2<f32>(_S64, _S64, _S64, _S64);
var _S80 : mat2x2<f32> = mat2x2<f32>(_S63 * QuadraticKernel_inv_d_0(_S56) * _S55, _S63 * QuadraticKernel_inv_d_0(_S56) * _S55, _S63 * QuadraticKernel_inv_d_0(_S56) * _S55, _S63 * QuadraticKernel_inv_d_0(_S56) * _S55);
var _S81 : mat2x2<f32> = mat2x2<f32>(_S59[0] * _S79[0], _S59[1] * _S79[1]) - mat2x2<f32>(_S78[0] * _S80[0], _S78[1] * _S80[1]);
entryPointParams_particles_pos_0[_S53].pt_0 = _S68;
entryPointParams_particles_dyn_0[_S53].velocity_0 = new_particle_vel_0;
var _S82 : array<vec2<f32>, i32(2)> = array<vec2<f32>, i32(2)>( vec2<f32>(new_deformation_gradient_0[i32(0)][i32(0)], new_deformation_gradient_0[i32(0)][i32(1)]), vec2<f32>(new_deformation_gradient_0[i32(1)][i32(0)], new_deformation_gradient_0[i32(1)][i32(1)]) );
entryPointParams_particles_dyn_0[_S53].def_grad_0.data_0 = _S82;
var _S83 : array<vec2<f32>, i32(2)> = array<vec2<f32>, i32(2)>( vec2<f32>(_S81[i32(0)][i32(0)], _S81[i32(0)][i32(1)]), vec2<f32>(_S81[i32(1)][i32(0)], _S81[i32(1)][i32(1)]) );
entryPointParams_particles_dyn_0[_S53].affine_0.data_0 = _S83;
return;
}