0
\$\begingroup\$

As shown in the image below I'm trying to find the points in which a line in the world space intersect a sprite. The idea was to get the corresponding values inside a shader to play around with pixel visibility but it seems that I cannot wrap my head around the problem in the correct way. What would be the best approach to achieve the result?

enter image description here

Edit: To clarify, what I'm trying to do is rendering a stickyman on a line, hiding what lies below that line. See picture below

enter image description here

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Safe to assume you're working in 2D? Within a shader, you probably won't be able to determine P1, P2 (because it would require in the worst case sampling every texel along the line to find the first & last intersections with certainty - unless your sprites have some mathematical regularity we can exploit, signed distance info, etc.), but you could determine for a given fragment, "am I on the 'right' side of the line or the 'left' side?" which might be what you need for rendering purposes? If not, it would help to edit your question to explain in more detail what you're using this to achieve. \$\endgroup\$
    – DMGregory
    Commented Apr 18, 2023 at 23:44
  • \$\begingroup\$ @DMGregory I elaborated the question to be clearer as per your suggestion, thanks. My understanding of these matter is pretty limited so please apologize if something is not completely clear to me. For my understanding your guess should be the right case, as I need to do something with what is below the line, that is set those part to transparent. \$\endgroup\$
    – Leggy7
    Commented Apr 19, 2023 at 6:38
  • \$\begingroup\$ You could probably do this even easier with little depth buffer foolery: after the background is drawn, draw a closer polygon to the depth buffer (but not the colour buffer) before drawing your stick figure. Any parts of your stick figure under the invisible occluder will get z-rejected, without having to change its shader. I'm not sure offhand how to execute something like this in Godot though. I'd recommend editing your question to ask "How to hide part of character under slope" (your end goal) if you're open to alternative ways of achieving this that don't involve world to texture coords. \$\endgroup\$
    – DMGregory
    Commented Apr 19, 2023 at 8:38
  • \$\begingroup\$ @DMGregory I'm definitely am. Thanks again for you suggestions. I changed the title and opened my mind to explore alternatives \$\endgroup\$
    – Leggy7
    Commented Apr 19, 2023 at 10:55
  • \$\begingroup\$ This makes me think that the shape that needs to be hidden from the Sprite might be more complex than a line segment. For example, if it were positioned at the bottom a V shape, we might have to deal with two segments. And the situation might be worse if there can be multiple small segments near each other. Now, is there a solid polygon that you could simply draw on top the Sprite, or do we need to think about making a mask or some other trickery? \$\endgroup\$
    – Theraot
    Commented Apr 19, 2023 at 16:26

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.