overte-HifiExperiments/libraries/render-utils/src/ssao_mip_depth.slf
2018-09-18 10:22:35 +02:00

38 lines
1.1 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$>
//
// ssao_mip_depth.frag
// fragment shader
//
// Created by Olivier Prat on 4/18/18.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
<@include gpu/ShaderConstants.h@>
layout(binding=GPU_TEXTURE_MIP_CREATION_INPUT) uniform sampler2D depthTexture;
in vec2 varTexCoord0;
out vec4 outFragColor;
void main(void) {
vec4 depths = textureGather(depthTexture, varTexCoord0);
// Order the depths from minimum to maximum
depths.xy = depths.x > depths.y ? depths.yx : depths.xy;
depths.xz = depths.x > depths.z ? depths.zx : depths.xz;
depths.xw = depths.x > depths.w ? depths.wx : depths.xw;
depths.yz = depths.y > depths.z ? depths.zy : depths.yz;
depths.yw = depths.y > depths.w ? depths.wy : depths.yw;
depths.zw = depths.z > depths.w ? depths.wz : depths.zw;
// Take the median depth
float outZ = (depths.y + depths.z) / 2.0;
outFragColor = vec4(vec3(outZ), 1.0);
}