fuckingtech/public/assets/glsl/lygia/space/viewZ2depth.glsl
Elias Rhouzlane bf76c6b086 fix: code
2025-04-06 17:23:52 +02:00

30 lines
No EOL
1.1 KiB
GLSL

/*
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.glsl.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 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