|
发表于 2012-12-28 11:16:38
|
显示全部楼层
//blend.vert
#version 110
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
//blend.frag
uniform sampler2D Texture0;
uniform smapler2D Texture1;
uniform sampler2D BlendTexture;
//blend texture stores a blend factor using r and g channel,the real blend factor
//can be evaluated by the following formula:
// blend_factor = (BlendTexture.r + BlendTexture.g / 256.0)
void main(void)
{
vec2 texCoord = gl_TexCoord[0].xy;
vec4 color0 = texture2D(Texture0,texCoord);
vec4 color1 = texture2D(Texture1,texCoord);
vec4 blend_factor = texture2D(BlendTexture,texCoord);
float factor = (blend_factor.r + blend_factor.g / 256.0);
gl_FragColor = mix(color0,color1,factor);
}
这是一段简单的融合着色器代码,但是如果你要让你所绘制的物体在背景之中呈现半透明的话,那这段代码是不行的,因为OpenGL的融合过程是在其固定管线之中完成的,位于片段着色器之后。你自己研究下OpenGL渲染管线就清楚了... |
|