I have created an object that is comprised of two bezier curves (constructed of an identical finite segments equal to a variable named
resolution). The two curves are then tessellated and filled in with a shader.
I would like to adjust shading within it based on a pixel's position relative to the object's coordinates (ie. a stripe along the middle would follow the curvature of the bezier curves.
My current approach simply breaks down the curve into a finite number of segments and then colors each pixel depending on its proximity, although this does not work because the scene will lag with even one of these objects if it has a resolution of 40+. Even if I could go to some arbitrarily large resolution, I am still unsure of how to "dynamically" color a pixel depending on it's relative height within the polygon. If there were a function to find the x or y coordinate relative to the curve's geometry (I assume normals play a role) then I would be pleased, because even if I did optimize my code as it is it is: it would not be seamless and I would have to have an arbitrarily and wastefully high resolution to guarantee a good look.
An algorithm that's reasonably efficient for 2> pixel accuracy for about 500,000 pixels worst-case scenario would also be equally helpful in place of a function that spits out an exact answer. I am more concerned about the effect being consistent than it being accurate as it is for visual purposes.
Polygon with unmodified x-axis shown:
Polygon with modified x-axis modified, f(x):
It is quite easy to brute force the solution by simply lerping between the curves A and B and filling them in until the entire polygon is filled, but a solution would require a function that would go backwards, translating each pixel coordinate into a point along an intermediary bezier curve as shown in f(x), ultimately letting me call f(x, y) to get the x, y within the polygon's space so that an image would fit exactly to the curvature of the bezier curves.
If the solution is significantly more simple with a quadratic bezier curve then I may go for that instead, as I am unsure if cubic is necessary.