I am trying to access a texture in a fragment shader to overlay this texture over a certain area.
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform sampler2D u_sampler2D;
uniform vec4 u_oldcolor;
uniform vec4 u_newcolor;
uniform vec3 u_noise;
void main(){
vec4 color = texture2D( u_sampler2D , v_texCoord0 ) ;
float threshold = 0.005f;
if(color.r <= (u_oldcolor.r + threshold) && color.g <= (u_oldcolor.g + threshold) && color.b <= (u_oldcolor.b + threshold)
&& color.r >= (u_oldcolor.r - threshold) && color.g >= (u_oldcolor.g - threshold) && color.b >= (u_oldcolor.b - threshold)){
color.rgb = u_newcolor.rgb + vec3(v_texCoord0, 0.1);
}
gl_FragColor = color ;
}
For every pixel the shader checks for a certain color and replaces it with a new color+v_texCoord0.
Now I am want to bring in a third component: a noise texture to make it look like this:
I searched the web for a solution but I could not find anything helpful.
My questions: 1.Is this even possible to accomplish via a shader? 2.How to access the texture ?
I hope that my questions are clear and proper for this forum :) .