mastodon.gamedev.place is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server focused on game development and related topics.

Server stats:

5.5K
active users

Nikita Lisitsa

New blog post! The discussions about mipmapping alpha-tested textures made me wanna try all the methods I could find and post the results with a ton of textures to compare these methods: lisyarus.github.io/blog/posts/

lisyarus blogExploring ways to mipmap alpha-tested textures

@lisyarus Since you’re doing alpha stencil, you may want to treat the alpha channel as a signed distance field. It will get you smoother edges on your cutouts and regular mipmapping might just work.

@jkaniarz How exactly would I do that? I mean, just leaving it as it is already kinda treats it as an SDF. Do you mean preprocessing the alpha channel to make sure it is an SDF or smth?

@lisyarus I don’t know how to convert raster images to SDF other than counting pixel distance. But what I’m getting at is if your alpha channel was close to 50% at the edge of the sprite and tapered with distance, normal resizing algorithms would preserve that edge. Right now you’ve got a 0%, 100% cliff and are hoping it smooths out to something useful.

You’d still need to use some of your tricks for getting the color channel to not blend with the transparent area.

@jkaniarz I don't have a 0%/100% cliff, I'm only showing it in the article because that's what we'll see on screen. The actual alpha channel is smooth.

I know of ways to convert the images to an SDF, I'm just not sure what to do next with it. Do you suggest just downsampling it with usual averaging?

Btw Tristam on bluesky suggested sampling this SDF to directly generate all mipmap levels (without hierarchical construction), and it looks promising: bsky.app/profile/trist.am/post

Bluesky Social · Tristam (@trist.am)There was a bug in my sampling code, I think this is probably about as good a result as the single SDF method will produce (there may be some errors in the final mipmap during to the 4 sprites bleeding together)

@lisyarus That’s exactly what I’m getting at and it looks like he has more experience with it than me. I’ve only used SDF for text.

@lisyarus It does make sense that the coverage preservation method does not produce the desired results for your use case. That said, here are some things I would try:

- In your initial coverage calculation try different thresholds. We generally used higher values, but we were doing alpha to coverage, not alpha testing.
- Test the coverage of the bilinearly upsampled texture. See the implementation here: github.com/castano/nvidia-text

GitHubnvidia-texture-tools/src/nvimage/FloatImage.cpp at master · castano/nvidia-texture-toolsTexture processing tools with support for Direct3D 10 and 11 formats. - castano/nvidia-texture-tools

- Estimate the coverage locally, instead of globally. For example, using a small kernel around each texel, or only considering texels within a certain radius.

Another old-school alternative is to simply compute the mipmaps using nearest neighbor sampling, or selecting one of the 4 nearest samples randomly.

As others have pointed out, for the look that you seem to be targeting distance field methods may work best.

@lisyarus I'm very offended that you didn't find "my" absolutely perfect, no flaws, 100% perfect technique of arbitrarily scaling the alpha by the mip level wasn't the best option. Clearly this was user error and you just didn't use the correct arbitrary scaling factor.

(editor note: the technique was one that was floating around in tech art circles for years, and is at best a better than nothing approach.)

@lisyarus What do you actually want the final result to look like? Outlining kind of breaks down when stuff is too small, the theoretically "correct" result is that a curly flower face ends up being all outline.

@NohatCoder My outlines fade out with distance in a smart way to prevent this "everything is just an outline" situation. Thus I want the flower just to be visible, that's it

@lisyarus But if the outline is gone then you are going to get the aliasing you draw, so normal alpha blending would be the answer in this case. Of course that means you have to work out what happens in the crossover phase, so still tricky.

@NohatCoder True, but it is usually not in player's focus, and I'm hoping for it to get hidden by fog, weather effects, etc. So my current plan is to ignore aliasing on small distant objects :)