Shader related question

In the past, I’ve passed in the near and far clipping to the shader from JME.

What I’d really like to do is get at them from inside the shader without having to pass them in. How would one go about this? Which values from the ProjectionMatrix (or for that matter which ProjectionMatrixeS) represent these? Google was about as helpful as asking myself… lots of references to near/far as uniforms… nothing about extracting them from one of the matrix. I’m assuming the info is there… otherwise clipping wouldn’t happen.

Clipping would happen anyway because the values are clamped to 0-1…

I don’t think it’s easy to get the near/far out of the projection matrix since it’s not in it. It’s a separate value as far as I understand it. One need only look in Matrix4f.fromFrustum to see that you’d need to know a lot of other values to extract near/far.

You can enable FrustumNearFar as one of the g_ style uniforms and these values will be set for you automatically. There must be a reason for this global. If it were easy to get it from the projection matrix then there would be no issue. :slight_smile:

In my shaders, to find Z, I found it easier just to include it as a varying. The vert shader is already well aware of Z. If you find a reliable way of getting Z back from depth + near + far, then I can probably clean some things up.

1 Like