Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-default samplers #47

Closed
obs1dium opened this issue Oct 4, 2018 · 4 comments
Closed

Using non-default samplers #47

obs1dium opened this issue Oct 4, 2018 · 4 comments

Comments

@obs1dium
Copy link

obs1dium commented Oct 4, 2018

I've been playing around with the lens blur filter and noticed that it tends to produce ugly artifacts near the image edges, especially when using a large blur radius.
Using samplers with their address mode set to 'mirror repeat' alleviates this.
However, simply setting the input images sampler is insufficient, as the filter generates intermediate images which appear to fall back to the default sampler.
I tried two things:

  • explicitly 'forwarding' the input image's sampler in the filter to the intermediate images, i.e. calling imageWithSamplerDescriptor a bunch of times
  • replacing the samplers in the shader code by 'properly' configured ones

Both approaches worked, but maybe there's a better way?

@YuAo
Copy link
Member

YuAo commented Oct 5, 2018

Lens blur filter is not so much tuned so there may be other problems. The main idea is based on https://colinbarrebrisebois.com/2017/04/18/hexagonal-bokeh-blur-revisited/

About your question, I think both way is ok. I personally prefer the “fowarding” way. It gives the caller an opportunity to choose a different address mode (maybe clamp_to_edge works well too?)

You can send pull requests if you’d like to refine the lens blur filter.

@obs1dium
Copy link
Author

obs1dium commented Oct 5, 2018

I think 'clamp to edge' is the default, 'mirrored repeat' is really the only address mode that minimized edge artifacts for me.

@YuAo
Copy link
Member

YuAo commented Oct 5, 2018

The default sampler address mode of MTIImage is “clamp to zero”. We think this is the most logical default address mode - when you read a pixel outside an image you get zero.

@YuAo YuAo closed this as completed Oct 5, 2018
@obs1dium
Copy link
Author

obs1dium commented Oct 5, 2018

Ah, you're right, I was looking at the Metal language specs, not the MTISamplerDescriptor implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants