funny-animated-gif-from-pro.../shaders/fragment.glsl

38 lines
1.3 KiB
Text
Raw Normal View History

/*
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.
2021-02-01 23:07:15 +02:00
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.
2021-02-01 23:07:15 +02:00
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2021-01-29 04:49:11 +02:00
#version 330 core
2021-02-01 23:07:15 +02:00
in vec2 vFragCoord;
2021-01-29 04:49:11 +02:00
2021-02-01 23:07:15 +02:00
uniform float aHorizontalOffset;
uniform sampler2D aTexture;
2021-01-29 04:49:11 +02:00
void main() {
2021-02-01 23:07:15 +02:00
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;
2021-02-01 23:07:15 +02:00
vec2 texCoord = vFragCoord * vec2(0.5,0.5) + vec2(0.5+aHorizontalOffset,0.5);
2021-02-01 23:07:15 +02:00
gl_FragColor = vec4(texture(aTexture, texCoord).xyz*specular, alpha);
2021-01-29 04:49:11 +02:00
}