Skip to content

Commit

Permalink
Undo Texture buffer shader changes, this would need to be handled bef…
Browse files Browse the repository at this point in the history
…ore vis.
  • Loading branch information
Robadob committed Aug 12, 2024
1 parent 23102a6 commit 44aebdd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 143 deletions.
122 changes: 20 additions & 102 deletions src/flamegpu/visualiser/shader/DirectionFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ DirectionFunction::DirectionFunction(const std::map<TexBufferConfig::Function, T
, has_bank(tex_buffers.find(TexBufferConfig::Bank) != tex_buffers.end())
, has_direction_hp(tex_buffers.find(TexBufferConfig::Direction_hp) != tex_buffers.end())
, has_direction_hpb(tex_buffers.find(TexBufferConfig::Direction_hpb) != tex_buffers.end())
, has_fw_dbl_x(tex_buffers.find(TexBufferConfig::Forward_dbl_x) != tex_buffers.end())
, has_fw_dbl_y(tex_buffers.find(TexBufferConfig::Forward_dbl_y) != tex_buffers.end())
, has_fw_dbl_z(tex_buffers.find(TexBufferConfig::Forward_dbl_z) != tex_buffers.end())
, has_fw_dbl_xz(tex_buffers.find(TexBufferConfig::Forward_dbl_xz) != tex_buffers.end())
, has_fw_dbl_xyz(tex_buffers.find(TexBufferConfig::Forward_dbl_xyz) != tex_buffers.end())
, has_up_dbl_x(tex_buffers.find(TexBufferConfig::Up_dbl_x) != tex_buffers.end())
, has_up_dbl_y(tex_buffers.find(TexBufferConfig::Up_dbl_y) != tex_buffers.end())
, has_up_dbl_z(tex_buffers.find(TexBufferConfig::Up_dbl_z) != tex_buffers.end())
, has_up_dbl_xyz(tex_buffers.find(TexBufferConfig::Up_dbl_xyz) != tex_buffers.end())
, has_heading_dbl(tex_buffers.find(TexBufferConfig::Heading_dbl) != tex_buffers.end())
, has_pitch_dbl(tex_buffers.find(TexBufferConfig::Pitch_dbl) != tex_buffers.end())
, has_bank_dbl(tex_buffers.find(TexBufferConfig::Bank_dbl) != tex_buffers.end())
, has_direction_dbl_hp(tex_buffers.find(TexBufferConfig::Direction_dbl_hp) != tex_buffers.end())
, has_direction_dbl_hpb(tex_buffers.find(TexBufferConfig::Direction_dbl_hpb) != tex_buffers.end())
{ }

std::string DirectionFunction::getSrc() {
Expand All @@ -82,20 +68,20 @@ std::string DirectionFunction::getSrc() {
ss << ROTATION_MAT_FN;
ss << ATAN2_FN;
// Define any sampler buffers
if (has_fw_x || has_fw_dbl_x) ss << "uniform samplerBuffer _fw_x;" << "\n";
if (has_fw_y || has_fw_dbl_y) ss << "uniform samplerBuffer _fw_y;" << "\n";
if (has_fw_z || has_fw_dbl_z) ss << "uniform samplerBuffer _fw_z;" << "\n";
if (has_fw_xz || has_fw_dbl_xz) ss << "uniform samplerBuffer _fw_xz;" << "\n";
if (has_fw_xyz || has_fw_dbl_xyz) ss << "uniform samplerBuffer _fw_xyz;" << "\n";
if (has_up_x || has_up_dbl_x) ss << "uniform samplerBuffer _up_x;" << "\n";
if (has_up_y || has_up_dbl_y) ss << "uniform samplerBuffer _up_y;" << "\n";
if (has_up_z || has_up_dbl_z) ss << "uniform samplerBuffer _up_z;" << "\n";
if (has_up_xyz || has_up_dbl_xyz) ss << "uniform samplerBuffer _up_xyz;" << "\n";
if (has_heading || has_heading_dbl) ss << "uniform samplerBuffer _heading;" << "\n";
if (has_pitch || has_pitch_dbl) ss << "uniform samplerBuffer _pitch;" << "\n";
if (has_bank || has_bank_dbl) ss << "uniform samplerBuffer _bank;" << "\n";
if (has_direction_hp || has_direction_dbl_hp) ss << "uniform samplerBuffer _direction_hp;" << "\n";
if (has_direction_hpb || has_direction_dbl_hpb) ss << "uniform samplerBuffer _direction_hpb;" << "\n";
if (has_fw_x) ss << "uniform samplerBuffer _fw_x;" << "\n";
if (has_fw_y) ss << "uniform samplerBuffer _fw_y;" << "\n";
if (has_fw_z) ss << "uniform samplerBuffer _fw_z;" << "\n";
if (has_fw_xz) ss << "uniform samplerBuffer _fw_xz;" << "\n";
if (has_fw_xyz) ss << "uniform samplerBuffer _fw_xyz;" << "\n";
if (has_up_x) ss << "uniform samplerBuffer _up_x;" << "\n";
if (has_up_y) ss << "uniform samplerBuffer _up_y;" << "\n";
if (has_up_z) ss << "uniform samplerBuffer _up_z;" << "\n";
if (has_up_xyz) ss << "uniform samplerBuffer _up_xyz;" << "\n";
if (has_heading) ss << "uniform samplerBuffer _heading;" << "\n";
if (has_pitch) ss << "uniform samplerBuffer _pitch;" << "\n";
if (has_bank) ss << "uniform samplerBuffer _bank;" << "\n";
if (has_direction_hp) ss << "uniform samplerBuffer _direction_hp;" << "\n";
if (has_direction_hpb) ss << "uniform samplerBuffer _direction_hpb;" << "\n";
// Begin function
ss << "mat3 getDirection() {" << "\n";
// Define vectors for our global coordinate system
Expand Down Expand Up @@ -136,39 +122,6 @@ std::string DirectionFunction::getSrc() {
ss << " return mat3(1);" << "\n";
// Normalize target incase the user forgot
ss << "target = normalize(target);" << "\n";
} else if (has_fw_dbl_x || has_fw_dbl_y || has_fw_dbl_z || has_fw_dbl_xz || has_fw_dbl_xyz) {
// missing buffers always return 0
ss << "vec3 target = vec3(" << "\n";
if (has_fw_dbl_x) {
ss << " float(texelFetch(_fw_x, gl_InstanceID).x)," << "\n";
} else if (has_fw_dbl_xz) {
ss << " float(texelFetch(_fw_xz, gl_InstanceID * 2).x)," << "\n";
} else if (has_fw_dbl_xyz) {
ss << " float(texelFetch(_fw_xyz, gl_InstanceID * 3).x)," << "\n";
} else {
ss << " 0," << "\n";
}
if (has_fw_dbl_y) {
ss << " float(texelFetch(_fw_y, gl_InstanceID).x)," << "\n";
} else if (has_fw_dbl_xyz) {
ss << " float(texelFetch(_fw_xyz, (gl_InstanceID * 3) + 1).x)," << "\n";
} else {
ss << " 0," << "\n";
}
if (has_fw_dbl_z) {
ss << " float(texelFetch(_fw_z, gl_InstanceID).x));" << "\n";
} else if (has_fw_dbl_xz) {
ss << " float(texelFetch(_fw_xz, (gl_InstanceID * 2) + 1).x));" << "\n";
} else if (has_fw_dbl_xyz) {
ss << " float(texelFetch(_fw_xyz, (gl_InstanceID * 3) + 2).x));" << "\n";
} else {
ss << " 0);" << "\n";
}
// If target is null, don't rotate
ss << "if (target.xyz == vec3(0))" << "\n";
ss << " return mat3(1);" << "\n";
// Normalize target incase the user forgot
ss << "target = normalize(target);" << "\n";
} else {
if (has_direction_hp) {
ss << "const int t = gl_InstanceID * 2;" << "\n";
Expand All @@ -178,24 +131,12 @@ std::string DirectionFunction::getSrc() {
ss << "const int t = gl_InstanceID * 3;" << "\n";
ss << "const float angle_H = texelFetch(_direction_hpb, t).x;" << "\n";
ss << "const float angle_P = texelFetch(_direction_hpb, t + 1).x;" << "\n";
} else if (has_direction_dbl_hp) {
ss << "const int t = gl_InstanceID * 2;" << "\n";
ss << "const float angle_H = float(texelFetch(_direction_hp, t).x);" << "\n";
ss << "const float angle_P = float(texelFetch(_direction_hp, t + 1).x);" << "\n";
} else if (has_direction_dbl_hpb) {
ss << "const int t = gl_InstanceID * 3;" << "\n";
ss << "const float angle_H = float(texelFetch(_direction_hpb, t).x);" << "\n";
ss << "const float angle_P = float(texelFetch(_direction_hpb, t + 1).x);" << "\n";
} else {
if (has_heading) {
ss << "const float angle_H = texelFetch(_heading, gl_InstanceID).x;" << "\n";
} else if(has_heading_dbl) {
ss << "const float angle_H = float(texelFetch(_heading, gl_InstanceID).x);" << "\n";
}
if (has_pitch) {
ss << "const float angle_P = texelFetch(_pitch, gl_InstanceID).x;" << "\n";
} else if (has_pitch_dbl) {
ss << "const float angle_P = float(texelFetch(_pitch, gl_InstanceID).x);" << "\n";
}
}
}
Expand All @@ -212,59 +153,36 @@ std::string DirectionFunction::getSrc() {
}
// Normalize target_up incase the user forgot
ss << "target_up = normalize(target_up);" << "\n";
} else if (((has_fw_dbl_x && has_fw_dbl_y && has_fw_dbl_z) || (has_fw_dbl_xz && has_fw_dbl_y) || has_fw_dbl_xyz) && ((has_up_dbl_x && has_up_dbl_y && has_up_dbl_z) || has_up_dbl_xyz)) {
ss << "vec3 target_up = vec3(" << "\n";
if (has_up_dbl_xyz) {
ss << " float(texelFetch(_up_xyz, gl_InstanceID * 3).x)," << "\n";
ss << " float(texelFetch(_up_xyz, (gl_InstanceID * 3) + 1).x)," << "\n";
ss << " float(texelFetch(_up_xyz, (gl_InstanceID * 3) + 2).x));" << "\n";
} else {
ss << " float(texelFetch(_up_x, gl_InstanceID).x)," << "\n";
ss << " float(texelFetch(_up_y, gl_InstanceID).x)," << "\n";
ss << " float(texelFetch(_up_z, gl_InstanceID).x));" << "\n";
}
// Normalize target_up incase the user forgot
ss << "target_up = normalize(target_up);" << "\n";
} else if (has_bank) {
ss << "const float angle_B = texelFetch(_bank, gl_InstanceID).x;" << "\n";
} else if (has_direction_hpb) {
ss << "const float angle_B = texelFetch(_direction_hpb, t + 2).x;" << "\n";
} else if (has_bank_dbl) {
ss << "const float angle_B = float(texelFetch(_bank, gl_InstanceID).x);" << "\n";
} else if (has_direction_dbl_hpb) {
ss << "const float angle_B = float(texelFetch(_direction_hpb, t + 2).x);" << "\n";
}
// Begin to perform rotation
ss << "mat3 rm = mat3(1);" << "\n";
// Euler angle extraction is based on: https://stackoverflow.com/questions/21622956/how-to-convert-direction-vector-to-euler-angles
// Apply rotation about 1st axis
if (has_heading || (has_fw_x || has_fw_z) || has_fw_xz || has_fw_xyz || has_direction_hp || has_direction_hpb ||
has_heading_dbl || (has_fw_dbl_x || has_fw_dbl_z) || has_fw_dbl_xz || has_fw_dbl_xyz || has_direction_dbl_hp || has_direction_dbl_hpb) {
if (has_heading || (has_fw_x || has_fw_z) || has_fw_xz || has_fw_xyz || has_direction_hp || has_direction_hpb) {
// Calculate the heading angle (yaw, about Y)
if (!(has_heading || has_direction_hp || has_direction_hpb||
has_heading_dbl || has_direction_dbl_hp || has_direction_dbl_hpb)) {
if (!(has_heading || has_direction_hp || has_direction_hpb)) {
ss << "float angle_H = atan2(target.z, target.x);" << "\n";
}
// Apply the heading angle
ss << "rm = RotationMat(UP, angle_H) * rm;" << "\n";
}
// Apply rotation about 2nd axis
if (has_pitch || has_fw_y || has_fw_xyz || has_direction_hp || has_direction_hpb ||
has_pitch_dbl || has_fw_dbl_y || has_fw_dbl_xyz || has_direction_dbl_hp || has_direction_dbl_hpb) {
if (has_pitch || has_fw_y || has_fw_xyz || has_direction_hp || has_direction_hpb) {
// Calculate the pitch angle (pitch, about Z)
if (!(has_pitch || has_direction_hp || has_direction_hpb ||
has_pitch_dbl || has_direction_dbl_hp || has_direction_dbl_hpb)) {
if (!(has_pitch || has_direction_hp || has_direction_hpb)) {
ss << "float angle_P = -asin(target.y);" << "\n";
}
// Apply the pitch angle
ss << "rm = RotationMat(rm * RIGHT, angle_P) * rm;" << "\n";
}
// Apply rotation about 3rd axis
if (has_bank || has_direction_hpb || (((has_fw_x && has_fw_y && has_fw_z) || (has_fw_xz && has_fw_y) || has_fw_xyz) && ((has_up_x && has_up_y && has_up_z) || has_up_xyz ||
has_bank_dbl || has_direction_dbl_hpb || (((has_fw_dbl_x && has_fw_dbl_y && has_fw_dbl_z) || (has_fw_dbl_xz && has_fw_dbl_y) || has_fw_dbl_xyz) && ((has_up_dbl_x && has_up_dbl_y && has_up_dbl_z) || has_up_dbl_xyz))) {
if (has_bank || has_direction_hpb || (((has_fw_x && has_fw_y && has_fw_z) || (has_fw_xz && has_fw_y) || has_fw_xyz) && ((has_up_x && has_up_y && has_up_z) || has_up_xyz))) {
// Calculate the bank angle (roll, about X)
if (!(has_bank || has_direction_hpb ||
has_bank_dbl || has_direction_dbl_hpb)) {
if (!(has_bank || has_direction_hpb)) {
ss << "float angle_B = 0; " << "\n";
ss << "if (target.x != 0 || target.z != 0) {" << "\n";
ss << " vec3 W0 = vec3(-target.z, 0, target.x);" << "\n";
Expand Down
14 changes: 0 additions & 14 deletions src/flamegpu/visualiser/shader/DirectionFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ class DirectionFunction {
bool has_bank;
bool has_direction_hp;
bool has_direction_hpb;
bool has_fw_dbl_x;
bool has_fw_dbl_y;
bool has_fw_dbl_z;
bool has_fw_dbl_xz;
bool has_fw_dbl_xyz;
bool has_up_dbl_x;
bool has_up_dbl_y;
bool has_up_dbl_z;
bool has_up_dbl_xyz;
bool has_heading_dbl;
bool has_pitch_dbl;
bool has_bank_dbl;
bool has_direction_dbl_hp;
bool has_direction_dbl_hpb;
static const char* ROTATION_MAT_FN;
static const char* ATAN2_FN;
};
Expand Down
22 changes: 0 additions & 22 deletions src/flamegpu/visualiser/shader/PositionFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace visualiser {
, has_pos_z(tex_buffers.find(TexBufferConfig::Position_z) != tex_buffers.end())
, has_pos_xy(tex_buffers.find(TexBufferConfig::Position_xy) != tex_buffers.end())
, has_pos_xyz(tex_buffers.find(TexBufferConfig::Position_xyz) != tex_buffers.end())
, has_pos_dbl_x(tex_buffers.find(TexBufferConfig::Position_dbl_x) != tex_buffers.end())
, has_pos_dbl_y(tex_buffers.find(TexBufferConfig::Position_dbl_y) != tex_buffers.end())
, has_pos_dbl_z(tex_buffers.find(TexBufferConfig::Position_dbl_z) != tex_buffers.end())
, has_pos_dbl_xy(tex_buffers.find(TexBufferConfig::Position_dbl_xy) != tex_buffers.end())
, has_pos_dbl_xyz(tex_buffers.find(TexBufferConfig::Position_dbl_xyz) != tex_buffers.end())
{ }

std::string PositionFunction::getSrc() {
Expand Down Expand Up @@ -46,23 +41,6 @@ std::string PositionFunction::getSrc() {
ss << " texelFetch(_pos_xyz, t).x," << "\n";
ss << " texelFetch(_pos_xyz, t + 1).x," << "\n";
ss << " texelFetch(_pos_xyz, t + 2).x);" << "\n";
} else if (has_pos_dbl_x || has_pos_dbl_y || has_pos_dbl_z) {
ss << " return vec3(" <<"\n";
ss << " " << (has_pos_dbl_x ? "float(texelFetch(_pos_x, gl_InstanceID).x)" : "0") << "," << "\n";
ss << " " << (has_pos_dbl_y ? "float(texelFetch(_pos_y, gl_InstanceID).x)" : "0") << "," << "\n";
ss << " " << (has_pos_dbl_z ? "float(texelFetch(_pos_z, gl_InstanceID).x)" : "0") << ");" << "\n";
} else if (has_pos_dbl_xy) {
ss << " const int t = gl_InstanceID * 2;" << "\n";
ss << " return vec3(" << "\n";
ss << " float(texelFetch(_pos_xy, t).x)," << "\n";
ss << " float(texelFetch(_pos_xy, t + 1).x)," << "\n";
ss << " 0);" << "\n";
} else if (has_pos_dbl_xyz) {
ss << " const int t = gl_InstanceID * 3;" << "\n";
ss << " return vec3(" << "\n";
ss << " float(texelFetch(_pos_xyz, t).x)," << "\n";
ss << " float(texelFetch(_pos_xyz, t + 1).x)," << "\n";
ss << " float(texelFetch(_pos_xyz, t + 2).x));" << "\n";
} else {
ss << "return glm::vec3(0);" << "\n";
}
Expand Down
5 changes: 0 additions & 5 deletions src/flamegpu/visualiser/shader/PositionFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ class PositionFunction {
bool has_pos_z;
bool has_pos_xy;
bool has_pos_xyz;
bool has_pos_dbl_x;
bool has_pos_dbl_y;
bool has_pos_dbl_z;
bool has_pos_dbl_xy;
bool has_pos_dbl_xyz;
};

} // namespace visualiser
Expand Down

0 comments on commit 44aebdd

Please sign in to comment.