I'm trying to wrap my head around making shaders but I have no real coding experience. I've tried looking for a solution to my problem but I haven't found anything. Maybe I'm not phrasing it right? The problem is this: I have a script that looks like this, which takes a texture with values in a certain range and then changes the range of the values while keeping their relative positions.

shader Exp_Shader(
float tex = 0,
float OldMax = 1,
float OldMin = 0,
float NewMax = 1,
float NewMin = 0,
output float Result = 0,
)
{
Result = (((tex - OldMin)*(NewMax-NewMin))/(OldMax-OldMin)) + NewMin;
}


The problem is, that this works on greyscale textures but not on color. How can I add a color input and output to make this work?

In OSL, you can use color as type of parameter. For example see here your script. I changed the tex parameter and the Result parameter

shader Exp_Shader(
color tex = 0,
float OldMax = 1,
float OldMin = 0,
float NewMax = 1,
float NewMin = 0,
output color Result = 0,
)
{
Result = (((tex - OldMin)*(NewMax-NewMin))/(OldMax-OldMin)) + NewMin;
}


After doing this and pressing the refresh button the Script node will look like this:

• Thanks for this! My problem was that I was trying to write it like : color tex = rgb(0,0,0) I still need to learn a lot. – Cos Dim Jan 12 '18 at 21:40

@J.Bakker's answer is perfectly good .. but just for completeness..

There are a number of ways of constructing a color in OSL, including these examples given in the Language Specification:

color (0, 0, 0) // black
color ("rgb", .75, .5, .5) // pinkish
color ("hsv", .2, .5, .63) // specify in "hsv" space
color (0.5) // same as color (0.5, 0.5, 0.5)


(see the rest of the color section for the complete list)