We have a custom Unity surface shader which generates some procedural patterns.

However we are getting very bad moire effects when the pattern frequency is too high (made worse by distance, surface angle).

I would like to apply some kind of blur on the texture to reduce this moire effect. All of the shader blur examples I can find rely on sampling surrounding pixels from the texture bitmap. Since we've generated the pattern procedurally per pixel, such a bitmap doesn't exist.

Does anyone know how we might introduce some kind of blur effect in this case, to reduce the moire?

Thank you.

  • \$\begingroup\$ You could render the procedural pattern to a texture at the start, create mipmaps from it and solve it the old fashioned way? Might not be applicable to your use case of course. \$\endgroup\$ – Elva Feb 17 '17 at 12:25
  • 1
    \$\begingroup\$ @UpTheCreek no, it's about pre-rendering your pattern to a texture (through a FBO, if memory serves), then using that texture. Nothing gets ported to the CPU. \$\endgroup\$ – Quentin Feb 17 '17 at 13:32
  • 1
    \$\begingroup\$ You can sample surrounding points in your procedural pattern by feeding multiple different inputs to your custom shading function. This does of course multiply its cost. Less brute-force solutions will depend on what the pattern is and how you generate it (eg. if your procedural pattern is differentiable, we might be able to compute its derivatives and use those to smooth the effect. Or if it uses octaves of noise we might be able to selectively fade the higher frequencies). Try editing your question to include more details/pictures/code of the specific effect you're trying to improve. \$\endgroup\$ – DMGregory Feb 17 '17 at 13:35
  • 1
    \$\begingroup\$ You can ask about each one of your algorithms in its own question (one at a time) to get custom solutions suited to each one. In terms of general solutions that can be applied without these details, you've basically seen what we can offer: run the function multiple times and average, bake to a texture, or maybe fade to a fallback colour/texture based on visible scale? If you need more than that, we'll need to get specific to each effect. \$\endgroup\$ – DMGregory Feb 17 '17 at 15:09
  • 1
    \$\begingroup\$ @UpTheCreek never used them myself, but this tutorial looks solid. From what I've understood, you bind the FBO in place of the window's buffer, attach a texture to the FBO, and render as normal. The rendered pixels then go to the texture. \$\endgroup\$ – Quentin Feb 17 '17 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.