"uniform float xDerivative;\n"
"uniform float yDerivative;\n"
"uniform sampler2D paletteSampler;\n"
- "vec4 texture2DPaletteResize(sampler2D sampler, highp vec2 texC) {\n"
- "float a = texture2D(sampler, texC).a;\n"
- "float a1 = texture2D(sampler, texC + vec2(xDerivative, 0.)).a;\n"
- "float a2 = texture2D(sampler, texC + vec2(0., yDerivative)).a;\n"
- "float a3 = texture2D(sampler, texC + vec2(xDerivative, yDerivative)).a;\n"
- "vec4 color = texture2D(paletteSampler, vec2(a, .5));\n"
- "vec4 color1 = texture2D(paletteSampler, vec2(a1, .5));\n"
- "vec4 color2 = texture2D(paletteSampler, vec2(a2, .5));\n"
- "vec4 color3 = texture2D(paletteSampler, vec2(a3, .5));\n"
- "vec2 f = fract(texC.xy / vec2(xDerivative, yDerivative));\n"
- "return mix(mix(color, color1, f.x), mix(color2, color3, f.x), f.y);\n"
+ "vec4 texture2DPaletteResize(sampler2D sampler, highp vec2 texC)\n"
+ "{\n"
+ " float a = texture2D(sampler, texC).a;\n"
+ " float a1 = texture2D(sampler, texC + vec2(xDerivative, 0.)).a;\n"
+ " float a2 = texture2D(sampler, texC + vec2(0., yDerivative)).a;\n"
+ " float a3 = texture2D(sampler, texC + vec2(xDerivative, yDerivative)).a;\n"
+ " vec4 color = texture2D(paletteSampler, vec2(a, .5));\n"
+ " vec4 color1 = texture2D(paletteSampler, vec2(a1, .5));\n"
+ " vec4 color2 = texture2D(paletteSampler, vec2(a2, .5));\n"
+ " vec4 color3 = texture2D(paletteSampler, vec2(a3, .5));\n"
+ " vec2 f = fract(texC.xy / vec2(xDerivative, yDerivative));\n"
+ " return mix(mix(color, color1, f.x), mix(color2, color3, f.x), f.y);\n"
"}\n"
- "vec4 texture2DPalette(sampler2D sampler, highp vec2 texC) {\n"
- "float a = texture2D(sampler, texC).a;\n"
- "return texture2D(paletteSampler, vec2(a, .5));\n"
+ "vec4 texture2DPalette(sampler2D sampler, highp vec2 texC)\n"
+ "{\n"
+ " float a = texture2D(sampler, texC).a;\n"
+ " return texture2D(paletteSampler, vec2(a, .5));\n"
"}\n"
"#endif\n"
"#ifdef SHD_ALPHA\n"
"#ifdef SHD_FILTER_ROUNDED_CORNER\n"
"uniform vec2 corner_radius;\n"
"uniform vec2 resolution;\n"
+ "highp float nrand(const in vec2 uv)\n"
+ "{\n"
+ " const highp float a = 12.9898, b = 78.233, c = 43758.5453, pi = 3.141592653589793;\n"
+ " highp float dt = dot(uv, vec2(a, b)), sn = mod(dt, pi);\n"
+ " return fract(sin(sn) * c);\n"
+ "}\n"
+ "vec3 applyDithering( vec3 inColor )\n"
+ "{\n"
+ " float rnd = nrand(tex_c) - 0.5;\n"
+ " inColor.rgb += rnd / 255.0;\n"
+ " return inColor;\n"
+ "}\n"
"float roundedBoxSDF(vec2 p, vec2 size, float r) {\n"
" return length(max(abs(p)-size+r,0.0)) - r;\n"
"}\n"
" c.rgb = c.a - c.rgba;\n"
"#endif\n"
"#ifdef SHD_FILTER_ROUNDED_CORNER\n"
+ " float radius =\n"
+ " mix(\n"
+ " mix(corner_radius.x, corner_radius.y, sign(coord.x)*0.5 + 0.5),\n"
+ " mix(corner_radius.x, corner_radius.y, sign(coord.x)*0.5 + 0.5),\n"
+ " sign(coord.y) * 0.5 + 0.5\n"
+ " );\n"
" vec2 location = resolution / 2.0;\n"
- " float edgeSoftness = 1.0;\n"
- " float radius = 30.0;\n"
+ " float edgeSoftness = min(1.0, radius);\n"
" float distance = roundedBoxSDF(gl_FragCoord.xy - location, location, radius);\n"
- " float smoothedAlpha = smoothstep(0.0, edgeSoftness, distance);\n"
+ " float smoothedAlpha = smoothstep(-edgeSoftness, edgeSoftness, distance);\n"
" c = mix(c, vec4(0.0), smoothedAlpha);\n"
+ " c.rgb = applyDithering(c.rgb);\n"
"#endif\n"
"#ifndef SHD_FILTER_BLUR\n"
" gl_FragColor =\n"
#ifdef SHD_FILTER_ROUNDED_CORNER
uniform vec2 corner_radius;
uniform vec2 resolution;
+
+highp float nrand(const in vec2 uv)
+{
+ const highp float a = 12.9898, b = 78.233, c = 43758.5453, pi = 3.141592653589793;
+ highp float dt = dot(uv, vec2(a, b)), sn = mod(dt, pi);
+ return fract(sin(sn) * c);
+}
+
+vec3 applyDithering( vec3 inColor )
+{
+ float rnd = nrand(tex_c) - 0.5;
+ inColor.rgb += rnd / 255.0;
+ return inColor;
+}
+
+
float roundedBoxSDF(vec2 p, vec2 size, float r) {
return length(max(abs(p)-size+r,0.0)) - r;
}
#endif
#ifdef SHD_FILTER_ROUNDED_CORNER
+ float radius =
+ mix(
+ mix(corner_radius.x, corner_radius.y, sign(coord.x)*0.5 + 0.5),
+ mix(corner_radius.x, corner_radius.y, sign(coord.x)*0.5 + 0.5),
+ sign(coord.y) * 0.5 + 0.5
+ );
+
vec2 location = resolution / 2.0;
- float edgeSoftness = 1.0;
- float radius = 30.0;
+ float edgeSoftness = min(1.0, radius);
float distance = roundedBoxSDF(gl_FragCoord.xy - location, location, radius);
- float smoothedAlpha = smoothstep(0.0, edgeSoftness, distance);
+ float smoothedAlpha = smoothstep(-edgeSoftness, edgeSoftness, distance);
c = mix(c, vec4(0.0), smoothedAlpha);
+ c.rgb = applyDithering(c.rgb);
#endif
#ifndef SHD_FILTER_BLUR