This project is read-only.

So, the first shader pair will be a transparent glass, with special color filtering.

 

How it works

For colored glass contains color information, including alpha information. The alpha will control the output of fragment’s each channel.

The output of each channel is the product of fragment’s channel value and glass’s alpha, plus the product of glass’s channel value and 1 minus glass’s alpha.

 

Source code

Vertex Shader

// simple vertex shader

void main()

{

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

gl_FrontColor = gl_Color;

gl_TexCoord[0] = gl_MultiTexCoord0;

}

Fragment Shader

// Transparent coloured glass fragment shader

//

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

 

// *****Algorithm of the coloured**********

// Uniform filter contains the colour of glass and alpha information. alpha controls how much of color can

// pass through the glass.

//

// For each channel of out put fragment, the result is the fragment's channel value multiply glass's alpha and

// glass's channel value multiply (1 - glass's alpha).

//

// Take red channel as example:

// gl_FragColor.x=gl_FragColor.x*glass.w+glass.x*(1.0-glass.w);

//

//

// *****End of algorithm*********************

uniform float time;// 'time' contains seconds since the program was linked.

uniform sampler2D tex;

uniform vec4 glass;// colored glass

void main()

{

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

    // Code below almost the same as mix function, except that the alpha channel.

    // gl_FragColor=mix(glass, gl_FragColor, glass.w);

    gl_FragColor.x=gl_FragColor.x*glass.w+glass.x*(1.0-glass.w);

    gl_FragColor.y=gl_FragColor.y*glass.w+glass.y*(1.0-glass.w);

    gl_FragColor.z=gl_FragColor.z*glass.w+glass.z*(1.0-glass.w);

}


  

Screenshot


 

 

Pic 1. Original picture
RGBStrip600X400

 

Pic 2. Red glass,with alpha 0.5, glass=(1.0, 0.0, 0.0, 0.5)
ColoredGlass_red_alpha0.5

Last edited Mar 10, 2013 at 2:19 PM by younthu, version 7

Comments

No comments yet.