Hey, thanks for reading this but I have a question regarding GLSL and texture coords.
Say I have the following shader program:
//note, 128.0 is the size of the texture width, hardcoded for now, needs to change
//to uniform variable.
void bilerp(in vec2 coords, out vec4 qtynew, in sampler2D qty)
{
//figure out the texture coords
vec4 st;
st.xy = coords-1.0/128.0; //implied translation into texture simulation domain.
st.zw = st.xy + 1.0/128.0; //top right corner of the "neighbor hood"
//now access the texture
vec4 t11 = texture2D(qty,st.xy);
vec4 t21 = texture2D(qty,st.zy);
vec4 t12 = texture2D(qty,st.xw);
vec4 t22 = texture2D(qty,st.zw);
//now lerp
vec2 factor = (coords - st.xy)*128.0; //Factor is in simulation domain!
//bilerp, such that, we compute lerp:
//l1 = 11 to 21, l2 = 12 to 22, lerping long the x axis.
//final = l1 to l2, lerping along the y axis. Please refer to any documentation on bilerp.
qtynew = mix(mix(t11,t21,factor.x),mix(t12,t22,factor.x),factor.y);
}
Where is exactly is the "center" of the texture coord?
In Mark Harris' GPU gem article, he uses CG. And he does this by adding a 0.5, which according to his comments is due to the fact that the center of a texel is 0.5, i.e 0.5, 1.5, ...
Mark Harris had something like this:
float4 f4texRECTbilerp(samplerRECT tex, float2 s)
{
float4 st;
st.xy = floor(s - 0.5) + 0.5;
st.zw = st.xy + 1;
float2 t = s - st.xy; //interpolating factors
float4 tex11 = f4texRECT(tex, st.xy);
float4 tex21 = f4texRECT(tex, st.zy);
float4 tex12 = f4texRECT(tex, st.xw);
float4 tex22 = f4texRECT(tex, st.zw);
// bilinear interpolation
return lerp(lerp(tex11, tex21, t.x), lerp(tex12, tex22, t.x), t.y);
}
Notice his offset of 0.5.
So how does GLSL translate?
I don't notice any difference from toggling between 0.5 and 1.0.