It is possible. Albeit we would employ some assumptions/epsilons but yes, you can do this. It means you need to query for collision repeatedly – because the collision routines consider the geometry (ignoring whether the texture at them is transparent or not). So you need to make a collision query, then look if you hit a transparent pixel on a texture, and if yes – make a new collision query from a new origin.
To do this:
-
You need to use a more general method
MyViewport.CameraRayCollision(RayOrigin, RayDirection)
. It returnsTRayCollision
, just likeMouseRayHit
(so it can be processed in the same way as above to detect the particular point). It takes as input ray position and direction. -
Use it in a loop.
-
The initial RayOrigin, RayDirection can come from the mouse position – use
MyViewport.PositionToRay
. -
Make a call to
MyViewport.CameraRayCollision(RayOrigin, RayDirection)
. If something was hit, but the texture pixel at the hit point is transparent, make another call toMyViewport.CameraRayCollision(NewRayOrigin, RayDirection)
. TheNewRayOrigin
should be “HitPosition + RayDirection.AdjustToLength(SomeEpsilon)”. -
The remaining task is to query the texture pixel at the hit point. To do this, note that
TRayCollisionNode
has a reference toTriangle
. UseTTriangle.ITexCoord
to get texture coordinate at the hit point, and finally use this texture coordinate to query the texture image (e.g. fromTImageTextureNode.TextureImage
). If the queried pixel has alpha < 0.5, you can consider it transparent, and thus repeat the call.
-