-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
The Behavior of RenderFlusher #737
Comments
That code does SSAA. By default everything is rendered with a pixel_ratio of 2, and when the offscreen buffer is rendered to screen there's two possible cases:
This triage happens here: pygfx/pygfx/renderers/wgpu/engine/flusher.py Lines 177 to 185 in eb0b089
I've tweaked the parameters at the time for visually appealing results, but it can well be that for text a more crisp result is desired. So we may want to re-tweak the BTW, the filter strength can be set with the |
Out of interest, how are you using wgpu with imgui? I think an example that uses imgui would be very interesting since a lot of downstream projects are eager for solutions to have simple gui elements ... |
I am using the library imgui-bundle, which provides Python bindings for imgui. After refactoring and optimizing the code, I will submit a PR. I am considering how to encapsulate the API, and I may submit separate PRs to the wgpu-py and pygfx libraries. |
I thought that as long as we rendered the scene at a higher resolution and then downsampled (using a linear filtering sampler), it would be considered SSAA, 😅
I tried setting the pixel_filter to 0, and the text did become sharper, but the scene aliasing was quite noticeable. Can we provide an option in the Renderer that allows users to disable the current behavior of the RenderFlusher (directly using a linear-filtering sampler instead)? Additionally, we could provide an option to enable MSAA (hardware acceleration). Regarding the API design, I have the following two suggestions:
If you agree, I can submit a PR. |
I think the first option makes the most sense, since you can have both ssaa and msaa at the same time.
It kindof is. Except if the screen is hidpi (and the pixel ratio already matches) we can just blit the pixels, so its not saa, really. We've now opted for a tiny bit of smoothing in this case, but we can remove/reduce that. Linear filtering is technically not an appropriate kernel to downsample data. It now uses a Gaussian filter, but now that I'm thinking about this I recall this is also not ideal - especially for small sigmas - because the data is discrete. I will look into some old code that implements Lindeberg's diffusion kernel. Apart from that, we could tune the kernel down a bit. The current behavior when the And we can do #75 :) If you want to look into msaa, I can have a look at improving the "ssaa" filtering. |
Okay, I will try to add MSAA. |
I've noticed before that compared to other engines, when rendering the same scene, pygfx sometimes appears "slightly blurry" in the rendering result. This is not very noticeable in most cases.
However, in my recent use of
![image](https://private-user-images.githubusercontent.com/8044566/324359111-4f72e9ae-d5ca-41fb-892b-18ce60e81dcd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxNjQwNDQsIm5iZiI6MTcxOTE2Mzc0NCwicGF0aCI6Ii84MDQ0NTY2LzMyNDM1OTExMS00ZjcyZTlhZS1kNWNhLTQxZmItODkyYi0xOGNlNjBlODFkY2QucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjNUMTcyOTA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2Q1YjhlNjk2NDg2ZTkwMWU2OWFhYmE0Yzc1ZGM5NmJhODM4MGMxNTQyMmIwYmNhNDM5NjhmYjA5NDQ2MzNjNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.kw9W4ccB3A09n1HFMvmgvZuNDoZX7jUGKfQR6VjEw_Y)
imgui
(integrated with wgpu), I found that the imgui elements (especially fonts) appeared very blurry when rendering.After some investigation, it seems that this is caused by the behavior of pygfx's
RenderFlusher
.pygfx/pygfx/renderers/wgpu/engine/flusher.py
Lines 253 to 270 in eb0b089
If I understand correctly, the logic here is to implement the MSAA algorithm in the shader? This seems to be causing the blurriness in the result.
As a comparison, the following are the results of not using RenderFlusher's current behavior:
![image](https://private-user-images.githubusercontent.com/8044566/324359367-e443772b-5de0-4bec-ad8f-c78b959e7862.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxNjQwNDQsIm5iZiI6MTcxOTE2Mzc0NCwicGF0aCI6Ii84MDQ0NTY2LzMyNDM1OTM2Ny1lNDQzNzcyYi01ZGUwLTRiZWMtYWQ4Zi1jNzhiOTU5ZTc4NjIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjNUMTcyOTA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2U1OTYwNGYzNjA4MzE0MDk2ZjFiNzk0Y2IzYmMwZWQzNTVkMDVlNzQ2YTMwYzAyN2NjODYyNTk4NGNmMWM0ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.P20mHnnGsbw8oF_9SxRUeIVSxHXJ5pE5AuMFB0lCdls)
Additionally, wgpu can support MSAA in hardware. Is there any special consideration behind the logic of RenderFlusher here?
The text was updated successfully, but these errors were encountered: