Using regl, I am trying to draw a triangle with WebGL where I can define a color at some reference point inside the triangle, and have the color of the other pixels be a function of their distance to this point.
So far, it only works when this reference point is one of the corner :
gradient from corner
This was done using the following Vert and Frag shaders :
vert: `
precision mediump float;
uniform float scale;
attribute vec2 position;
attribute vec3 color;
varying vec3 fcolor;
void main () {
fcolor = color;
gl_Position = vec4(scale * position, 0, 1);
}
`,
frag: `
precision mediump float;
varying vec3 fcolor;
void main () {
gl_FragColor = vec4(sqrt(fcolor), 1);
}
`,
attributes: {
position: [
[1, 0],
[0, 1],
[-1, -1]
],
color: [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1]
]
},
uniforms: {
scale: regl.prop('scale')
}
The reference points here are [1,0], [0,1] and [-1,-1]. With the same triangle, how do I put another reference point at [0,0] with color white for instance ? (that would give an "island" of white inside the triangle)