Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Here is my current code in the shaders that have the adapt size option :

float adapted_blur_size = blur_size;
if (adapt_size == 1) {
// estimating screen UV → polygon UV
    float uv_to_px_x = dFdx(UV.x) / SCREEN_PIXEL_SIZE.x;
    float uv_to_px_y = dFdy(UV.y) / SCREEN_PIXEL_SIZE.y;
const float typical_box_size_over_screen_size = 0.2;
    float poly_scale = typical_box_size_over_screen_size * max(uv_to_px_x, uv_to_px_y) ;
    adapted_blur_size = blur_size / poly_scale;
adapted_blur_size = clamp(adapted_blur_size, adapt_size_min_max.x, adapt_size_min_max.y);
}

because  dFdx(UV.x) is the variation of UV between two neighboring pixels so we can estimate the total size of the polygon on the screen. You can do the same in your custom fragment shader.

Note that this "works" only because polygons are only boxes for now. I do this to avoid sending the bounding box for each polygon as a uniform. I will add the uniform bounding_box_size when censor polygons could have various shape.