funny-animated-gif-from-pro.../shaders/fragment.glsl
2021-02-01 16:07:15 -05:00

37 lines
1.3 KiB
GLSL

/*
Copyright (C) 2021 hiimgoodpack
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 <https://www.gnu.org/licenses/>.
*/
#version 330 core
in vec2 vFragCoord;
uniform float aHorizontalOffset;
uniform sampler2D aTexture;
void main() {
float distanceFromCenterSquared = dot(vFragCoord, vFragCoord);
// alpha = 0 if fragment is outside circle
// alpha = 1 if fragment is inside circle
float alpha = distanceFromCenterSquared > 1 ? 0 : 1;
// An equation which seems to work
float specular = distanceFromCenterSquared * (-0.5f*vFragCoord.x + vFragCoord.y) + 1;
vec2 texCoord = vFragCoord * vec2(0.5,0.5) + vec2(0.5+aHorizontalOffset,0.5);
gl_FragColor = vec4(texture(aTexture, texCoord).xyz*specular, alpha);
}