Mipmapping example

I’d like to use mipmapping in a final shader pass but I can’t seem to get it to work. I know I need to use mipmap_inputN = true, but otherwise I’m lost. When I sample the source texture it just turns out the same? Can someone post an example of a simple preset and shader that shows how it works or point me in the write direction?

The “ambient glow” border shader uses mips to get the average color. I believe there’s at least one video driver that just straight-up doesn’t do them properly, so you might be hitting that.

1 Like

Best you use it with the pass you are sampling from and with the pass you are sampling with. But you can test-debug the mip sampling further with various drivers…

A good example of mip sampling is:

vec3 avg = textureLod(Source, vec2(0.5, 0.5), m).rgb; // average screen rgb value

where mip-level m can be calculated:

float m = max(log2(SourceSize.x), log2(SourceSize.y));

You can also add:

m = ceil(m); // etc...
3 Likes

Indeed the keyworkd naming is misleading.

With mipmap_inputX you’re not telling that everything sampled by X can give a mipmap, but that pass X-1 will provide mipmaps to everything that samples from it (with some caveats about feedbacks).

This weird behaviour applies to other metadatas as well.

quoting my rant in the discord channel from years ago:

This was driving me crazy since days. Finally I understood, and is the same old (mis)behaviour of retroarch chain system. As we know, to have passN filtered,mipmapped,wrapped, you have to set those metadatas in passN+1.

However, to linear filter the mipmaps feedback of passN, you have to set filter=linear in the passN metadat itself, NOT passN+1

It probably applies to other metadatas too, but did not bothered to try. (EDIT- confirmed for wrap mode too)

Of course this is unoptimal and a bug, because feedback and previous pass share the same filtering and wrap modes.

And even then, mipmap_input metadata (good thing, no waste of performance) does not follow that rule. (read: mipmap_input1=true does not make textureLod(pass1Feedback,N) working)

2 Likes

@hunterk Ambient glow does not work for D3D12:

Vulkan:

Is the cause known? Will this issue be fixed?

Not that I’m aware, no. Seeing as it works on d3d11, though, it’s probably not too terribly hard to hook up. D3d12 was very new when those drivers were written and I don’t think anyone has put any more work into 12 since then.

2 Likes

D3D12 is the best performing driver for me in Windows, and probably for others, so I hope this can get fixed.

1 Like

Interesting article entitled “10 years of D3D12”.

2 Likes

What a mess D3D11/12 is, at least on Retroarch. To be avoided. Don’t know if that’s due to drivers, Retroarch or whatever.