-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
SSAO delayed resize fix #4342
SSAO delayed resize fix #4342
Conversation
Removed the resize timeout in the post effects queue. Removed the resizecanvas listener from the SSAO effect.
Please add the handling of this for the bloom as well. |
…I was working on.
Also fixed missing line in the vertex shader.
@@ -76,10 +72,6 @@ class PostEffectQueue { | |||
*/ | |||
this.resizeLast = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this.resizeLast still needed?
@@ -404,6 +368,8 @@ class PostEffectQueue { | |||
|
|||
for (let i = 0, len = effects.length; i < len; i++) { | |||
const fx = effects[i]; | |||
if (fx.effect.resize !== undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (fx.effect.resize !== undefined) | |
if (fx.effect.resize) |
BloomEffect.prototype.resize = function (target) { | ||
|
||
var width, height; | ||
if (target == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (target == null) { | |
if (target === null) { |
height = target.colorBuffer.height; | ||
} | ||
|
||
if (width == this.width && height == this.height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (width == this.width && height == this.height) | |
if (width === this.width && height === this.height) |
return; | ||
|
||
if (this.targets) { | ||
for (let i = 0; i < this.targets.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot use let
in ES5, only var
var width = Math.ceil(this.device.width / this.device.maxPixelRatio / this.downscale); | ||
var height = Math.ceil(this.device.height / this.device.maxPixelRatio / this.downscale); | ||
var width, height; | ||
if (target == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (target == null) { | |
if (target === null) { |
} else { | ||
width = Math.ceil(target.colorBuffer.width / this.device.maxPixelRatio / this.downscale); | ||
height = Math.ceil(target.colorBuffer.height / this.device.maxPixelRatio / this.downscale); | ||
} | ||
|
||
// If no change, skip resize | ||
if (width == this.width && height == this.height) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please use ===
here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving with some minor comments (please fix before the merge)
var width = Math.ceil(this.device.width / this.device.maxPixelRatio / this.downscale); | ||
var height = Math.ceil(this.device.height / this.device.maxPixelRatio / this.downscale); | ||
var width, height; | ||
if (target === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GSterbrant If the target is undefined this method will error (happens in line 561).
I guess it should be checked if the target is actually defined and instead of passing null
everywhere, just call the function without arguments?
@@ -577,11 +561,6 @@ SSAO.prototype.initialize = function () { | |||
this.effect.resize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion this resize should also happen if the effect is not enabled. Else we can have this situation:
User disables the effect -> User changes the downscale -> User enables the effect
Now we have the situation, that the render targets did not change in size although downscale
was changed
Also the new resize function should be added to the pc.PostEffect docs. |
Perhaps the resize function should be called internally within the effect, and not from the engine (post-effect-queue). Inside the render call, the effect should check the sizes of its internal buffers vs the source / target buffer it has, and rescale those internal buffers as needed. |
The effect itself doesn't know about the input target and has to defer to the graphics device for dimensions. The post effects queue knows about the input targets, and can therefore forward it to the effect when it's enabled/disabled. Wouldn't it be better if we can avoid dealing with resize related code if we're not resizing? |
the render function of the effect knows input and output handling size compare is not very expensive, we handle it in few places like this. It's simpler for the user / creator of the effect. engine/src/framework/scene-grab.js Lines 156 to 158 in 24f325f
|
This way you also avoid to maintain / handle resizing while the effect / camera is disabled and similar. Each time you render, you make sure targets are the right size. |
I like that approach. This way the resizing can be handled on a per post-effect instance. |
Also what i noticed, in the post-effect-queue the width and height is calculated like this: engine/src/framework/components/camera/post-effect-queue.js Lines 364 to 365 in 24f325f
In the bloom post effect like this: engine/scripts/posteffects/posteffect-bloom.js Lines 193 to 194 in 24f325f
And in ssao like this: engine/scripts/posteffects/posteffect-ssao.js Lines 391 to 392 in 24f325f
Shouldnt those calculations all be the same? Except for the downscale in the ssao effect. |
The issue of having to make this calculation at all is due to the fact that post effects are setup prior to knowing the input target. This will be fixed in the PR I am working on addressing these issues :). The post effect queue calculates the size of the internal targets, and really the effects should just read those values. The device dimensions shouldn't be used at all. |
I've made a PR here for these issues: #4397 |
Fixes #4239
Removed the resize timeouts. Added a general resize callback to the post effects such that they can handle resize.
Bloom needs such a callback to adapt it's internal targets (which should save performance when viewport is small).