The second GLSL effect is a glass with textured mask.

 

How it works

It use mix fragment function to blend mask texture with the frag output.

 

Source code

 

VertexShader

// simple vertex shader

void main()

{

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

gl_FrontColor = gl_Color;

gl_TexCoord[0] = gl_MultiTexCoord0;

}


Fragment Shader

// Glass with textured mask.

//

// Created by Zhiyong Yang, younthu@yahoo.com.cn

//

// The effects of this fragment shader is a transparent glass with texture mask.

// It is implemented with blend function of GL ONE MINUS SRC ALPH, in another word,

// we use mix fragment function.

uniform float time;

uniform float alpha; // Control the alpha of textured mask

uniform sampler2D glassMask;

uniform sampler2D tex;

void main()

{

gl_FragColor = gl_Color * texture2D(tex,gl_TexCoord[0].xy);

vec4 mask=texture2D(glassMask,gl_TexCoord[0].xy);

gl_FragColor=mix(mask,gl_FragColor,alpha);

}

 

 

Screenshot

Original pictures
Texture
RGBStrip600X400


Mask

pond1


Glass with textured mask, alpha=0.5
GlassOfTexturedMask_alpha0.5

Last edited Mar 10, 2013 at 1:06 PM by younthu, version 1

Comments

No comments yet.