Pixel-Composer/shaders/sh_posterize/sh_posterize.fsh

29 lines
653 B
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform int colors;
2023-08-01 19:21:51 +02:00
uniform int alpha;
2023-12-23 09:39:55 +01:00
uniform vec2 gamma;
uniform int gammaUseSurf;
uniform sampler2D gammaSurf;
2022-01-13 05:24:03 +01:00
void main() {
2023-12-23 09:39:55 +01:00
float gam = gamma.x;
if(gammaUseSurf == 1) {
vec4 _vMap = texture2D( gammaSurf, v_vTexcoord );
gam = mix(gamma.x, gamma.y, (_vMap.r + _vMap.g + _vMap.b) / 3.);
}
2022-01-13 05:24:03 +01:00
vec4 _col = texture2D( gm_BaseTexture, v_vTexcoord );
2023-08-01 19:21:51 +02:00
vec4 c = _col;
2023-12-23 09:39:55 +01:00
c = floor(pow(c, vec4(gam)) * float(colors));
c = pow(c / float(colors), vec4(1.0 / gam));
2023-08-01 19:21:51 +02:00
if(alpha == 1) gl_FragColor = c;
else gl_FragColor = vec4(c.rgb, _col.a);
2022-01-13 05:24:03 +01:00
}