The effect I am trying to achieve is have a sprite split into two colors according to which side of an equation they’re on, like so:

The Way I thought I would go about that is to have two sprites, one colored blue, the other red, and use a sprite mask to hide one of the two sprites. I thought I would form a mesh with vertices on the line/equation and on the edges of the sprite and use that mesh as the sprite mask.

The problem is that I don’t know how to find which side of the equation a point is on. Sometimes the equation could enclose an area and that would be difficult too:

Is this a good idea and is it achievable or is this a bad idea and is there a better alternative?

Any help or discussion is appreciated!

I’m pretty sure this is doable with a custom shader, but I don’t know much about coding shaders so I can’t help you there.

The method you describe with a script-handled mesh is probably how I would do it too.

*“The problem is that I don’t know how to find which side of the equation a point is on”*

This can be solved by creating pairs of points along the equation. You begin by creating the first point at the start of the equation (Or anywhere if it loops), you then place the second point as close as you can to the first without sacrificing precision. Draw a vector perpendicular to the vector between the two points, and place the third point along that vector. Repeat for the whole equation.

You end up with two sets of points along the equation, that are paired up at each “step”. (See below: 1 & 3; 2 & 5) Then any point in space can be determined as either on one side of the equation or the other by finding the closest pair and checking which of the points in that pair is closer.

You can then use the points to create your mesh/meshes and to determine which color you want where. This also solves the enclosed area problem.