Thank for responding Kiril! I really appreciate it.
What I’m using:
Maya 2018, cut 201706261615-f9658c4cfc
VRay Next for Maya, hotfix 2, v4.04.03.00010
The shader you provided doesn’t work for me (which would seem user error, right?). It compiled, I went into maya, added a fresh VRayMtl and a VRayTexOSL, referenced my oso, and connected the output color to the diffuse color on the VRayMtl. I see the parameters I should see on the VRayTexOSL node.
On the VRayTexOSL node, without adding the filename widget hint, ‘input_texture’ is just a color that I can wire up to a ‘file’ node. But I can’t get the VRayTexOSL to return anything other than black, with or without the widget hint, even if I hardcode ‘Col’ to something like color(1,1,1). That’s really weird. But in my case I’m trying to do all of this in one node a VRayMatlOSL, so the VRayTexOSL might be a mystery for another day?
I’m still seeing the maya crash issue when I access the color component of a ‘file’ node connection. Here is an example shader that shows what I’m doing.
#include "include/stdosl.h"
#include "include/oslutil.h"
color RGBtoHSV(color rgb) {
float r = rgb[0];
float g = rgb[1];
float b = rgb[2];
float mincomp = min (r, min (g, b));
float maxcomp = max (r, max (g, b));
float delta = maxcomp - mincomp; // chroma
float h, s, v;
// Calculate value
v = maxcomp;
s = 0;
h = 0;
// Calculate saturation
if ((delta > 0) && (maxcomp > 0)) {
s = delta / maxcomp;
} else {
s = 0;
}
// Calculate hue
if ((s <= 0) || (delta <= 0)) {
h = 0;
} else {
if (r >= maxcomp) h = (g-b) / delta;
else if (g >= maxcomp) h = 2 + (b-r) / delta;
else h = 4 + (r-g) / delta;
// Normalize to 0-1
h /= 6;
// Wrap it around
if (h < 0)
h += 1;
}
return color (h, s, v);
}
color HSVtoRGB (color c) {
float h = c[0], s = c[1], v = c[2];
color r;
if (s < 0.0001) {
r = v;
} else {
h = 6 * (h - floor(h)); // expand to [0..6)
int hi = (int)h;
float f = h - hi;
float p = v * (1-s);
float q = v * (1-s*f);
float t = v * (1-s*(1-f));
if (hi == 0) r = color (v, t, p);
else if (hi == 1) r = color (q, v, p);
else if (hi == 2) r = color (p, v, t);
else if (hi == 3) r = color (p, q, v);
else if (hi == 4) r = color (t, p, v);
else r = color (v, p, q);
}
return r;
}
surface TestSurface
(
color inputColor = color(1.0, 1.0, 1.0)
[[ string help = "Input color, a starting place",
string page = "Color"]],
// Without this widget hint, I don't get a string input, I get a color that I can connect to a maya "file" node.
// I can set the color to something and it flows through. If I connect a file node it flows through.
// If I add this widget hint (filename) I get black from the texture call, which in turn disables the
// diffuse closure below if I multiply it with the closure.
string colorFilename = ""
[[ string help = "Filename for the color pass (RGBA), it layers over Base Color and Base Alpha",
string page = "Maps",
string widget = "filename"]],
float hueOffset = 0
[[ string help = "Offset on the current global hue value",
string page = "Color",
string label = "Hue Offset"]],
float satMult = 1
[[ string help = "Multiplier on the current global saturation value",
string page = "Color",
string label = "Sat Mult"]],
float valMult = 1
[[ string help = "Multiplier on the current global value value",
string page = "Color",
string label = "Val Mult"]]
)
{
// If I don't access the compenents of the color, maya doesn't crash, but the result
// of this texture call is black.
color fileColor = texture(colorFilename,u,v,"missingcolor",color(1,1,1));
color accumColor = fileColor;
// Without this line, ie I let 'fileColor' flow through, maya crashes
// And it crashes whenever I try to access the components of a color
accumColor = inputColor;
accumColor = RGBtoHSV(accumColor);
accumColor[0] += hueOffset;
accumColor[1] = clamp(accumColor[1]*satMult,0,1);
accumColor[2] = clamp(accumColor[2]*valMult,0,1);
accumColor = HSVtoRGB(accumColor);
// If I let fileColor be assigned to accumColor, it's black, though I've provided a string.
// If accumColor is black the diffuse closure is ignored and my surface becomes transparent
closure color accumClosure = diffuse(N) * accumColor;
Ci = accumClosure;
}
Jake