# Are there any math limitations on the near plane in a perspective matrix?

I've noted that if in the perspective camera I put near plane to a low number like 0.000001 and far plane to 1000 my render has some problems, like strange depth artifacts (see images below) or division by zero during the unprojection procedure.

I'm not very skilled in math but there should be something strange because if I put near plane at 0.1 everything is working as expected.

Is there any mathematical limitation to the near plane value I'm not aware of?

I'm on WebGL with JavaScript (I'm not using Three.js; my question is related to the math, not to a particular framework). If it matters, I'm using Float32Array to store matrices, and I'm using those libraries to do the math:

In particular the division by zero happens here:

function project (out, vec, m) {
var x = vec,
y = vec,
z = vec,
a00 = m, a01 = m, a02 = m, a03 = m,
a10 = m, a11 = m, a12 = m, a13 = m,
a20 = m, a21 = m, a22 = m, a23 = m,
a30 = m, a31 = m, a32 = m, a33 = m

// DIVISION BY ZERO HERE:
var lw = 1 / (x * a03 + y * a13 + z * a23 + a33)

out = (x * a00 + y * a10 + z * a20 + a30) * lw
out = (x * a01 + y * a11 + z * a21 + a31) * lw
out = (x * a02 + y * a12 + z * a22 + a32) * lw
return out
}