-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up DynamicStrands simulation pipeline. (#13)
The correction step simply create chaos... But at least it's moving strand segments now, incorrectly corrected though.
- Loading branch information
1 parent
2da68e8
commit ac3c0be
Showing
21 changed files
with
2,159 additions
and
486 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...coSysLabResources/Shaders/Compute/DynamicStrands/Constraints/StiffRodInitConstraints.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_KHR_shader_subgroup_basic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
#extension GL_KHR_shader_subgroup_vote : require | ||
#extension GL_ARB_shading_language_include : enable | ||
#extension GL_EXT_control_flow_attributes : require | ||
|
||
#define DYNAMIC_STRANDS_SET 0 | ||
#include "DynamicStrands.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_TASK_SUBGROUP_COUNT * EXT_TASK_SUBGROUP_SIZE; | ||
|
||
const uint ITERATIONS_PER_TASK = ((EXT_INVOCATIONS_PER_TASK + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
uint baseID = gl_WorkGroupID.x * EXT_INVOCATIONS_PER_TASK; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
layout(push_constant) uniform PUSH_CONSTANTS { | ||
uint constraint_size; | ||
float time_step; | ||
float inv_time_step; | ||
}; | ||
|
||
#define DYNAMIC_STRANDS_PHYSICS_SET 1 | ||
#include "DynamicStrandsPhysics.glsl" | ||
|
||
void init_constraint(in uint rod_constraint_handle); | ||
//Line 52 | ||
void main(){ | ||
|
||
[[unroll]] | ||
for (uint i = 0; i < ITERATIONS_PER_TASK; i++) | ||
{ | ||
uint local_index = laneID + i * WORKGROUP_SIZE; | ||
uint constraint_index = baseID + local_index; | ||
|
||
if(constraint_index >= constraint_size) break; | ||
init_constraint(constraint_index); | ||
} | ||
} | ||
|
||
void init_constraint(in uint rod_constraint_handle){ | ||
RodConstraint rod_constraint = rod_constraints[rod_constraint_handle]; | ||
|
||
vec3 stretch_compliance; | ||
vec3 bending_and_torsion_compliance; | ||
vec6 lambda_sum; | ||
|
||
init_stretch_bending_twisting_constraint( | ||
rod_constraint.stiffness_coefficient_k_segment0_index.xyz, | ||
inv_time_step, | ||
rod_constraint.stretch_compliance_average_segment_length.w, | ||
stretch_compliance, | ||
bending_and_torsion_compliance, | ||
lambda_sum); | ||
|
||
rod_constraints[rod_constraint_handle].stretch_compliance_average_segment_length.xyz = stretch_compliance; | ||
rod_constraints[rod_constraint_handle].bending_and_torsion_compliance_next_constraint_handle.xyz = bending_and_torsion_compliance; | ||
|
||
rod_constraints[rod_constraint_handle].lambda_sum0 = lambda_sum.v[0]; | ||
rod_constraints[rod_constraint_handle].lambda_sum1 = lambda_sum.v[1]; | ||
rod_constraints[rod_constraint_handle].lambda_sum2 = lambda_sum.v[2]; | ||
rod_constraints[rod_constraint_handle].lambda_sum3 = lambda_sum.v[3]; | ||
rod_constraints[rod_constraint_handle].lambda_sum4 = lambda_sum.v[4]; | ||
rod_constraints[rod_constraint_handle].lambda_sum5 = lambda_sum.v[5]; | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...ysLabResources/Shaders/Compute/DynamicStrands/Constraints/StiffRodProjectConstraints.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_KHR_shader_subgroup_basic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
#extension GL_KHR_shader_subgroup_vote : require | ||
#extension GL_ARB_shading_language_include : enable | ||
#extension GL_EXT_control_flow_attributes : require | ||
#define DYNAMIC_STRANDS_SET 0 | ||
#include "DynamicStrands.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_TASK_SUBGROUP_COUNT * EXT_TASK_SUBGROUP_SIZE; | ||
|
||
const uint ITERATIONS_PER_TASK = ((EXT_INVOCATIONS_PER_TASK + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
uint baseID = gl_WorkGroupID.x * EXT_INVOCATIONS_PER_TASK; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
layout(push_constant) uniform PUSH_CONSTANTS { | ||
uint strand_size; | ||
}; | ||
|
||
#define DYNAMIC_STRANDS_PHYSICS_SET 1 | ||
#include "DynamicStrandsPhysics.glsl" | ||
|
||
void project_constraint(in int rod_constraint_handle); | ||
|
||
void main(){ | ||
|
||
[[unroll]] | ||
for (uint i = 0; i < ITERATIONS_PER_TASK; i++) | ||
{ | ||
uint local_index = laneID + i * WORKGROUP_SIZE; | ||
uint strand_index = baseID + local_index; | ||
|
||
if(strand_index >= strand_size) break; | ||
|
||
PerStrandData strand_data = per_strand_data_list[strand_index]; | ||
int rod_constraint_handle = strand_data.begin_rod_constraint_handle; | ||
while(rod_constraint_handle != strand_data.end_rod_constraint_handle){ | ||
project_constraint(rod_constraint_handle); | ||
rod_constraint_handle = floatBitsToInt(rod_constraints[rod_constraint_handle].bending_and_torsion_compliance_next_constraint_handle.w); | ||
} | ||
project_constraint(rod_constraint_handle); | ||
} | ||
} | ||
|
||
void project_constraint(in int rod_constraint_handle){ | ||
RodConstraint rod_constraint = rod_constraints[rod_constraint_handle]; | ||
|
||
vec3 x0_correction, x1_correction; | ||
vec4 q0_correction, q1_correction; | ||
vec6 lambda_sum; | ||
lambda_sum.v[0] = rod_constraint.lambda_sum0; | ||
lambda_sum.v[1] = rod_constraint.lambda_sum1; | ||
lambda_sum.v[2] = rod_constraint.lambda_sum2; | ||
lambda_sum.v[3] = rod_constraint.lambda_sum3; | ||
lambda_sum.v[4] = rod_constraint.lambda_sum4; | ||
lambda_sum.v[5] = rod_constraint.lambda_sum5; | ||
|
||
int segment0_handle = floatBitsToInt(rod_constraint.stiffness_coefficient_k_segment0_index.w); | ||
int segment1_handle = floatBitsToInt(rod_constraint.rest_darboux_vector_segment1_index.w); | ||
StrandSegment segment0 = strand_segments[segment0_handle]; | ||
StrandSegment segment1 = strand_segments[segment1_handle]; | ||
|
||
mat3 inverse_inertia_tensor_w0, inverse_inertia_tensor_w1; | ||
inverse_inertia_tensor_w0 = mat3(segment0.inv_inertia_w); | ||
inverse_inertia_tensor_w1 = mat3(segment1.inv_inertia_w); | ||
|
||
solve_stretch_bending_twisting_constraints( | ||
segment0.inv_inertia_tensor_inv_mass.w, segment0.x.xyz, inverse_inertia_tensor_w0, segment0.q, | ||
segment1.inv_inertia_tensor_inv_mass.w, segment1.x.xyz, inverse_inertia_tensor_w1, segment1.q, | ||
rod_constraint.rest_darboux_vector_segment1_index.xyz, | ||
rod_constraint.stretch_compliance_average_segment_length.w, | ||
rod_constraint.stretch_compliance_average_segment_length.xyz, | ||
rod_constraint.bending_and_torsion_compliance_next_constraint_handle.xyz, | ||
rod_constraint.constraint_info, | ||
x0_correction, q0_correction, | ||
x1_correction, q1_correction, | ||
lambda_sum); | ||
|
||
if(segment0.inv_inertia_tensor_inv_mass.w != 0.0){ | ||
strand_segments[segment0_handle].x.xyz = segment0.x.xyz + x0_correction; | ||
strand_segments[segment0_handle].q = normalize(segment0.q + q0_correction); | ||
} | ||
|
||
if(segment1.inv_inertia_tensor_inv_mass.w != 0.0){ | ||
strand_segments[segment1_handle].x.xyz = segment1.x.xyz + x1_correction; | ||
strand_segments[segment1_handle].q = normalize(segment1.q + q1_correction); | ||
} | ||
|
||
rod_constraints[rod_constraint_handle].lambda_sum0 = lambda_sum.v[0]; | ||
rod_constraints[rod_constraint_handle].lambda_sum1 = lambda_sum.v[1]; | ||
rod_constraints[rod_constraint_handle].lambda_sum2 = lambda_sum.v[2]; | ||
rod_constraints[rod_constraint_handle].lambda_sum3 = lambda_sum.v[3]; | ||
rod_constraints[rod_constraint_handle].lambda_sum4 = lambda_sum.v[4]; | ||
rod_constraints[rod_constraint_handle].lambda_sum5 = lambda_sum.v[5]; | ||
} |
55 changes: 55 additions & 0 deletions
55
...SysLabResources/Shaders/Compute/DynamicStrands/Constraints/StiffRodUpdateConstraints.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_KHR_shader_subgroup_basic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
#extension GL_KHR_shader_subgroup_vote : require | ||
#extension GL_ARB_shading_language_include : enable | ||
#extension GL_EXT_control_flow_attributes : require | ||
|
||
#define DYNAMIC_STRANDS_SET 0 | ||
#include "DynamicStrands.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_TASK_SUBGROUP_COUNT * EXT_TASK_SUBGROUP_SIZE; | ||
|
||
const uint ITERATIONS_PER_TASK = ((EXT_INVOCATIONS_PER_TASK + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
uint baseID = gl_WorkGroupID.x * EXT_INVOCATIONS_PER_TASK; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
layout(push_constant) uniform PUSH_CONSTANTS { | ||
uint constraint_size; | ||
}; | ||
|
||
#define DYNAMIC_STRANDS_PHYSICS_SET 1 | ||
#include "DynamicStrandsPhysics.glsl" | ||
|
||
void update_constraint(in uint rod_constraint_handle); | ||
|
||
void main(){ | ||
|
||
[[unroll]] | ||
for (uint i = 0; i < ITERATIONS_PER_TASK; i++) | ||
{ | ||
uint local_index = laneID + i * WORKGROUP_SIZE; | ||
uint constraint_index = baseID + local_index; | ||
|
||
if(constraint_index >= constraint_size) break; | ||
update_constraint(constraint_index); | ||
} | ||
} | ||
|
||
void update_constraint(in uint rod_constraint_handle){ | ||
RodConstraint rod_constraint = rod_constraints[rod_constraint_handle]; | ||
mat4 constraint_info = rod_constraint.constraint_info; | ||
|
||
StrandSegment strand_segment0 = strand_segments[floatBitsToInt(rod_constraint.stiffness_coefficient_k_segment0_index.w)]; | ||
StrandSegment strand_segment1 = strand_segments[floatBitsToInt(rod_constraint.rest_darboux_vector_segment1_index.w)]; | ||
|
||
update_stretch_bending_twisting_constraint(strand_segment0.x.xyz, strand_segment0.q, strand_segment1.x.xyz, strand_segment1.q, constraint_info); | ||
rod_constraints[rod_constraint_handle].constraint_info = constraint_info; | ||
} |
52 changes: 52 additions & 0 deletions
52
.../Internals/EcoSysLabResources/Shaders/Compute/DynamicStrands/Operators/ExternalForce.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_KHR_shader_subgroup_basic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
#extension GL_KHR_shader_subgroup_vote : require | ||
#extension GL_ARB_shading_language_include : enable | ||
|
||
#define DYNAMIC_STRANDS_SET 0 | ||
#include "DynamicStrands.glsl" | ||
|
||
#include "Math.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_TASK_SUBGROUP_COUNT * EXT_TASK_SUBGROUP_SIZE; | ||
|
||
const uint ITERATIONS_PER_TASK = ((EXT_INVOCATIONS_PER_TASK + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
uint baseID = gl_WorkGroupID.x * EXT_INVOCATIONS_PER_TASK; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
struct ExternalForce{ | ||
vec4 force_index; | ||
}; | ||
|
||
layout(std430, set = 1, binding = 0) readonly buffer EXTERNAL_FORCE_BLOCK { | ||
ExternalForce external_forces[]; | ||
}; | ||
|
||
layout(push_constant) uniform PUSH_CONSTANTS { | ||
uint command_size; | ||
float delta_time; | ||
}; | ||
|
||
void main(){ | ||
for (uint i = 0; i < ITERATIONS_PER_TASK; i++) | ||
{ | ||
uint local_index = laneID + i * WORKGROUP_SIZE; | ||
uint global_index = baseID + local_index; | ||
|
||
if(global_index >= command_size) break; | ||
|
||
ExternalForce external_force = external_forces[global_index]; | ||
uint segment_index = floatBitsToUint(external_force.force_index.w); | ||
vec3 force = external_force.force_index.xyz; | ||
StrandSegment segment = strand_segments[segment_index]; | ||
strand_segments[segment_index].acceleration.xyz = force * segment.inv_inertia_tensor_inv_mass.w; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...Internals/EcoSysLabResources/Shaders/Compute/DynamicStrands/Operators/PositionUpdate.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#extension GL_EXT_shader_explicit_arithmetic_types_int8 : require | ||
#extension GL_KHR_shader_subgroup_basic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
#extension GL_KHR_shader_subgroup_vote : require | ||
#extension GL_ARB_shading_language_include : enable | ||
|
||
#define DYNAMIC_STRANDS_SET 0 | ||
#include "DynamicStrands.glsl" | ||
|
||
#include "Math.glsl" | ||
|
||
const uint WORKGROUP_SIZE = EXT_TASK_SUBGROUP_COUNT * EXT_TASK_SUBGROUP_SIZE; | ||
|
||
const uint ITERATIONS_PER_TASK = ((EXT_INVOCATIONS_PER_TASK + WORKGROUP_SIZE - 1) / WORKGROUP_SIZE); | ||
|
||
uint baseID = gl_WorkGroupID.x * EXT_INVOCATIONS_PER_TASK; | ||
uint laneID = gl_LocalInvocationID.x; | ||
|
||
layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in; | ||
|
||
#define BARRIER() \ | ||
memoryBarrierShared(); \ | ||
barrier(); | ||
|
||
struct PositionUpdate{ | ||
vec4 new_position_index; | ||
}; | ||
|
||
layout(std430, set = 1, binding = 0) readonly buffer POSITION_UPDATE_BLOCK { | ||
PositionUpdate position_updates[]; | ||
}; | ||
|
||
layout(push_constant) uniform PUSH_CONSTANTS { | ||
uint command_size; | ||
}; | ||
|
||
void main(){ | ||
for (uint i = 0; i < ITERATIONS_PER_TASK; i++) | ||
{ | ||
uint local_index = laneID + i * WORKGROUP_SIZE; | ||
uint global_index = baseID + local_index; | ||
|
||
if(global_index >= command_size) break; | ||
|
||
PositionUpdate position_update = position_updates[global_index]; | ||
|
||
uint segment_index = floatBitsToUint(position_update.new_position_index.w); | ||
|
||
vec3 new_position = position_update.new_position_index.xyz; | ||
vec3 old_position = strand_segments[segment_index].x.xyz; | ||
vec3 delta_position = new_position - old_position; | ||
|
||
strand_segments[segment_index].x.xyz = new_position; | ||
strand_segments[segment_index].last_x.xyz = strand_segments[segment_index].last_x.xyz + delta_position; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.