YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
26 stars 8 forks source link

Mipmapping Support On Surfaces #4325

Open XorDev opened 10 months ago

XorDev commented 10 months ago

Is your feature request related to a problem?

Having large radius blur shaders, bloom and Depth of Field effects are generally quite slow and complicated. To do it more efficiently, you have to run the shader in multiple passes, which takes some extra effort and know-how to set up. As a side note, texture2DLod doesn't work either and that'd be nice to have too. image

Describe the solution you'd like

You have mipmapping support for surfaces, you can do full screen blur effects cheaply and easily without multiple steps. I put together a strong blur effect for Construct engine that is fast and high-quality, but I still can't do so in GM image

Describe alternatives you've considered

There are alternatives. We can build mipmaps ourselves by down sampling the surface progressively, but this will not be nearly as efficient as the shader supported mipmapping. We also have options like Dual Kawase blur, but that only works for some effects and can be more limited to work with. Mipmapping isn't perfect, but it's a great generalized solution that can save time and complexity

Additional context

No response

XorDev commented 10 months ago

Oops, I forgot I already made a request for this. I couldn't find it when I searched earlier https://github.com/YoYoGames/GameMaker-Bugs/issues/3003

mistletoe commented 10 months ago

There is a good way to solve this problem without mipmaps. You can render a Surface to another Surface that's a smaller size, then use the downsampled result to perform a big blur, then render the result to the required resolution.

XorDev commented 10 months ago

Believe me, I've definitely considered this, but it has several drawbacks. Texture sampling is a complex process, so any manual solution is going to be much slower than a native solution. Downsampling this way will use more texture pages, more uniform samplers (we're limited to 8), more edge cases to handle (trilinear interpolation at the texture edges, handling non-power-of-2 sizes, texture repeat, texture LOD calculations). It would be slow, clunky and only practical in a few niche cases

mistletoe commented 10 months ago

To be sure, you'll use a bit more texture memory when you do downsampling to another Surface that way, but it should be OK. I'd try a simple experiment with doing downsampling this way and see. I'm doing this for one blurring process over here and it's pretty straightforward. The VRAM costs are entirely reasonable if you're not throwing around lots of unnecessary Surfaces and destroy anything you don't need right now.