mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-14 03:56:41 +02:00
45 lines
1.3 KiB
Text
45 lines
1.3 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// BloomThreshold.slf
|
|
// 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
|
|
//
|
|
|
|
uniform sampler2D colorMap;
|
|
uniform float threshold;
|
|
|
|
in vec2 varTexCoord0;
|
|
out vec4 outFragColor;
|
|
|
|
#define DOWNSAMPLING_FACTOR 4
|
|
#define SAMPLE_COUNT (DOWNSAMPLING_FACTOR/2)
|
|
|
|
void main(void) {
|
|
vec2 deltaX = dFdx(varTexCoord0) / SAMPLE_COUNT;
|
|
vec2 deltaY = dFdy(varTexCoord0) / SAMPLE_COUNT;
|
|
vec2 startUv = varTexCoord0;
|
|
vec4 maskedColor = vec4(0,0,0,0);
|
|
|
|
for (int y=0 ; y<SAMPLE_COUNT ; y++) {
|
|
vec2 uv = startUv;
|
|
|
|
for (int x=0 ; x<SAMPLE_COUNT ; x++) {
|
|
vec4 color = texture(colorMap, uv);
|
|
float luminance = (color.r+color.g+color.b) / 3.0;
|
|
float mask = clamp((luminance-threshold)*0.25, 0, 1);
|
|
|
|
color *= mask;
|
|
maskedColor += color;
|
|
uv += deltaX;
|
|
}
|
|
|
|
startUv += deltaY;
|
|
}
|
|
maskedColor /= SAMPLE_COUNT*SAMPLE_COUNT;
|
|
outFragColor = vec4(maskedColor.rgb, 1.0);
|
|
}
|