overte-JulianGro/libraries/render-utils/src/BloomThreshold.slf
2018-10-23 10:40:12 -07:00

44 lines
1.4 KiB
Text

<@include gpu/Config.slh@>
<$VERSION_HEADER$>
// BloomThreshold.frag
// Perform a soft threshold on an input texture and downsample to half size in one go.
//
// Created by Olivier Prat on 09/26/2017
// Copyright 2017 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 BloomThreshold.shared.slh@>
<@include render-utils/ShaderConstants.h@>
LAYOUT(binding=RENDER_UTILS_TEXTURE_BLOOM_COLOR) uniform sampler2D colorMap;
LAYOUT_STD140(binding=RENDER_UTILS_BUFFER_BLOOM_PARAMS) uniform parametersBuffer {
Parameters parameters;
};
layout(location=0) in vec2 varTexCoord0;
layout(location=0) out vec4 outFragColor;
void main(void) {
vec2 startUv = varTexCoord0;
vec4 maskedColor = vec4(0,0,0,0);
for (int y=0 ; y<parameters._sampleCount ; y++) {
vec2 uv = startUv;
for (int x=0 ; x<parameters._sampleCount ; x++) {
vec4 color = texture(colorMap, uv);
float luminance = (color.r+color.g+color.b) / 3.0;
float mask = clamp((luminance-parameters._threshold)*0.25, 0.0, 1.0);
color *= mask;
maskedColor += color;
uv.x += parameters._deltaUV.x;
}
startUv.y += parameters._deltaUV.y;
}
maskedColor /= float(parameters._sampleCount * parameters._sampleCount);
outFragColor = vec4(maskedColor.rgb, 1.0);
}