enve/examples/shaderEffects/eDots.frag

61 lines
1.9 KiB
GLSL
Raw Permalink Normal View History

2019-08-24 15:07:28 +00:00
// enve - 2D animations software
2020-01-02 19:46:10 +00:00
// Copyright (C) 2016-2020 Maurycy Liebner
2019-08-24 15:07:28 +00:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2019-08-12 10:25:38 +00:00
#version 330 core
layout(location = 0) out vec4 fragColor;
2019-08-12 10:25:38 +00:00
in vec2 texCoord;
layout(pixel_center_integer) in vec4 gl_FragCoord;
uniform sampler2D texture;
2020-03-04 13:44:52 +00:00
uniform vec2 translate;
uniform float dotDistance;
uniform float dotRadius;
uniform float opacity;
uniform vec2 scenePos;
2019-08-12 10:25:38 +00:00
void main(void) {
bool inDot;
float mixAlpha;
2020-03-04 13:44:52 +00:00
vec2 transformedCoord = scenePos - translate + gl_FragCoord.xy;
2019-08-12 10:25:38 +00:00
2020-03-04 13:44:52 +00:00
vec2 dotID = floor(transformedCoord/dotDistance + 0.5);
vec2 posInDot = transformedCoord - dotID*dotDistance;
float distToCenter = sqrt(posInDot.x*posInDot.x +
posInDot.y*posInDot.y);
2019-08-12 10:25:38 +00:00
float distToEdge = distToCenter - sqrt(dotRadius*dotRadius);
if(distToEdge > 0.f) {
inDot = false;
} else {
distToEdge = abs(distToEdge);
inDot = true;
if(distToEdge < 1.f) {
2019-12-19 20:54:11 +00:00
mixAlpha = opacity + distToEdge*(1. - opacity);
2019-08-12 10:25:38 +00:00
} else {
mixAlpha = 1.f;
}
}
2019-12-19 20:54:11 +00:00
vec4 texCol = texture2D(texture, texCoord);
2019-08-12 10:25:38 +00:00
if(inDot) {
fragColor = vec4(mixAlpha*texCol.rgb, mixAlpha*texCol.a);
2019-08-12 10:25:38 +00:00
} else {
2019-12-19 20:54:11 +00:00
fragColor = vec4(opacity*texCol.rgb, opacity*texCol.a);
2019-08-12 10:25:38 +00:00
}
}