lygia
/space
/viewZ2depth
)Convert camera depth to view depth. based on https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk/packing.glsl.js
Use:
<float> viewZ2depth( <float> viewZ, [, <float> near, <float> far] )
#ifndef FNC_VIEWZ2DEPTH
#define FNC_VIEWZ2DEPTH
float viewZ2depth( const in float viewZ, const in float near, const in float far ) {
#if defined(CAMERA_ORTHOGRAPHIC_PROJECTION)
return ( viewZ + near ) / ( near - far );
#else
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
#endif
}
#if defined(CAMERA_NEAR_CLIP) && defined(CAMERA_FAR_CLIP)
float viewZ2depth( const in float viewZ) {
return viewZ2depth( viewZ, CAMERA_NEAR_CLIP, CAMERA_FAR_CLIP);
}
#endif
#endif
Use:
<float> viewZ2depth( <float> viewZ, [, <float> near, <float> far] )
#ifndef FNC_VIEWZ2DEPTH
#define FNC_VIEWZ2DEPTH
float viewZ2depth( const in float viewZ, const in float near, const in float far ) {
#if defined(CAMERA_ORTHOGRAPHIC_PROJECTION)
return ( viewZ + near ) / ( near - far );
#else
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
#endif
}
#if defined(CAMERA_NEAR_CLIP) && defined(CAMERA_FAR_CLIP)
float viewZ2depth( const in float viewZ) {
return viewZ2depth( viewZ, CAMERA_NEAR_CLIP, CAMERA_FAR_CLIP);
}
#endif
#endif
Use:
<float> viewZ2depth( <float> viewZ, [, <float> near, <float> far] )
#ifndef FNC_VIEWZ2DEPTH
#define FNC_VIEWZ2DEPTH
float viewZ2depth( const float viewZ, const float near, const float far ) {
#if defined(CAMERA_ORTHOGRAPHIC_PROJECTION)
return ( viewZ + near ) / ( near - far );
#else
return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
#endif
}
#if defined(CAMERA_NEAR_CLIP) && defined(CAMERA_FAR_CLIP)
float viewZ2depth( const float viewZ) {
return viewZ2depth( viewZ, CAMERA_NEAR_CLIP, CAMERA_FAR_CLIP);
}
#endif
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository