mame/3rdparty/bgfx/examples/45-bokeh/fs_bokeh_linear_depth.sc
Miodrag Milanović 812e6094f4
Update BGFX, BX and BIMG (#10789)
* Update to bgfx a93a714632b79b5ddbf5c86ac323fa9b76ed3433
Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
2023-01-05 09:32:40 -05:00

36 lines
1.0 KiB
Scala

$input v_texcoord0
/*
* Copyright 2021 elven cache. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "../common/common.sh"
#include "parameters.sh"
SAMPLER2D(s_depth, 0);
// from assao sample, cs_assao_prepare_depths.sc
float ScreenSpaceToViewSpaceDepth( float screenDepth )
{
float depthLinearizeMul = u_depthUnpackConsts.x;
float depthLinearizeAdd = u_depthUnpackConsts.y;
// Optimised version of "-cameraClipNear / (cameraClipFar - projDepth * (cameraClipFar - cameraClipNear)) * cameraClipFar"
// Set your depthLinearizeMul and depthLinearizeAdd to:
// depthLinearizeMul = ( cameraClipFar * cameraClipNear) / ( cameraClipFar - cameraClipNear );
// depthLinearizeAdd = cameraClipFar / ( cameraClipFar - cameraClipNear );
return depthLinearizeMul / ( depthLinearizeAdd - screenDepth );
}
void main()
{
vec2 texCoord = v_texcoord0;
float depth = texture2D(s_depth, texCoord).x;
float linearDepth = ScreenSpaceToViewSpaceDepth(depth);
gl_FragColor = vec4_splat(linearDepth);
}