Skip to content

Commit

Permalink
Checkpoint. Waiting to implement constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonlee0212 committed Oct 16, 2024
1 parent ac3c0be commit af3e89b
Show file tree
Hide file tree
Showing 19 changed files with 456 additions and 908 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#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"

Expand All @@ -22,34 +21,39 @@ memoryBarrierShared(); \
barrier();

layout(push_constant) uniform PUSH_CONSTANTS {
uint constraint_size;
uint strand_size;
};

#define DYNAMIC_STRANDS_PHYSICS_SET 1
#include "DynamicStrandsPhysics.glsl"

void update_constraint(in uint rod_constraint_handle);
void project_constraint(in int 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;
uint strand_index = baseID + local_index;

if(strand_index >= strand_size) break;

if(constraint_index >= constraint_size) break;
update_constraint(constraint_index);
PerStrandData strand_data = per_strand_data_list[strand_index];
int constraint_handle = strand_data.begin_constraint_handle;
while(constraint_handle != strand_data.end_constraint_handle){
project_constraint(constraint_handle);
constraint_handle = floatBitsToInt(constraints[constraint_handle].bending_and_torsion_compliance_next_constraint_handle.w);
}
project_constraint(constraint_handle);
}
}

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)];
void project_constraint(in int constraint_handle){
Constraint constraint = constraints[constraint_handle];
int segment0_handle = floatBitsToInt(constraint.stiffness_coefficient_k_segment0_index.w);
int segment1_handle = floatBitsToInt(constraint.rest_darboux_vector_segment1_index.w);
Segment segment0 = segments[segment0_handle];
Segment segment1 = segments[segment1_handle];

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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ barrier();

layout(push_constant) uniform PUSH_CONSTANTS {
uint constraint_size;
float time_step;
float inv_time_step;
float time_step;
};

#define DYNAMIC_STRANDS_PHYSICS_SET 1
#include "DynamicStrandsPhysics.glsl"

void init_constraint(in uint rod_constraint_handle);
void init_stretch_bending_twisting_constraint(in vec3 stiffness_coefficient_k, in float time_step,
in float average_segment_length, out vec3 stretch_compliance,
out vec3 bending_and_torsion_compliance) {
float time_step_quadratic = time_step * time_step;

stretch_compliance = vec3(time_step_quadratic / stiffness_coefficient_k[0],
time_step_quadratic / stiffness_coefficient_k[0],
time_step_quadratic / stiffness_coefficient_k[0]);

bending_and_torsion_compliance = vec3(time_step_quadratic / stiffness_coefficient_k[1],
time_step_quadratic / stiffness_coefficient_k[1],
time_step_quadratic / stiffness_coefficient_k[2]);
}

void init_constraint(in uint constraint_handle);
//Line 52
void main(){

Expand All @@ -45,29 +58,19 @@ void main(){
}
}

void init_constraint(in uint rod_constraint_handle){
RodConstraint rod_constraint = rod_constraints[rod_constraint_handle];
void init_constraint(in uint constraint_handle){
Constraint constraint = constraints[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,
constraint.stiffness_coefficient_k_segment0_index.xyz,
time_step,
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];
bending_and_torsion_compliance);

constraints[constraint_handle].stretch_compliance_average_segment_length.xyz = stretch_compliance;
constraints[constraint_handle].bending_and_torsion_compliance_next_constraint_handle.xyz = bending_and_torsion_compliance;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#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 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 constraint_handle = strand_data.begin_constraint_handle;
while(constraint_handle != strand_data.end_constraint_handle){
project_constraint(constraint_handle);
constraint_handle = floatBitsToInt(constraints[constraint_handle].bending_and_torsion_compliance_next_constraint_handle.w);
}
project_constraint(constraint_handle);
}
}

void project_constraint(in int constraint_handle){
Constraint constraint = constraints[constraint_handle];
int segment0_handle = floatBitsToInt(constraint.stiffness_coefficient_k_segment0_index.w);
int segment1_handle = floatBitsToInt(constraint.rest_darboux_vector_segment1_index.w);
Segment segment0 = segments[segment0_handle];
Segment segment1 = segments[segment1_handle];

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void main(){
if(global_index >= command_size) break;

ExternalForce external_force = external_forces[global_index];
uint segment_index = floatBitsToUint(external_force.force_index.w);
uint particle_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;
Particle particle = particles[particle_index];
particles[particle_index].acceleration_inv_mass.xyz = force * particle.acceleration_inv_mass.w;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ void main(){

PositionUpdate position_update = position_updates[global_index];

uint segment_index = floatBitsToUint(position_update.new_position_index.w);
uint particle_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 old_position = particles[particle_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;
particles[particle_index].x.xyz = new_position;
particles[particle_index].last_x.xyz = particles[particle_index].last_x.xyz + delta_position;
particles[particle_index].old_x.xyz = particles[particle_index].old_x.xyz + delta_position;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,35 @@ layout(local_size_x = WORKGROUP_SIZE, local_size_y = 1, local_size_z = 1) in;
memoryBarrierShared(); \
barrier();


layout(push_constant) uniform PUSH_CONSTANTS {
uint segment_size;
uint particle_size;
float time_step;
float inv_time_step;
};

void main(){
for (uint i = 0; i < ITERATIONS_PER_TASK; i++)
{
uint local_index = laneID + i * WORKGROUP_SIZE;
uint segment_index = baseID + local_index;

if(segment_index >= segment_size) break;
StrandSegment segment = strand_segments[segment_index];
uint particle_index = baseID + local_index;

if(particle_index >= particle_size) break;

Particle particle = particles[particle_index];

//Calculate velocity and apply acceleration.
vec3 velocity = vec3(0, 0, 0);
if(particle.acceleration_inv_mass.w != 0.0){
velocity = inv_time_step * (1.5 * particle.x.xyz - 2.0 * particle.old_x.xyz + 0.5 * particle.last_x.xyz);
velocity += particle.acceleration_inv_mass.xyz * time_step;
}

//Shift position values
particle.last_x.xyz = particle.old_x.xyz;
particle.old_x.xyz = particle.x.xyz;
//Apply velocity
particle.x.xyz += time_step * velocity;

particles[particle_index] = particle;
}
}
Loading

0 comments on commit af3e89b

Please sign in to comment.