Skip to content

Commit

Permalink
Fix some math used by disableDepthDistance.
Browse files Browse the repository at this point in the history
  • Loading branch information
emackey committed Aug 9, 2017
1 parent be83a12 commit 04eb594
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Source/Shaders/BillboardCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,12 @@ void main()

if (disableDepthTestDistance != 0.0)
{
gl_Position.z = min(gl_Position.z, gl_Position.w);

bool clipped = gl_Position.z < -gl_Position.w || gl_Position.z > gl_Position.w;
// Don't try to "multiply both sides" by w. Greater/less-than comparisons won't work for negative values of w.
float zclip = gl_Position.z / gl_Position.w;
bool clipped = (zclip < -1.0 || zclip > 1.0);
if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))
{
// Position z on the near plane.
gl_Position.z = -gl_Position.w;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Source/Shaders/PointPrimitiveCollectionVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,12 @@ void main()

if (disableDepthTestDistance != 0.0)
{
gl_Position.z = min(gl_Position.z, gl_Position.w);

bool clipped = gl_Position.z < -gl_Position.w || gl_Position.z > gl_Position.w;
// Don't try to "multiply both sides" by w. Greater/less-than comparisons won't work for negative values of w.
float zclip = gl_Position.z / gl_Position.w;
bool clipped = (zclip < -1.0 || zclip > 1.0);
if (!clipped && (disableDepthTestDistance < 0.0 || (lengthSq > 0.0 && lengthSq < disableDepthTestDistance)))
{
// Position z on the near plane.
gl_Position.z = -gl_Position.w;
}
}
Expand Down

0 comments on commit 04eb594

Please sign in to comment.