Problematic Raycasting of Offscreen THREE.Sprite object

I was debugging an issue from library using threejs where mouseover event was getting triggered for every offscreen THREE.Sprite objects.

Upon further research it seems like the raycaster responsible for emitting mouse events falsely detects intersections with offscreen THREE.Sprite objects.

Looking through the code for THREE.Sprite it seems like raycasting for sprite object is treated specially, and is dependent on modelViewMatrix variable.

However, if I am understanding this correctly, updating modelViewMatrix is solely handled by the shader, thus it does not get updated if it does not get rendered, i.e. offscreen.

Since the variable used in calculation is inaccurate, it follows that raycasting to offscreen THREE.Sprite objects are also inaccurate, and is probably causing the weird bug I’m having.

So my situation is that after all that I have no idea where I should go about fixing this issue. Is this an issue of three.js? or the library I’m using? or my application?

If it is the fault of my application, is there a way to detect if THREE.Sprite object is offscreen so that I can safely ignore it?

I would love to hear your thoughts on this issue.

That’s not true. The modelViewMatrix is calculated in WebGLRenderer but only if the object is going to be rendered.

There is an example about raycasting with sprites. I was not able to produce intersections when sprites are outside of the viewport. Please alter the example and provide it as a live demo in order to demonstrate the bug.

Ah, my apologies. I am not too fond of how rendering works in threejs yet.

However it seems like the point that modelViewMatrix does not get updated when offscreen still stands.

I will get back to you after I have reproduced the issue by modifying the example you’ve provided.

@Mugen87 I have successfully reproduced the issue with the provided example.

You will see nothing in screen. This is because the sprite is offscreen at coordinate (-5000, 0, 0).

However, if you hover over the screen, you will see that it triggers the logic where sprite is detected with raycasting. (It outputs 'hovered' to developer console)

1 Like

Thanks for the fiddle :+1:

Yes, I can confirm this is a bug. As you said, using the modelViewMatrix in Sprite.raycast is problematic since it might be reflect a wrong transformation. I think it’s best when you open an issue at github. Please add the fiddle to your bug report.

I’ve created an issue:

1 Like

Sorry for the late response and thanks for submitting an issue for me!