Jump to content
  • Advertisement
Sign in to follow this  
strivingJuno

GLSL and intelligent texture blending

This topic is 2904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi out there,

I got a task for which I do not have a solution. Hope somebody can help me.

Let be given two textures T0 and T1 that correspond to pictures of the same scene taken at different positions. T0 and T1 overlap each other. However, if the textures are stitched together there is a seam visible, caused by inhomogene lighting and/or camera distortions. A very effective solution to get rid of the seam is to gradually blend from one texture to the other.

So far so good - I've implemented this in GLSL by adding to each texture a transparent border that gets gradually opaque. (Hell yeah, I know, my GLSL skills are not yet very outstanding.)


// Vertex shader.
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}





// Fragment shader.
uniform sampler2D tex;

const float BORDER_SIZE = 0.1;

void main(void)
{
vec4 activeColor = gl_Color;

vec4 color = texture2D(tex, gl_TexCoord[0].st);
color.a = 1.0;

float s = gl_TexCoord[0].s;
float t = gl_TexCoord[0].t;

if(s < BORDER_SIZE)
{
color.a = color.a*(1/BORDER_SIZE)*s;
}
if(s > 1-BORDER_SIZE)
{
color.a = color.a*(1/BORDER_SIZE)*(1-s);
}
if(t < BORDER_SIZE)
{
color.a = color.a*(1/BORDER_SIZE)*t;
}
if(t > 1-BORDER_SIZE)
{
color.a = color.a*(1/BORDER_SIZE)*(1-t);
}
gl_FragColor = color;
}





And here is the problem I have: The way I do alpha-blending leads to fuzzy edges regardless whether there is overlap or not (I set the alpha channel for each texture seperately). What I actually want is that there is only gradual alpha-blending at regions where the textures overlap - the other edges should remain unaffected. How to do this in GLSL? How to do this efficiently?

Thanks a lot for any hint!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!