1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
uniform sampler2D Tex_Sampler;
varying vec2 texcoord;
uniform bool NoiseEffect;
vec4 rand(vec2 A,vec2 B,vec2 C,vec2 D){
vec2 s=vec2(12.9898,78.233);
vec4 tmp=vec4(dot(A,s),dot(B,s),dot(C,s),dot(D,s));
return fract(sin(tmp) * 43758.5453)* 2.0 - 1.0;
}
float noise(vec2 coord,float d){
vec2 C[4];
float d1 = 1.0/d;
C[0]=floor(coord*d)*d1;
C[1]=C[0]+vec2(d1,0.0);
C[2]=C[0]+vec2(d1,d1);
C[3]=C[0]+vec2(0.0,d1);
vec2 p=fract(coord*d);
vec2 q=1.0-p;
vec4 w=vec4(q.x*q.y,p.x*q.y,p.x*p.y,q.x*p.y);
return dot(vec4(rand(C[0],C[1],C[2],C[3])),w);
}
void main(void)
{
vec4 tex_color = texture2D(Tex_Sampler,texcoord.st);
if (tex_color.a>0 && NoiseEffect ){
vec4 noisevec;
float level=-log2(min(length(dFdx(texcoord.st)),length(dFdy(texcoord.st))));
level = min(level,10.0); //limit the level to avoid slowness
float n = 0.35;
for(int i = 3; i< level;i++){ //3 is the lowest noise level
n += 0.80 * noise(texcoord.xy+fTime, exp2(i));
}
noisevec = vec4(n*0.5,0.7,0.1,1);
tex_color = noisevec;
}
gl_FragColor = tex_color;
} |
Partager