huaner
05-07-2007, 12:50 AM
hi:
i write a effect of shader that a quad has two texture and the second texture inside the first texure.the shader as fellow:
vertex:
varying vec2 tex1;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord0;
tex1 = gl_MultiTexCoord0;
gl_Position = ftransform();
}
fragment:
uniform sampler2D TextureUnit0;
uniform sampler2D TextureUnit1;
varying vec2 tex1;
void main()
{
vec4 value1 = texture2D(TextureUnit0, gl_TexCoord[0]);
vec4 value2 = texture2D(TextureUnit1, gl_TexCoord[1]);
if(tex1.x >= 0.2 && tex1.y >= 0.2 &&
tex1.x <= 0.8 && tex1.y <= 0.8)
gl_FragColor = value2;
else
gl_FragColor = value1;
}
http://blog.163.com/chunjiao_106/blog/getBlog.do?bid=_fks__aB0ExprET-V6OsKCyQARN2EKcj0kp8E
the problem is there is a black quad below the effect quad, and turn back the background picture. May the texture coordnate that i deal with is wrong?
i write a effect of shader that a quad has two texture and the second texture inside the first texure.the shader as fellow:
vertex:
varying vec2 tex1;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord0;
tex1 = gl_MultiTexCoord0;
gl_Position = ftransform();
}
fragment:
uniform sampler2D TextureUnit0;
uniform sampler2D TextureUnit1;
varying vec2 tex1;
void main()
{
vec4 value1 = texture2D(TextureUnit0, gl_TexCoord[0]);
vec4 value2 = texture2D(TextureUnit1, gl_TexCoord[1]);
if(tex1.x >= 0.2 && tex1.y >= 0.2 &&
tex1.x <= 0.8 && tex1.y <= 0.8)
gl_FragColor = value2;
else
gl_FragColor = value1;
}
http://blog.163.com/chunjiao_106/blog/getBlog.do?bid=_fks__aB0ExprET-V6OsKCyQARN2EKcj0kp8E
the problem is there is a black quad below the effect quad, and turn back the background picture. May the texture coordnate that i deal with is wrong?