summaryrefslogtreecommitdiff
path: root/src/render/shaders/glsl/blurFinish.glsl
blob: bdfe2bc8891812e398e0da7cc07e485c84733522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef ALLOW_INCLUDES
#define ALLOW_INCLUDES
#extension GL_ARB_shading_language_include : enable
#endif

#include "defines.h"

#if USE_CM
#include "cm_helpers.glsl"
#endif

float hash(vec2 p) {
    vec3 p3 = fract(vec3(p.xyx) * 1689.1984);
    p3 += dot(p3, p3.yzx + 33.33);
    return fract((p3.x + p3.y) * p3.z);
}

vec4 blurFinish(vec4 pixColor, vec2 v_texcoord, float noise, float brightness
#if USE_CM
                ,
                int sourceTF, int targetTF, mat3 convertMatrix, vec2 srcTFRange, vec2 dstTFRange
#endif
) {
    // noise
    float noiseHash   = hash(v_texcoord);
    float noiseAmount = noiseHash - 0.5;
    pixColor.rgb += noiseAmount * noise;

    // brightness
    pixColor.rgb *= min(1.0, brightness);

#if USE_CM
    if (targetTF == CM_TRANSFER_FUNCTION_EXT_LINEAR) {
        pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, vec2(0.0, 203.0)); // FIXME wtf
    } else {
        pixColor = doColorManagement(pixColor, sourceTF, targetTF, convertMatrix, srcTFRange, dstTFRange);
    }
#endif

    return pixColor;
}