Give specific color to texture in fragment shader

Hi,

I am trying to apply a specific color to a texture that is added to a circle that is drawn in the fragment shader. However the texture won’t take the color. In the following jsfiddle I have drawn a red circle with a green border. Inside the red circle I would like to add the texture and apply any color to that texture. In the jsfiddle I am trying to make this texture blue.
https://jsfiddle.net/tqn9k4ha/18/

I’m not sure what you mean, i don’t see any green border, but maybe like this?
https://jsfiddle.net/02smryLf/

Or like this: https://jsfiddle.net/prisoner849/f4xkdzu7/
There is no green border because there is no data in the respective attribute.
This line needs to be added: borderColor.toArray(this._bordercolors, i * 3)

I updated the jsfiddle https://jsfiddle.net/tqn9k4ha/20/
However it’s not about the border, I want to color the texture without the color of the background interfering.

So, that’s how you can do it in the shader:

          uv = gl_PointCoord;
          uv.y = 1. - uv.y;
          float texValue = texture2D(textures[0], uv).r;
          
          vec4 col = vec4(0, 1, 1, 1); // the color of texture
	  gl_FragColor = mix(gl_FragColor, col, texValue);

Like that? https://jsfiddle.net/ykou3t1b/

Your fiddle does the trick, but could you explain what you did?
uv = gl_PointCoord;
uv.y = 1. - uv.y;
float texValue = texture2D(textures[0], uv).r;
vec4 col = vec4(1, 1, 1, 1); // This is the color I can change?
gl_FragColor = mix(gl_FragColor, col, texValue);

Yes like that thank you. How exactly does this work?

You just added the texture color (additive blending basically), instead you need to alpha blend them gl_FragColor = mix(gl_FragColor, texture, texture.a);

Will need to look into blending more to fully understand, but thank you @Fyrestar and @prisoner849 for your help.

2 Likes