I am trying to access a texture in a fragment shader to overlay this texture over a certain area. This is how it looks at the moment

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: How it should look like

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 :) .


1 Answer 1


To get noise in a shader you can:

a) Just calculate the noise in the shader

b) Simpler, use a (precalculated) noise texture. Just add another sampler and use it as you want.

  • \$\begingroup\$ How to add another sampler that has a custom texture stored? Edit: ohh okay i found it:) , thanks :) \$\endgroup\$
    – Klitz
    May 18, 2014 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .