summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/render/bgfx/shaders/chains/misc/fs_lut.sc
blob: 2c8cffab7e12762e57dd4fd186dc673fae1b1d6f (plain) (blame)
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
$input v_color0, v_texcoord0

// license: BSD-3-Clause
// copyright-holders: W. M. Martinez

#include "common.sh"

#define LUT_TEXTURE_WIDTH 4096.0f
#define LUT_SIZE 64.0f
#define LUT_SCALE vec2(1.0f / LUT_TEXTURE_WIDTH, 1.0f / LUT_SIZE)

SAMPLER2D(s_tex, 0);
SAMPLER2D(s_3dlut, 1);

void main()
{
	vec4 bp = texture2D(s_tex, v_texcoord0);
	vec3 color = bp.rgb;
	// NOTE: Do not change the order of parameters here.
	vec3 lutcoord = vec3(color.rg * ((LUT_SIZE - 1.0f) + 0.5f) *
		LUT_SCALE, (LUT_SIZE - 1.0f) * color.b);
	float shift = floor(lutcoord.z);

	lutcoord.x += shift * LUT_SCALE.y;
	color.rgb = mix(texture2D(s_3dlut, lutcoord.xy).rgb,
		texture2D(s_3dlut, vec2(lutcoord.x + LUT_SCALE.y,
		lutcoord.y)).rgb, lutcoord.z - shift);
	gl_FragColor = vec4(color, bp.a) * v_color0;
}