Shaders
/* toon.sl - Toon shader for all renderman renderers. * (c) Copyright 1998, Colin Doncaster. * colind@name.net and colind@calibre-dd.com * Tested with BMRT 2.3.6 and PRMan 3.7 * * The RenderMan (R) Interface Procedures and RIB Protocol are: * Copyright 1988, 1989, Pixar. All rights reserved. * RenderMan (R) is a registered trademark of Pixar. * * Basically this shader measures the light values and uses Cs and supplied * parameters for building the colour. Quite simple actually! * * Usage: * threshold is used to define how the areas are broken up based on the * diffuse light. * Low and High are used to alter Cs to get the desired shade of Cs. * Variance is used to stop hard edges forming along the colour change, * this is basically used to control the smoothstep between the two colours. * Edges is the colour of the out and inner line colours; * EdgeVal is used to blend the base colour with the edges so it fits * better on the object. * * HaveFun!!!!! Colin. * * BTW The code probably isn't the greatest, if someone knows some speed * ups, let me know. */ surface toon (float Low = 0.2; float High = 1.1; float threshold = 0.1; float variance = 0.02; color Edges = 0; float EdgeVal = 0.9; ) { float Lum = 1; color LowC ; color HighC ; color Ct; color border; /* normal Nf = faceforward (normalize(N),I); */ point Nf; Nf = faceforward (normalize(N),I); Oi = Os; Lum = (comp(diffuse(Nf), 0) + comp(diffuse(Nf),1) + comp(diffuse(Nf), 2)) / 3; LowC = Cs * float Low; HighC = Cs * float High; Ci = mix(LowC, HighC, smoothstep(threshold - variance, threshold + variance, Lum)); border = mix(Ci, Edges, EdgeVal); Ci = mix(Ci, border, smoothstep(-2, -1, Nf.I)); }