Connections To Individual Array Elements?


dresserd@...
 

This is currently a very general question - is it likely that OSL might support connections to individual array elements in the future?

For Gaffer, we're currently looking at how we represent ramp UI's that control splines in shaders.  Currently, this looks something like this: https://github.com/GafferHQ/gaffer/blob/main/shaders/Pattern/FloatSpline.osl#L42 - a shader with a couple of array parameters.  We have a user request to support connecting an input shader to control the Y value of one control point on the spline.  The easiest way to implement this would be by creating a connection to one element of one of these arrays, but this is currently unsupported by OSL.

We're considering options like adding a kind of ridiculous looking adapter shader for handling array element connections ... or just changing how we handle spline shaders completely, and having a shader that only supports a spline with up to 10 inputs or something, and just having 10 separate inputs ( then we'd need to assemble an array based on the number of inputs actually being used, in order to pass into OSL's spline() function, and since the array can't be dynamically sized, this would have to be a pile of separate calls to spline() generated with a big ugly macro ).

How we approach this may be affected by whether we can envision a much cleaner future where OSL supports array element connections natively.  It looks like it wasn't too bad to add support for connections to components of a color in https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/pull/801, maybe this would be similar?

-Daniel Dresser


Stephen Friedman
 

FWIW, we have an existence proof that this is doable, we have customized RenderMan's version to support this, but we haven't upstreamed it yet because there were some niggling TODO's around defaults (looks like similar corner cases may be ignored in the component connection code) and we need to port the tests from our renderer to testshade.  
 
Hearing there is wider interest is encouraging and is a good prod to remind us to upstream, but just to temper expectations I think summer is probably the earliest we could find time to do it, but even then, I can make no promises.  However, if you're feeling adventurous again and want to attempt a PR yourself, I think it was a fairly straightforward thing to do.  

--Stephen

On Fri, Mar 3, 2023 at 4:20 PM <dresserd@...> wrote:
This is currently a very general question - is it likely that OSL might support connections to individual array elements in the future?

For Gaffer, we're currently looking at how we represent ramp UI's that control splines in shaders.  Currently, this looks something like this: https://github.com/GafferHQ/gaffer/blob/main/shaders/Pattern/FloatSpline.osl#L42 - a shader with a couple of array parameters.  We have a user request to support connecting an input shader to control the Y value of one control point on the spline.  The easiest way to implement this would be by creating a connection to one element of one of these arrays, but this is currently unsupported by OSL.

We're considering options like adding a kind of ridiculous looking adapter shader for handling array element connections ... or just changing how we handle spline shaders completely, and having a shader that only supports a spline with up to 10 inputs or something, and just having 10 separate inputs ( then we'd need to assemble an array based on the number of inputs actually being used, in order to pass into OSL's spline() function, and since the array can't be dynamically sized, this would have to be a pile of separate calls to spline() generated with a big ugly macro ).

How we approach this may be affected by whether we can envision a much cleaner future where OSL supports array element connections natively.  It looks like it wasn't too bad to add support for connections to components of a color in https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/pull/801, maybe this would be similar?

-Daniel Dresser