Drawing cubic splines in OSL

It took me ages to find a workable (= fast enough) solution to draw cubic splines in OSL. The quadratic version is simple enough because the shortest distance to a quadratic curve is a cubic equation which can be solved analytically, but the shortest distance to a cubic spline is a quintic equation for which there are only numerical methods.

Fortunately I finally found one, and although it toook quite some work to translate the original C-version to OSL (because OSL doesn’'t know recursion) I am quite pleased with the resullt.

Details in this article.

Love,

– Michel.


(img is drawn as two cubic splines)

1 Like

Tweaked the code a bit & made it 2D instead of full 3D because i think the major use case is w. uv coords. Code still contains 3D lines, just undef CALC2D macro in source. The result is a 10% speed increase (and a lot messier code :frowning:

Judging from the number of replies on this thread (zero), cubic splines in OSL is not that interesting to most people so I’ll stop tweaking it, but 10% may be worth it so I have updated the code on GitHub anyway :slight_smile:

Happy Holidays,

– Michel.

1 Like

wow nice work, you open my eyes of what OSL is capable . Makes me wonder how feasible is to take an SVG file and draw it with Cycles and OSL.

basically anything is possible in OSL and it certainly can read xml and thus SVG (via its dictionary functions) but from a practical point of view it would be unfeasible I think because it would be way to slow (the xml file would be cached but for each shader sample all primitives in the SVG would need to be examined).

well then maybe brake the xml (SVG) to several xmls per object and assign each xml to its corresponding object and shader.

I have no idea what I would use it for, but I appreciate that you made it…not least because I am finding this one interesting to study

That’s great, I have seen some users in GLSL generate solid geometry out of thin air (e.g. a sphere has a vector 3 attribute for position and a float attribute for size). In OpenGL this is a great way to optimize graphics (e.g. you won’t have to create vertex buffer objects).

I guess that this might be handy for doing something similar as well, generating various lines (hair?) based on raw data, who knows? :slight_smile: