• Advertisement
Sign in to follow this  

GLSL: how to determine uv sampling interval?

This topic is 2108 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, I'm performing custom anti-aliasing in GLSL for procedural textures and was wondering how to determine the uv sampling intervals between fragments. i.e. how to determine the approximate size of the filter area?

I know in Render-man these are the variables du and dv but how do you find them in GLSL?. I've looked at the dFdx/y functions but I'm not really sure how they work.

Thanks,

Share this post


Link to post
Share on other sites
Advertisement
dFdx and dFdy are what you're looking for. These will give you the rate of change of a variable in screen space. So for instance if your texture U coordinate is 0.2 at pixel (0,0) and it's 0.3 at (1, 0), then calling dFdx will give you a value of 0.1 since that's the difference in the X direction.

Share this post


Link to post
Share on other sites
Thanks,

I was about to post again to ask for help but I might have found the problem - I'm implementing a procedural strip texture using the code below and I was convinced there was something wrong with the code because it was producing weird results. After opening a black and white strip texture into GIMP and scaling the image to a lower resolution I got this:



testkl.png


which is the exact same artifacts that are showing up in my application. Any reason why this happens?



const float TILE_WIDTH = 1.0f/500.0;

// intergral function of a set of strips
float integral1(float s) {
float ss = s / TILE_WIDTH;
// get the strip index
float index = floor(ss);
float base = index*(TILE_WIDTH*0.5);
float relratio = ss - index;
float sint;
if(relratio <= 0.5) {
sint = base;
} else {
sint = base + ((TILE_WIDTH*0.5) * ((relratio-0.5)*2.0));
}
return sint;
}

float integral(float s, float t) {
return integral1(s) * t;
}

void main() {
vec2 st = gl_TexCoord[0].st;
// st change for on pixel in x
vec2 dvdx = dFdx(st);
// st change for one pixel in y
vec2 dvdy = dFdy(st);

// filter size in s
float sfs = max(abs(dvdx.s), abs(dvdy.s)) * 0.5;
// filter size in t
float tfs = max(abs(dvdx.t), abs(dvdy.t)) * 0.5;

float a = integral(st.s - sfs, st.t - tfs);
float b = integral(st.s + sfs, st.t - tfs);
float c = integral(st.s - sfs, st.t + tfs);
float d = integral(st.s + sfs, st.t + tfs);
float color = (d + a - b - c) / ((sfs*2) * (tfs*2));
gl_FragColor = vec4(color, color, color, 1);
}

Share this post


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

  • Advertisement