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

Make blur distance independent of resolution & FOV #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

omgitsraven
Copy link
Contributor

Previously, the image would always be blurred by a certain number of pixels, which meant that as the resolution increased, the apparent amount of blur (relative to the world/image) decreased (by staying the same as the resolution went up).

This new approach takes the resolution and FOV into account when determining how far across the texture to sample for the blur; this means that a given view of the world will always look (essentially) the same regardless of how "big" it's rendering.

The one problem that this fix reveals, is that for a sufficiently high resolution (or sufficiently narrow FOV), the step between blur samples may be noticeably larger than a single on-screen pixel, which would introduce a visual 'echoing' effect. In this case, the blur step distance value may be decreased until the problem is no longer visible -- the only downside to this is that doing so will decrease the distance over which the image is blurred (in world terms), which may be undesired. (This could be compensated for by adding more blur iterations, but as that's hardcoded into the shader as well as the CommandBuffer, there's no simple way to change that without manually editing the shader's code, as far as I'm aware.) Of course, users can also choose to adjust the blur step distance for purely aesthetic reasons, to change the range of possible amounts of diffusion that the values in the texture correspond to, so that's just a fun freebie :)

Previously, the image would always be blurred by a certain number of *pixels*, which meant that as the resolution increased, the apparent amount of blur (relative to the world/image) *decreased* (by staying the same as the resolution went up).

This new approach takes the resolution and FOV into account when determining how far across the texture to sample for the blur; this means that a given view of the world will always look (essentially) the same regardless of how "big" it's rendering.

The one problem that this fix reveals, is that for a sufficiently high resolution (or sufficiently narrow FOV), the step between blur samples may be noticeably larger than a single on-screen pixel, which would introduce a visual 'echoing' effect. In this case, the `blur step distance` value may be decreased until the problem is no longer visible -- the only downside to this is that doing so will decrease the distance over which the image is blurred (in world terms), which may be undesired. (This could be compensated for by adding more blur iterations, but as that's hardcoded into the shader as well as the CommandBuffer, there's no simple way to change that without manually editing the shader's code, as far as I'm aware.) Of course, users can also choose to adjust the `blur step distance` for purely aesthetic reasons, to change the range of possible amounts of diffusion that the values in the texture correspond to, so that's just a fun freebie :)
ugh, sorry; I wrote this up in my previous commit but forgot to actually paste it in :)
@omgitsraven
Copy link
Contributor Author

omgitsraven commented Jun 22, 2018

(edit: this is now fixed, see below)

Just FYI, the more I look at this in real-world scenarios, it seems to have a slight screen-aligned aliasing issue (which is extra noticeable in VR), that I'm not sure how to approach fixing... I think it's still an unambiguous step up over the previous screen-relative blurring, but I might be opening an issue for my own code once this is accepted, in hopes that someone with a bit more knowledge of these things can tweak its look just a bit more :)

@omgitsraven
Copy link
Contributor Author

hang on, I might have found
A) a workaround, and
B) an unrelated issue that only happens in VR :) Stay tuned.

The calculations were totally wrong in cases where the render target size did not match the "screen" size (i.e. for cameras with non-identity viewport rects, i.e. stereo VR rendering!)
@omgitsraven
Copy link
Contributor Author

Hahahah, the "unrelated issue" was NOT unrelated at all, it was in fact the cause of the quality problems I was seeing too. Glad I caught that. Quality is now perfect in VR as well as in 2D, no more screen-space aliasing, no "quality" fixes needed after all. Good to go.

@omgitsraven
Copy link
Contributor Author

Not to be a pest, but is anything wrong with this PR? (Only asking because the last one went in right away..)

@andydbc
Copy link
Owner

andydbc commented Jul 3, 2018

@omgitsraven I was quite busy recently and didn't had much time to review this PR, will do this week.

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

Successfully merging this pull request may close these issues.

2 participants