Click on 3D object with shader

Hi, Guys

  1. I have some issue with clicking on a 3D objects functionality. I determine if I click on it or no by ray intersection with 3D object’s bounding boxes and it works great but then I added vertex shader which move vertices to other positions and now 3D objects on a screen and their bounding boxes doesn’t much to each other positions. So how can I detect if I click on 3D object if it’s vertices positions changes in each frame by some shader?

  2. And one more question, I attach the shader, I mentioned above, to all my materials, but I also use Text Component in World layer on this scene. How I can apply the vertex shader also to world text component?

Thanks

you can make a 3d object with the same text in a 3d model maker or something so instead of it being text, it is a 3d object

I would do it. But I need to change the text sometimes, so it should be as a text element.

i found a 3d model website that has text models

1 Like
  1. There’s no easy answer to this, you would have to recalculate the bounding box ‘somehow’ which is difficult because the processing is in a shader. You may want to consider framebuffer picking instead Entity Picking | Learn PlayCanvas

  2. This involves private API to do at the moment. You have to get the element component, access the _text property that contains the actual text element bit and set the material via _setMaterial: engine/text-element.js at 69dfe65c9bc94fc612f6489733de987a76df1a8a · playcanvas/engine · GitHub

TLDR, this would be this.entity.element._text._setMaterial(customMaterialWithShader);

1 Like

@yaustar Appreciate a lot.

  1. Works like a charm, even better that using ray casting.
  2. Thanks, it works. Any chance that it will became like public parameter in future?

It’s not planned but we have a ticket to track the progress of something like this: Create API to assign a material to a text UI element · Issue #4076 · playcanvas/engine · GitHub

Please comment on the GitHub issue to add support for adding this feature

1 Like