Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions crates/bevy_gizmos/src/lines.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,11 @@ fn vertex(vertex: VertexInput) -> VertexOutput {

fn clip_near_plane(a: vec4<f32>, b: vec4<f32>) -> vec4<f32> {
// Move a if a is behind the near plane and b is in front.
// equivalent to `a.z / a.w > 1.0 && b.z / b.w <= 1.0` but avoids divs
if a.z * sign(a.w) > abs(a.w) && b.z * sign(b.w) <= abs(b.w) {
if a.z > a.w && b.z <= b.w {
// Interpolate a towards b until it's at the near plane.
let distance_a = a.z - a.w;
let distance_b = b.z - b.w;
// Add an epsilon to the interpolator to ensure that the point is
// not just behind the clip plane due to floating-point imprecision.
let t = distance_a / (distance_a - distance_b) + EPSILON;
let t = distance_a / (distance_a - distance_b);
return mix(a, b, t);
}
return a;
Expand Down