Practicing OSL with Renderman for Maya

General / 21 July 2020

Circle:

Circle Used in Shading Network:

Circle OSL Code:

shader circle(
    float s_center = 0.5,
    float t_center = 0.5,
    float radius = 0.4,
    float s = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    float t = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
        
    color base_color = color(1,1,1),
    color pat_color = color(1,0,0),
    output color resultRGB = 0)
{
// i am shading a location in the middle of the "s" texture space
float ss = mod(s,1);
    float tt = mod(t,1);
    float a = ss - s_center;
    float b = tt - t_center;
    float d = sqrt((a*a) + (b*b));
    if (d <= radius)
        resultRGB = pat_color;
    else
        resultRGB = base_color;
}

Hollow Circle:

Hollow Circle Used in Shading Network:

Hollow Circle OSL Code:

shader circle_hollow(
    float s_center = 0.5,
    float t_center = 0.5,
    float smallRadius = 0.2,
    float bigRadius = 0.4,
    float s = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    float t = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
        
    color base_color = color(1,1,1),
    color pat_color = color(1,0,0),
    output color resultRGB = 0)
{
// i am shading a location in the middle of the "s" texture space
float ss = mod(s,1);
    float tt = mod(t,1);
    float a = ss - s_center;
    float b = tt - t_center;
    float d = sqrt((a*a) + (b*b));
    if (d <= smallRadius || d>= bigRadius)
        resultRGB = pat_color;
    else
        resultRGB = base_color;
}

Cross:

Cross Used in Shading Network:

Cross OSL Code:

shader UBar(
    float s = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    float t = 0 
        [[
        int lockgeom = 0,
        string widget = "null",
        ]],
    //float s_offset = 0.5,
    float s_offset = 0.1,
    float s_width = 0.223,
    float t_offset = 0.5,
    float t_width = 0.223,
    
    color base_color = color(1,1,1),
    color pat_color = color(1,0,0),
    output color resultRGB = 0)
{
// i am shading a location in the middle of the "s" texture space
float left = s_offset - s_width/2;
float right = s_offset + s_width/2;
float top = t_offset - t_width/2;
float bottom = t_offset + t_width/2;
if(s>= left && s<= right || t>= top && t<= bottom)
    resultRGB = base_color;
else
    resultRGB = pat_color;
}