I have been porting the watermelon shader from RSL Guide. There is one line of code that crashes blender, I’ve filed a bug report at https://projects.blender.org/tracker/index.php?func=detail&aid=33498&group_id=9&atid=498. It works if you comment it out. I also found a discrepancy between viewport and rendered when I used the dented shader that I ported. see below…

**WATERMELON.OSL**

```
#include "stdosl.h"
/* Define metrics for estimating filter widths, if none has already
* been defined. This is crucial for antialiasing.
*/
#ifndef MINFILTWIDTH
# define MINFILTWIDTH 1.0e-6
#endif
float smoothpulse (float e0, float e1, float e2, float e3, float x)
{return smoothstep(e0,e1,x) - smoothstep(e2,e3,x);}
/* Signed noise -- the original Perlin kind with range (-1,1) We prefer
* signed noise to regular noise mostly because its average is zero.
* We define three simple macros:snoisexy(x,y) - Perlin noise on a 2-D domain.*/
float snoisexy(float x, float y)
{return (2 * noise("perlin",x,y) - 1);}
vector vsnoise(point p)
{return 2 * (noise(p)) - 1;}
/* The filterwidthp macro is similar to filterwidth, but is for
* point data. */
float filterwidthp(point p)
{return max (sqrt(area(p)), MINFILTWIDTH);}
float filteredabs (float x, float dx){
float integral (float t) {
return sign(t) * 0.5 * t*t;
}
float x0 = x - 0.5*dx;
float x1 = x0 + dx;
return (integral(x1) - integral(x0)) / dx;}
/* If we know the filter size, we can crudely antialias snoise by fading
* to its average value at approximately the Nyquist limit.
*/
float filteredsnoise(point p, float width)
{return snoise(p) * (1-smoothstep (0.2,0.75,width));}
vector filteredvsnoise(point p,float width)
{return vsnoise(p) * (1-smoothstep (0.2,0.75,width));}
/* Antialiased turbulence. Watch out -- the abs() call introduces infinite
* frequency content, which makes our antialiasing efforts much trickier!*/
float turbulence (
point p,
float filtwidth,
float octaves,
float lacunarity,
float gain)
{
float amp = 1;
point pp = p;
float sum = 0, fw = filtwidth;
float i;
for (i = 0; i < octaves; i += 1) {
float n = filteredsnoise (pp, fw);
sum += amp * filteredabs (n, fw);
amp *= gain; pp *= lacunarity; fw *= lacunarity;}
return sum;}
/* A vector-valued antialiased fBm. */
vector vfBm (point p, float filtwidth,
float octaves, float lacunarity, float gain)
{
float amp = 1;
point pp = p;
vector sum = 0;
float fw = filtwidth;
float i;
for (i = 0; i < octaves; i += 1) {
sum += amp * filteredvsnoise (pp, fw);
amp *= gain; pp *= lacunarity; fw *= lacunarity;
}
return sum;
}
shader watermelon(
color baseColor = color(0.56,0.6,0.41),
float baseFreq = 4,
float label = 0.5,
color stripeColor = color(0.35,0.45,0.31),
float stripeFreq = 25,
float stripeNoiAmp = 0.015,
float stripeNoiLevels = 12,
float stripeNoiFreq = 5,
float detailFreq = 20,
point st = P,
output color Final = (0)
)
{
/* Initialize shader variables */
color sc,lc;
float lo;
float s = st[0];
float t = st[1];
/*Layer 1 - Base color */
/*Transform P from "current" to "shader" */
point Pshad = transform("shader",P) * baseFreq + label;
/*calculate a very simple noise to drive the spline function*/
float smallnoise = noise(2 * Pshad);
/*create variations of the baseColor to pass it to the spline function */
color basevariation[11] = {
baseColor - 0.0006265412909334433,
baseColor - 0.0006265412909334433,
baseColor - 6.504321932827129e-05,
baseColor,
baseColor + 0.0001829220207709304,
baseColor + 0.0001829220207709304,
baseColor - 6.504321932827129e-05,
baseColor,
baseColor + 0.0001829220207709304,
baseColor + color(0.0001829220207709304,0.0001829220207709304,0.0001829220207709304),
baseColor + color(0.0001829220207709304,0.0001829220207709304,0.0001829220207709304)
};
/* use the spline function to color the base of the watermelon */
sc = spline("linear", smallnoise,basevariation);
/* Layer 2 - Dark green stripes
* compute base noise based on the texture coordinates.
* This is a turbulence noise that uses gradual clamping.
* it was taken from Steve May;s RmanNotes */
float width = filterwidthp(Pshad);
float cutoff = clamp(0.5 / width, 0, stripeNoiLevels); //4 = maxfreq
float f;
float turb = 0;
for (f=1; f < 0.5 * cutoff; f *= 2)
turb += abs(snoise(Pshad * stripeNoiFreq * f)) / f;
float fade = clamp(2 * (cutoff -f) / cutoff, 0,1);
turb += fade * abs(snoise(Pshad * f))/f;
/* perturb s based on turb, add the label to control randomness */
float ss = s + snoise(turb + 912) * stripeNoiAmp + label;
lc = stripeColor;
/*use a noise to create broad long noisy stripes */
float stripeOp = abs(snoisexy(stripeFreq*ss, 0.6 *t));
float lo1 = smoothpulse(0.1,0.3,0.74,0.94,stripeOp);
lo = smoothpulse(0.5,0.3,0.74,0.94,stripeOp);
sc = mix(sc,lc,lo);
/* Layer 3 - Veins / Detail within th stripes */
Pshad = label + detailFreq * transform("shader",P);
float Pshadw = filterwidthp(Pshad);
/* First calculate the underlying color of the substrate
* Use turbulence - use frequncy clamping */
turb = 0.5 * turbulence (Pshad, Pshadw, 5, 2, 0.5);
//color stripeDetail = spline("linear",turb,basevariation);
//sc = mix (sc,stripeDetail,lo1 * smoothstep(0.1,0.3,turb));
/* Layer 3 */
/*perturb the point lookup */
Pshad += vector(35.2, -21.9, 6.25) + vfBm(Pshad,Pshadw, 6, 2, 0.5);
/* Now calculate the veining function for the lookup area */
float turbsum, freq, i;
turbsum = 0;
freq = 1;
Pshad *= 0.75; // scale down the scale of Pshad
for(i = 0; i < 4; i += 1)
{ turb = abs(filteredsnoise(Pshad * freq,Pshadw * freq));
turb = pow (smoothstep (0.55,0.98,1 - turb), 30)/ freq;
turbsum += (1-turbsum) * turb;
freq *= 2;}
turbsum *= smoothstep (-0.1,0.05, snoise((Pshad+vector(-4.4,8.34,27.1))));
sc = mix (sc,stripeColor * 0.9, turbsum*lo1);
Final = sc;
}
```

**DENTED.OSL**

```
/* Copyrighted Pixar 1989 */
/* From the RenderMan Companion p.352 */
/* Listing 16.16 Displacement shader to dent a surface */
/*
* dented(): Create a worn surface.
*/
normal PolygonDisplaceFix(normal N, float amount){
point P;
normal Ng;
normal Ndiff;
Ndiff = normalize(N) - normalize(Ng);
P += amount * normalize(N);
return normalize(calculatenormal(P)) + Ndiff;}
displacement
dented (
float Km = 1.0,
output float mag = 0)
{
float size = 1.0;
float magnitude = 0.0;
float i;
point P2;
P2 = transform ("object", P);
for (i = 0; i < 6.0; i += 1.0)
/* Calculate a simple fractal 1/f noise function */
{magnitude += abs (.5 - noise (P2 * size)) / size;
size *= 2.0;}
mag = (magnitude * magnitude * magnitude)* Km;
P2 = P - normalize (N) * mag;
N = calculatenormal(P2);
}
```

ViewPort vs Rendered

Viewport

Rendered