Skip to content

Commit

Permalink
Merge pull request #81315 from conorlawton/z-billboard-y-velocity-no-…
Browse files Browse the repository at this point in the history
…scale

Fix z-billboard + y to velocity transform alignment to correctly respect non-uniform scale
  • Loading branch information
akien-mga committed Sep 8, 2023
2 parents 5fef875 + 9ecafcc commit 3815b2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions drivers/gles3/shaders/particles_copy.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,16 @@ void main() {
} break;
case TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY: {
vec3 sv = velocity_flags.xyz - sort_direction * dot(sort_direction, velocity_flags.xyz); //screen velocity
float s = (length(txform[0]) + length(txform[1]) + length(txform[2])) / 3.0;

if (length(sv) == 0.0) {
sv = align_up;
}

sv = normalize(sv);

txform[0].xyz = normalize(cross(sv, sort_direction)) * s;
txform[1].xyz = sv * s;
txform[2].xyz = sort_direction * s;
txform[0].xyz = normalize(cross(sv, sort_direction)) * length(txform[0]);
txform[1].xyz = sv * length(txform[1]);
txform[2].xyz = sort_direction * length(txform[2]);

} break;
}
Expand Down
7 changes: 3 additions & 4 deletions servers/rendering/renderer_rd/shaders/particles_copy.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ void main() {
case TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY: {
vec3 v = particles.data[particle].velocity;
vec3 sv = v - params.sort_direction * dot(params.sort_direction, v); //screen velocity
float s = (length(txform[0]) + length(txform[1]) + length(txform[2])) / 3.0;

if (length(sv) == 0) {
sv = params.align_up;
}

sv = normalize(sv);

txform[0].xyz = normalize(cross(sv, params.sort_direction)) * s;
txform[1].xyz = sv * s;
txform[2].xyz = params.sort_direction * s;
txform[0].xyz = normalize(cross(sv, params.sort_direction)) * length(txform[0]);
txform[1].xyz = sv * length(txform[1]);
txform[2].xyz = params.sort_direction * length(txform[2]);

} break;
}
Expand Down

0 comments on commit 3815b2f

Please sign in to comment.