Sign in to follow this  

how to do color blending on specific texture coordinate using shader

This topic is 3726 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

hello, I am new to shader,need your help. I want to do color blending on specific texture coordinate,using shaders, which is: for texture1 : get part of texture from texture1 coordinate: 0-0.1 for texture2 : get part of texture from texture2 coordinate: 0.9-1 blend these two parts of texture, and save to texture 1 (0-0.1) and texture 2 (0.9-1) This is a normal edge blending algorithm, but I don't know if I use shaders, how can I do it. The most problem is that I don't know how to look up different texture coordinates at the same time. Thanks everyone!

Share this post


Link to post
Share on other sites
I'm not sure that I fully understand what you want to do, but I'll give it a try.

You can only read one color value at once, so you need multiple reads.

For reading just from 2 coordinates that you provide as a parameter to the shader, you'd do (I'm using CG here, so please check the correct syntax for GLSL):

float4 col1 = tex2d(texture1, texcoord1);
float4 col2 = tex2d(texture2, texcoord2);

You then blend col1 and col2 and process the result further (e.g. write it to one or more render targets).

Additionally, you could use an if statement to only blend if (texcoord1 >= 0 and texcoord1 <= 0.1) and (texcoord2 >= 0.9 and texcoord2 <= 1).

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord_Evil
I'm not sure that I fully understand what you want to do, but I'll give it a try.

You can only read one color value at once, so you need multiple reads.

For reading just from 2 coordinates that you provide as a parameter to the shader, you'd do (I'm using CG here, so please check the correct syntax for GLSL):

float4 col1 = tex2d(texture1, texcoord1);
float4 col2 = tex2d(texture2, texcoord2);

You then blend col1 and col2 and process the result further (e.g. write it to one or more render targets).

Additionally, you could use an if statement to only blend if (texcoord1 >= 0 and texcoord1 <= 0.1) and (texcoord2 >= 0.9 and texcoord2 <= 1).


thanks for your help, you are very nice. To clear my question, I think I can write in C language:

There are two byte arrays a[10][10], b[10][10], two dimension,same length, (which indicate two textures). What I want to do is:

for(int i=0;i<9;i++)
{
byte c=a[i][0]; //left most column of array a
byte d=b[i][9]; //right most column of array b
byte result=(c+d)/2
a[i][0]=result;
b[i][9]=result;
}

It is very simple in C, but in GLSL, I don't know if I can do this. In C language, I can look up arrays simply by a[5][2] or b[4][6], but in shader, seems like it is impossible to look up texel directly by texture[x][y], what I can do is just receive the color value by texture.xy. Is that right?

Thanks , I am a very newer

Share this post


Link to post
Share on other sites
Well, you can use point filtering on the texture to get just the texel at the coordinate (without filtering).

The texture coordinates normally are in the range [0;1] so the texel at position x would have the position x * 1/width + 1/(2 * width). The same applies to y.

I'm not sure, however, if you can write the values back to the texture you read them from. My machine doesn't support render targets other than the frame buffer so I could not do that yet. Maybe someone else can clarify that point.

Share this post


Link to post
Share on other sites

This topic is 3726 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this