30 lines
No EOL
1.1 KiB
Text
30 lines
No EOL
1.1 KiB
Text
/*
|
|
contributors: Patricio Gonzalez Vivo
|
|
description: Convert camera depth to view depth. based on https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk/packing.msl.js
|
|
use: <float> viewZ2depth( <float> viewZ, [, <float> near, <float> far] )
|
|
options:
|
|
- CAMERA_NEAR_CLIP
|
|
- CAMERA_FAR_CLIP
|
|
- CAMERA_ORTHOGRAPHIC_PROJECTION, if it's not present is consider a PERECPECTIVE camera
|
|
license:
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Prosperity License - https://prosperitylicense.com/versions/3.0.0
|
|
- Copyright (c) 2021 Patricio Gonzalez Vivo under Patron License - https://lygia.xyz/license
|
|
*/
|
|
|
|
#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 |