OSL

Outline shader


This is an osl shader that producers an outline that has the ability to be given a wavy style to the outline mimicking a drawn line. I used it in conjunction with a curvature based line to produce the top image. Areas where the geometry is thin such as the hands could use work as the fingers turn completely black.  

shader outline(

output color outColor = 0,

float width = .01,

float dis = 3,

float nscale = 0,

float namount = 0,

)
{
point op = point(0,0,0);

point op1 = point(0,0,0);

for(int i = -1; i < 2; i++){

if(outColor[0] > 0){break;}

point Cam = P - I;

point eye = normalize(I);

vector width2 = i * N * width + (noise("perlin",P * nscale) * namount);

point Cam2 = P + width2 - I;

point op = point(0,0,0);

point op2 = point(0,0,0);

int hit = trace(Cam, normalize(I));

if(hit ){

getmessage("trace", "P", op);

op = transform("world",op);

string name = "nogeo";

getmessage("trace","geom:name",name);

int hit2 = trace(Cam2, normalize(I));

outColor = 1;

if(hit2 ){

getmessage("trace", "P", op1);

op1 = transform("world",op1);

string name2;

getmessage("trace","geom:name",name2);

if(name != name2){ 
outColor = 1; 
break;
}

if(name == name2){ outColor = 0; }

if(distance(op,op1) > dis) { outColor = 1; }
}
}
i++;
}
}


Ray Marcher

This shader is a simple raymarcher that steps through the geometry of and raymarches a noise function as it goes. Im using it as a pattern on this spooky ghost guy.



shader raymarch(

output color outColor = 0,
output float dist = 0,
int steps = 16,
float stepLength = .1,
output color opp = 0,

)
{
vector bias = normalize(I) * .0001;

point op = point(0,0,0);

vector worldP = transform("world",P);

int hit = trace(P+bias, normalize(I));

if(hit ){

getmessage("trace", "P", op);

op = transform("world",op);

opp = op;

dist = abs(distance(op,worldP));

for(int i=0;i<steps;i++){

float stepSize = stepLength * i;

vector stepPoint = N * stepSize + worldP ;

if(abs(distance(worldP,stepPoint)) > dist){ continue ;}

outColor += noise("gabor",stepPoint);


}
}
outColor /= steps;
}

Thesis Work

This shader which I think I cleaned up and removed a lot of code but I can't seem to find that was used on my thesis. It creates a mask that blends between two textures by looking into the direction of a light vector to see if the shading point is occluded or not. It then uses a shadow texture if the image is occluded. 




shader npr06(

float diff_x = 0.0,
float diff_y = 0.0,
float diff_z = 0.0,
float spec_x = 0.0,
float spec_y = 0.0,
float spec_z = 0.0,
float specamount = 0.8,
float Distance = 100,
color mincolor = color(0,0,.2),
color maxcolor = color(1,1,0.5),
color speccolor = color(0,1,1),
output color resultRGBcos = color(0),
output float dist = 0,
output float blenddis = 0,
output float blendtheta = 0,
output float blendphi = 0,
output float blendeye = 0,
)
{
vector NN = vector("world", N[0],N[1],N[2]);

point PP = transform("world", P);

vector II = vector("world", I[0],I[1],I[2]);

vector A = vector(diff_x,diff_y,diff_z); // Locator for diffuse

vector B = vector(spec_x+diff_x+I[0],spec_y+diff_y+I[1],spec_z+diff_z+I[2]); // Locator for spec

vector L = normalize(A-PP);

vector L2 = normalize(B-PP);

vector L4 = normalize(II-PP);

float cosinetheta = dot(NN,L);

float cosinephi = dot(NN,L2);

float cosineeye = dot(NN,L4);

blendtheta = smoothstep(-1,1,cosinetheta);

vector noisevector = vector (0, 0, 0);

vector aovector =   0.001 * noise("perlin", P*10000.0) ;

float aoangle = radians(30);

    //cell gives float between 0 and 1.0

noisevector = (aoangle * ( 1 - 2.0 * noise("cell", aovector*10000.0)));

int hit = trace(P, normalize(A+noisevector));

float hitd = 0;

if(hit ){

if(cosinetheta > 0){

normalize(A-PP);

cosinetheta = dot(NN,L);

float blendtheta2 = smoothstep(-0.99,-0.5,cosinetheta)*.1;

point hitpoint = point(0);

getmessage("trace", "P", hitpoint);

    vector hitnormal = vector(0);

    getmessage("trace", "N", hitnormal);

    getmessage("trace", "hitdist", hitd);
   
    float cosinetheta2= dot(hitnormal,L);

            blendtheta = smoothstep(-1,1,cosinetheta);



    //blendtheta = smoothstep(0.3,0.7,cosinetheta2);

    blendtheta = (blendtheta*smoothstep(-0.99,-0.5,cosinetheta2) + blendtheta2) /2;

    if(cosinetheta < 0){

    blendtheta = smoothstep(-1,1,cosinetheta);
    //blendtheta = smoothstep(0.3,0.7,cosinetheta2);
    blendtheta = blendtheta*smoothstep(-0.99,-0.5,cosinetheta);
    }

   
    }


}

resultRGBcos = mix(mincolor,maxcolor, blendtheta);



// resultRGBcos = normalize(PP)+1/2;

/*
blendphi = smoothstep(-1,1,cosinephi);

float spec = specamount/1000;

if(blendphi < spec){

resultRGBcos = speccolor; // cosine theta

}
else{

resultRGBcos = mix(mincolor,maxcolor, blendtheta); // cosine theta

}
*/
}