Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion examples/jsm/lines/LineMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ ShaderLib[ 'line' ] = {
// conservative estimate of the near plane
float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
float nearEstimate = - 0.5 * b / a;

// we need different nearEstimate formula for reversed and default depth buffer
// a is positive with a reversed depth buffer so it can be used for controlling the code flow
float nearEstimate = ( a > 0.0 ) ? ( - b / ( a + 1.0 ) ) : ( - 0.5 * b / a );

float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );

Expand Down
6 changes: 5 additions & 1 deletion src/materials/nodes/Line2NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ class Line2NodeMaterial extends NodeMaterial {

const a = cameraProjectionMatrix.element( 2 ).element( 2 ); // 3nd entry in 3th column
const b = cameraProjectionMatrix.element( 3 ).element( 2 ); // 3nd entry in 4th column
const nearEstimate = b.mul( - 0.5 ).div( a );

// we need different nearEstimate formula for reversed and default depth buffer
// a is positive with a reversed depth buffer so it can be used for controlling the code flow

const nearEstimate = a.greaterThan( 0 ).select( b.negate().div( a.add( 1 ) ), b.mul( - 0.5 ).div( a ) );

const alpha = nearEstimate.sub( start.z ).div( end.z.sub( start.z ) );

Expand Down
Loading