I have a texture in a fragment shader where I want to calculate the difference value between two neighbour texels in that texture.
I want to calculate it according to this formula:
bs = b[s+1,t] - b[s,t] which is along the s-coordinate and
bt = b[s,t+1] - b[s,t] which is along the t-coordinate in that texture
Now, in my fragment shader these are the essential predefined variables (I have also other variables too but I post those that are the important ones):
uniform sampler2D texUnit; //The texture map
void main(void)
{
float offset = 1.0 / 256.0; // texture size
vec2 texCoord = gl_TexCoord[0].xy; //The maps coordinates
vec4 c = texture2D(texUnit, texCoord);
float bs = ?;
float bt = ?;
}
Now from what I understand you have to access the texels in a certain way from the vector c and you want to take the s and t coordinates from that vector. But I don’t know how since that vector consists of four elements. I have been looking at various tutorial and the more I read the more confused I get. In one tutorial it says that the four-dim texture2D vector represents rgba values and in other one says it represents xyzw values. So, can you explain how I obtain the texels and calculate the differences?