Ported KMPuffyClouds from RSL. Had so trouble with the smoothstep function, so I had to add stand-in floats for it to work (weird imo, but I don’t know programming, so maybe that’s normal to you). Apart from that, it was very straight forward.
#include "stdosl.h"
#include "node_texture.h"
float noise_musgrave_fBm(point p, string basis, float H, float lacunarity, float octaves)
{
float rmd;
float value = 0.0;
float pwr = 1;
float pwHL = pow(lacunarity, -H);
int i;
for (i = 0; i < (int)octaves; i++) {
value += noise("perlin", p) * pwr;
pwr *= pwHL;
p *= lacunarity;
}
rmd = octaves - floor(octaves);
if (rmd != 0.0)
value += rmd * noise("perlin", p) * pwr;
return value;
}
shader node_musgrave_texture(
color Sky = color(.15, .15, .6),
color Clouds = 1,
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "fBM",
float Threshold = .25,
float Dimension = .5,
float Lacunarity = 2.0,
float Detail = 8.0,
float Scale = 5.0,
point Vector = P,
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
float threshold = clamp(Threshold, 0, 1);
float dimension = max(Dimension, 1e-5);
float octaves = clamp(Detail, 0.0, 16.0);
float lacunarity = max(Lacunarity, 1e-5);
string Basis = "Perlin";
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
p = p * Scale;
Fac = noise_musgrave_fBm(p, Basis, dimension, lacunarity, octaves);
float Condition = Fac;
float Mu = smoothstep(Threshold, 1, Condition);
Color = mix(Sky, Clouds, Mu);
}