Q:

Add a color input and output to OSL shader

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?

A:

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:

Hope this answers your question.

