OSL lets begin - load a texture

Below is some code for a very simple OSLshader that loads in a texture and uses the UV coordinates existing on the object.

It begins with "shader image", which will create a shader named image. The variables that are listed and initialised in the ( parentheses ) are the arguments that it takes. It expects a string for the filename, float values called s and t, initialised to u & v and also a bunch of other stuff that I'm ignoring, for this post. Also, we have the output listed, which is of type color and named Cout, defaulting to black (or 0).

The actual doing part of the shader, the part between the { curly brackets, or braces } is very quick - it just takes all the variables mentioned and uses them to assign the texture image to the colour output.

Cout=texture(filename,s,t);


CODE AS FOLLOWS-

shader image

    [[ string help = "Texture lookup" ]]

(

    string filename = ""

        ,

    float s = u

        ,

    float t = v

        ,

    /*float  sblur = 0

        [[  string help = "Blur in the s direction",

            float min = 0, float max = 1 ]],

    float  tblur = 0

        [[  string help = "Blur in the s direction",

            float min = 0, float max = 1 ]],

    string swrap = "periodic"

        [[  string help = "Wrap mode for the s direction",

            string widget = "popup",

            string options = "default|black|clamp|periodic|mirror" ]],

    string twrap = "periodic"

        [[  string help = "Wrap mode for the t direction",

            string widget = "popup",

            string options = "default|black|clamp|periodic|mirror" ]],*/

    output color Cout = 0

        [[  string help = "Output color" ]]

  )

{

    Cout = texture (filename, s, t

, "sblur", sblur, "tblur", tblur,

                    "swrap", swrap, "twrap", twrap*/);

}


Comments

Popular posts from this blog

kodelife/glsl drawing a circle (sdf)

OSL - simple UV things and frac fract alternative

step and smoothstep functions, drawing a line