Get color of sprite from ray pickingInfo

Is it possible to get the color of the sprite at the intersection with a given ray?

This topic is about the same thing but for textures on a mesh:

For my use case I’d like to get the color of the sprite at the intersection with a picking ray.

Hi @Censor

It’s funny cause I’m replaying about this issue, that I opened, and its solution a second time today :slight_smile:

I do not know if will it work with sprites. What it gives you when you try?

@Evgeni_Popov might give you some more insight on that :slight_smile: He helped me a lot along the years :slight_smile: Big shout tout to him :slight_smile:

Regards
Peter

You could copy what the sprite manager is doing to check picking is really inside a non alpha-0 pixel (when sprite.useAlphaForPicking=true):

You simply need to replace the end of the function with:

        const r = this._textureContent![(u + v * textureSize.width) * 4 + 0];
        const g = this._textureContent![(u + v * textureSize.width) * 4 + 1];
        const b = this._textureContent![(u + v * textureSize.width) * 4 + 2];
        const alpha = this._textureContent![(u + v * textureSize.width) * 4 + 3];

The calling code is inside the intersects function and let you know how the parameters to the _checkTextureAlpha call are computed:

5 Likes

Ok thanks both for your replies, I’ll try and see if that works for me. Will get back to you!

I tried getting this to work, but so far no luck.
I tried overriding the intersects method for setting a property on PickingInfo which included a Color4 with the color channels. I keep getting back each value as 0…

In my case, I have a pickingInfo on a sprite before I need to check the color. Is it possible to easily do this with the pickingInfo data instead?