summaryrefslogtreecommitdiff
path: root/advanced_lighting/6.hdr/shaders/hdr.frag
blob: f12c6a8494d476d9de8554de2a38e9c8b63fd816 (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
#version 330 core

in VSOUT {
	vec2		texc;
} vsout;

out vec4		fcolor;

uniform sampler2D	hdrbuf;
uniform float		exposure;

void main(void)
{
	const float	gamma = 2.2;

	vec3		hdrcolor, mapped;

	hdrcolor = vec3(texture(hdrbuf, vsout.texc));

	/* NOTE(pryazha): Reinhard tone mapping */
	/* mapped = hdrcolor/(hdrcolor+vec3(1.0)); */

	/* NOTE(pryazha): Tone mapping with exposure (i guess) */
	mapped = vec3(1.0)-exp(-hdrcolor*exposure);

	mapped = pow(mapped, vec3(1.0/gamma));

	fcolor = vec4(mapped, 1.0);
}