-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix error when using the reflection component on desktop browsers #5384
Fix error when using the reflection component on desktop browsers #5384
Conversation
The real issue is why there is a enter-vr event when you click on fullscreen icon I think. Is this expected? |
@vincentfretin personally I rely on the current behavior of the event being fired when immersive mode is entered (headset) or fullscreen is activated (desktop). I also find this to make things consistent across the differen platforms. AFAIK this is also a very long standing behavior, so I am not sure how tricky it is to change it... Just my two cents |
Have you tried 1.5.0 on the XR starter kit and without this PR? The enter VR flow and UI have changed. And yeah that code shouldn't run. Components should not check for the session unless in immersive mode |
src/components/scene/reflection.js
Outdated
@@ -45,7 +45,7 @@ module.exports.Component = register('reflection', { | |||
var renderer = self.el.renderer; | |||
var session = renderer.xr.getSession(); | |||
if ( | |||
session.requestLightProbe && self.el.is('ar-mode') | |||
session && session.requestLightProbe && self.el.is('ar-mode') |
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.
can do an early return if (!self.el.is('ar-mode')) { return; }
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.
I have reworked the commit according to your suggestion 👍
88fbb04
to
94ae721
Compare
src/components/scene/reflection.js
Outdated
@@ -61,9 +60,9 @@ module.exports.Component = register('reflection', { | |||
this.xrLightProbe = null; | |||
if (this.probeLight) { | |||
this.probeLight.components.light.light.intensity = 0; | |||
this.needsVREnvironmentUpdate = true; |
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.
we still need to move these?
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.
I am not sure: on one hand I do not see why the VR environment needs to be updated again if no light probes have been added, on the other hand recalculating should not have any effect if the light conditions have not changed, e.g. these line should be harmless...
However (full disclosure), in a use case of mine this does make a difference, specifically this happens: the scene starts "bright enough", but if I toggle the fullscreen mode, upon exiting fullscreen this becomes suddenly much darker.
I am unfortunately unable to reproduce this behavior on a public domain asset at the moment. I will remove the moving of these lines for the time being and will open a different PR if I manage to collect further understanding of the issue. So far I believe it has to do to light conditions at start of the scene being different from those at a later time (e.g. after a model has loaded).
I have tried cloning https://github.com/AdaRoseCannon/aframe-xr-boilerplate and using https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-master.min.js instead of the original https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-master.min.js I can still reproduce this particular issue. Something else seem to be off unrelated to this problem concerning light and model loading, see screenshot: |
What do you mean by off? Could be related to #5383? |
I don't think so: if you look at the ceiling in the screenshot you will see that textures belonging to the window are rendered. It is also very dark compared to the expected behavior, see screenshot from the original page: |
94ae721
to
4f49761
Compare
I think it could be related to #5383 I mentioned. Can you try?
|
The a-scene definition in https://github.com/AdaRoseCannon/aframe-xr-boilerplate/blob/glitch/index.html is quite involved and e.g. just the renderer definition looks like:
hence, color management is true regardless of the A-Frame version. I have tried setting colorManagement to false, again on 1.5.0, and the result is the same as in the first "dark" screenshot |
In case you're not aware in // Once the building has loaded update the reflections
building.addEventListener('object3dset', function () {
if (this.components && this.components.reflection) this.components.reflection.needsVREnvironmentUpdate = true;
}, {once: true}); to update the reflection map after the building model is loaded. |
Dear @vincentfretin I was not aware of this, it might explain the behavior I encounter! Still, I am still not sure if the VR environment should be updated again when extit-vr is emitted and no probe has been set. Do you you have an opinion on this? |
If you are in AR and then exit, it make sense to update the reflection, yes, the probe is removed so the lighting changed and the map need to be recalculated. |
Indeed and I agree. But what if we were not in AR mode, hence the probe was not set at all? In this case we are computing the new light for nothing imo. |
I'm actually using the reflection component on non AR/VR scene, just on desktop. It takes into account the lights in the aframe scene and calculate an envmap. |
Of course, this is done once at init time (or better, at the first valid tick) regardless of mode and works on every platform. What I mean is that if one does not enter AR mode, no further updates to the envmap are required: only in AR mode we have the case of the component adding another light to the scene. |
This is my understanding of how it works. |
By looking at the code it looks as the directionalLight property comes into play only if this.xrLightProbe is set aframe/src/components/scene/reflection.js Lines 126 to 138 in c9b51a2
The only way this.xrLightProbe can be set, is if setupLightProbe is executed aframe/src/components/scene/reflection.js Lines 71 to 109 in c9b51a2
which can only happen if this.needsLightProbeUpdate is set to true by the startLightProbe method aframe/src/components/scene/reflection.js Lines 148 to 153 in c9b51a2
aframe/src/components/scene/reflection.js Lines 68 to 70 in c9b51a2
My argument is simply that, as startLightProbe will never be executed as long as we do not enter AR mode (as it is the case on desktop), there is not need to recalculate the light upon exiting vr mode in this case. In practice, if we assume the lights on a scene to be stable, it should not make any visual difference that we recalculate once or a 1000 times the envmap whenever we exit fullscreen, so my argument only concerns a possible performance improvement and not a functional change. In my use case it bites me only because the light conditions at startup (before my model is loaded) are different from those later, but I should address it by fixing my lights on the scene rather than relying on the current behavior. I am not sure if there is something I don't understand here, but in any case the current changes in this PR are sufficient to address the original error and there is no really need for further changes from my side. Many thanks for the time and effort reviewing this! |
Oh I just understood what you were saying. Yeah, calling |
Thanks so much! |
Dear maintainers,
when opening the excellent boilerplate example available at https://aframe-xr-starterkit.glitch.me/ with a desktop browser such as Chrome, upon entering fullscreen mode, the console will complain about:
The code responsible for this error seem to be relevant only to AR mode and to my understanding should not be executed in other contexts. I have simply ensured that the session is not null to fix the problem.
Additionally, I have also changed that the VR environment update performed in stopLightProbe is executed only if a light probe was set up in the first place (e.g. startLightProbe was executed), which again seems to be supposed to happen only in limited circumstances.
All the best