Hello all
Presently Arnold/MtoA's OSL support is limited to one output of a fundamental OSL data type.
Are there plans to support multiple outputs, and/or to support compound data types? Example, if one wants to write a custom texture node for whatever reason, one would need a color4 composited of RGB and A which can be done on the same lookup. Having multiple outputs of a Voronoi/Worley noise shader to output besides the features distances, the nearest cell centers and their IDs in the same shader - it would be far too expensive to have separate nodes for this, each with one output, just to name a couple of examples.
MtoA oslc compiles a test shader fine, but the node then fails to load with an "parameters of type POINTER are not supported".
Is this something being contemplated on the near or medium term, or is it better to abandon hope and find alternatives?
Thanks in advance
I just wrote a test, this has 3 outputs generating 3 different channels.
I use 3dsmax, and I am just using very basic funcionality, I would be very surprized if this was not possible to load in maya.
shader MultiOut (
float a = 0,
float b = 0,
vector c = vector(.0),
output float aa = 0,
output float bb = 0,
output vector cc = 0,
)
{
aa = a*0.1;
bb = aa+2.0;
cc = vector ( aa, bb, 0 );
}
Thanks for taking your time to have a look at this
This seems to be Maya limitation, but from the documentation provided it seems there are two levels of OSL support in Maya.
In
https://docs.arnoldrenderer.com/display/A5AFMUG/OSL+Shaders
you only have one output, no array or matrices support, and no custom data types via structures.
In
https://docs.arnoldrenderer.com/display/A5ARP/OSL+Shaders
it seems you still have one output, but arrays, matrices are supported, as well as custom data types.
Taking your example shader results in a node with only the last declared output active, and exposing all attributes shows nothing else:
If you try to use structures to make your own data types as in the example below, then the error mentioned earlier occurs.
struct color4
{
color rgb;
float a;
};
color4 __operator__add__(color4 a, color4 b)
{
return color4(a.rgb + b.rgb, a.a + b.a);
}
shader col4
(
color4 A = {color(0), 0.0}
[[
string label = "A"
]],
color4 B = {color(0), 0.0}
[[
string label = "B"
]],
output color4 C = {color(0), 1.0}
[[
string label = "C"
]]
)
{
C = A + B;
}
Out of curiosity, does the above shader snippet work for you in Max? You might need to use the attached tarball since the codebox has limits and the double underscore in the addition overloaded operator changed the text into italic.
If you need the MTD file, here goes
[node col4]
maya.name STRING "col4"
maya.id INT 0x00130387
maya.classification STRING "utility"
maya.output_name STRING "C"
maya.output_short_name STRING "oc"
- The struct parses fine.
- "color4 __operator_add_" this is not generic OSL. You would have to make the function generic and not call C library I belive.
So just refference the color4.
struct color4
{
color rgb;
float a;
};
color4 test ( stuff ){
return things;
}
So you are trying to exit on a rgb+a, I don't think we can exit on a vec4 directly.
You would have to exit on a vector or color and add the A as a second out, The OSL implementation, atleast in max, and everything I have seen from blender etc, exit on a vec3/color and pipe the alpha, 4th channel seperatly.
The Bitmap Lookup node Zap wrote for max, also exit RGB to 1 socket, and then 4 seperate float exits, R,G,B and A.
Internally, you can do struct handling with 4 entries but when you exit you need to format it.
Atleast that's what I gather.
The MultiOut you put in the package works perfect btw. I get 3 outs. shader compiles.
The meta data limits also works perfect.
Only in GLSL which is simular I see output to fragColor in 4 channels which typically looks like:
FragColor = vec4(vec3(col,col,col),1.0);
Or something down those lines, but in OSL we have to get rid of the alpha and send it on a seperate channel so it would look more down the lines of:
#define vec3 vector
Out = vec3(col);
OutA = 1.0;
The overloaded operators are valid OSL (double underscores are some markdown here), but i could not use the codebox earlier since it seems to clamp the code to a certain size. Let's see if it works with a shorter snippet for clarification
color4 __operator__add__(color4 a, color4 b) { return color4(a.rgb + b.rgb, a.a + b.a); }
I'm not sure if the operators are standard OSL or implementations of the operations with structures as listed in the OSL documentation section 5.9 on structure data types.
https://github.com/imageworks/OpenShadingLanguage/blob/master/src/doc/osl-languagespec.pdf
As part of MaterialX, you can find example implementations here:
https://github.com/imageworks/OpenShadingLanguage/blob/master/src/shaders/color4.h
It seems we have to wait a bit further to have the level of OSL support in Maya that Arnold already provides to Max users then.
Once again thanks for taking your time to look at this.
OK IC!
The materialX has passed under my radar for now, but would like to give it a stab 4sure.
So with those overloads, in max I can show you how to integrate, normally we only have - vector -
We can however:
#include <vector4.h> #define vec4 vector4
So now every time vec4 is called, all those add, minus, multiply, etc etc sub functions are called directly so we can work with the vec4 struct.
like:
#include <vector4.h>
#define vec4 vector4
vec4 fract ( vec4 x ) {
return x - floor(x);
}
I can confirm that the forums code box is toasted!
The above code was imposible to get to render correctly, the first block worked however.
So we dont actually adress the internal add, we just load the h rules from start and it glides through.
I guess what you look for is something simular in Maya.
I will try your code later, I just tried it and it crashed my application, will check again.
I guess if a particular .h file is missing ( dev hanvent made it for the app yet ) , you can try generate it yourself. I havent tried if that worked.
Hey there, is there any hope for multiple outputs in OSL for maya?
Not having more than one output really limits its usage, or at least make it a real pain and inefficient.
The main reason behind OSL is the hability to use them in ANY software and ANY renderer, does it?
So, why we don't have outputs inside MAYA?
Take the simple tiles OSL for example..., inside max, you get Index output, but NOT in MAYA.
I suppose it is a MAYA bug, but after years, no updates seems to fix it, and Autodesk doesn't seem to care.
So much care for MAX, no love for MAYA in this case 😞
I'd love to know your opinion @madsd