Posts

Showing posts from January, 2023

OSL - simple UV things and frac fract alternative

Here is a shoddy OSL shader that follow on from some of my GLSL experiments of yesteryear. I couldn't seem to find a frac or fract  function, but fmod-ing (it's like modulo) against 1 does the same thing. I don't put any input parameters in this shader. EDIT - just saw someone else's code that use x-floor(x) for fract, which could be faster..who knows! Variables Lame an Cat are assigned to u and v, I then multiply them by different values and fmod them so they repeat 3 and 4 times. It seems like u and v will be taken automatically, which is nice. After that I do a bit of if statement colour assignment.   shader use_uv(output color resultRGB = 0) {      float lame=u;      float cat=v;      cat=fmod(v*3,1);      lame=fmod(u*4,1);      resultRGB = color(lame, v, 1);      if(lame>0.5){      resultRGB+=color(0.3,0.4,0); } if(v<0.1){      resultRGB+=color(0,0,1); } if(lame<0.5){      resultRGB+=color(0,lame,0); } }

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