p5js/参考/p5-reference/assets/shader-gradient.frag
2022-12-07 20:42:16 +08:00

22 lines
582 B
GLSL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Code adopted from "Creating a Gradient Color in Fragment Shader"
// by Bahadır on stackoverflow.com
// https://stackoverflow.com/questions/47376499/creating-a-gradient-color-in-fragment-shader
precision highp float; varying vec2 vPos;
uniform vec2 offset;
uniform vec3 colorCenter;
uniform vec3 colorBackground;
void main() {
vec2 st = vPos.xy + offset.xy;
// color1 = vec3(1.0,0.55,0);
// color2 = vec3(0.226,0.000,0.615);
float mixValue = distance(st,vec2(0,1));
vec3 color = mix(colorCenter,colorBackground,mixValue);
gl_FragColor = vec4(color,mixValue);
}