Skip to content

Instantly share code, notes, and snippets.

@JBlackCat
Last active August 26, 2023 17:36
Show Gist options
  • Save JBlackCat/30f0273d61c668f9877c2491699be56c to your computer and use it in GitHub Desktop.
Save JBlackCat/30f0273d61c668f9877c2491699be56c to your computer and use it in GitHub Desktop.
Linear Vertical Gradient Fragment Shader
uniform vec4 u_gradient_color_1;//#fa67ba
uniform vec4 u_gradient_color_2;//#b17ff5
uniform float u_gradient_alpha_color_1;//0:1:0.53
uniform float u_gradient_alpha_color_2;//0:1:1.00
uniform float u_gradient_location_color_1;//0:1:0.00
uniform float u_gradient_location_color_2;//0:1:0.96
vec4 LinearVertGradient(float yCoord, vec4 color_1, float alpha_color_1, float location_color_1, vec4 color_2, float alpha_color_2, float location_color_2) {
color_1.a = alpha_color_1;
color_2.a = alpha_color_2;
float mPct = smoothstep(location_color_1, location_color_2, yCoord);
return mix(color_1, color_2, mPct);
}
void main() {
vec2 vUV = gl_FragCoord.xy/resolution.xy;
vec4 pixelOut = LinearVertGradient(vUV.y, u_gradient_color_1, u_gradient_alpha_color_1, u_gradient_location_color_1, u_gradient_color_2, u_gradient_alpha_color_2, u_gradient_location_color_2);
gl_FragColor = pixelOut;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment