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

UnrealBloomPass: Unify the display effect of pc and mob. #20798

Closed
wants to merge 6 commits into from

Conversation

gonnavis
Copy link
Contributor

@gonnavis gonnavis commented Dec 1, 2020

Related issue: -

Description

At present, the display effect of UnrealBloomPass on pc and mob is very inconsistent.

To make the difference more obvious, I changed the geometry based on the current example.
https://raw.githack.com/gonnavis/three.js/d588f473a695cf1409d5f2de46835823795b6929/examples/webgl_postprocessing_unreal_bloom.html

PC current:
image

MOB current:
image

I found that EffectComposer automatically multiplied devicePixelRatiao when setSize() caused this problem. And EffectComposer is very correct in doing so, fabric.js and create.js will automatically multiply the canvas size by devicePixelRatio to ensure high image quality on mobile devices too. So we can't change the code of EffectComposer.

Therefore, I think the shader author must consider the influence of devicePixelRatio by self.

After this pr:
https://raw.githack.com/gonnavis/three.js/0345cba81af86885f75bbf988d5aeb474248ce52/examples/webgl_postprocessing_unreal_bloom.html

PC after:
image

MOB after:
image

@@ -190,7 +190,7 @@ UnrealBloomPass.prototype = Object.assign( Object.create( Pass.prototype ), {
this.renderTargetsHorizontal[ i ].setSize( resx, resy );
this.renderTargetsVertical[ i ].setSize( resx, resy );

this.separableBlurMaterials[ i ].uniforms[ "texSize" ].value = new Vector2( resx, resy );
this.separableBlurMaterials[ i ].uniforms[ "texSize" ].value = new Vector2( resx / window.devicePixelRatio, resy / window.devicePixelRatio );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no guarantee of what a user has set the pixel ratio of the effect composer to or that they have set it at all in which case the effect will be inconsistent again so this doesn't feel like an adequate fix. I often change the pixel ratio dynamically, as well, depending on the run time performance of my application.

The postprocessing package deals with this by using a fixed render target resolution so the effect is consistent relative to the screen size. You can see an example of it in the blur demo. Something similar may be a better solution here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often change the pixel ratio dynamically, as well, depending on the run time performance of my application.

Hello @gkjohnson, thank you for your information, I'll research it. But why you change window.devicePixelRatio? Although it can be changed, but I think this parameter should be a parameter of a physical device and should not be changed. If really needed, can other new variable be used instead?

Copy link
Contributor

@makc makc Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he meant he changes the value on the composer, so you cant assume that it equals to window.devicePixelRatio that you used here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makc OK, thanks! I'll research more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he meant he changes the value on the composer, so you cant assume that it equals to window.devicePixelRatio that you used here

That's right -- I adjust it based on performance because it can have a significant impact. On some devices the pixel ratio is set to 3 or 4 so lowering it can help a lot without really sacrificing visuals.

Copy link
Contributor Author

@gonnavis gonnavis Dec 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mugen87 I found that, at least for this UnrealBloomPass, resolution is only used for initialize resx and resy, change resolution afterwards will no any effect.
And the initialized values will be overwritten by setSize() immediately, because when composer.addPass( bloomPass ); is called, composer will automatically call setSize().
However, uniform naming must be done, I'm trying.

Copy link
Contributor Author

@gonnavis gonnavis Dec 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a this.resizer to keep this.resolution untouched, so will not cause naming problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the initialization code in the constructor should also be deleted, because they will be overwritten by the code in setSize() immediately, there is no need to exist, and the code complexity can be simplified.

Copy link
Contributor Author

@gonnavis gonnavis Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkjohnson I found that this Resizer.js solution is fixed height, which will be very wasteful of performance under small size and wide-screen-ratio.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using Resizer.js will introduce too much complexity, and it also has performance problems under low resolution, so I don't want to use Resizer.js.

How about let EffectCompoer pass pixelRatio to Passs through setSize()?
Thus, Pass can aware of the current pixelRatio, even if it is manually modified?

https://github.com/mrdoob/three.js/pull/20798/files/b13d25e07bb466b22c96c808b5ce0c72a5d37ef7

@gonnavis gonnavis force-pushed the UnifyPcMobUnrealBloomPass branch from 32387a0 to 1ed1640 Compare December 2, 2020 10:22
@gonnavis gonnavis force-pushed the UnifyPcMobUnrealBloomPass branch from 1ed1640 to 60184fb Compare December 2, 2020 10:26
@gonnavis gonnavis marked this pull request as draft December 3, 2020 02:44
@gonnavis gonnavis force-pushed the UnifyPcMobUnrealBloomPass branch from 1a299a8 to 0096d29 Compare December 6, 2020 04:18
This was referenced Dec 10, 2020
@gonnavis gonnavis force-pushed the UnifyPcMobUnrealBloomPass branch from f769a55 to 9d4917f Compare December 14, 2020 10:46
@gonnavis gonnavis marked this pull request as ready for review December 15, 2020 07:44
@gonnavis gonnavis force-pushed the UnifyPcMobUnrealBloomPass branch from 8367fcc to 2df2213 Compare December 15, 2020 07:47
@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 3, 2021

Closing, see #20798 (comment).

@Mugen87 Mugen87 closed this Sep 3, 2021
@gonnavis
Copy link
Contributor Author

gonnavis commented Sep 3, 2021

@Mugen87 Hello, is this link wrong? I see the third page of pr list, not a specific pr.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 3, 2021

Link updated.

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.

4 participants