/*
* VeinedMarble.osl by Shane Ambler
* from https://github.com/sambler/osl-shaders
*
* original script from -
* http://www.renderman.org/RMR/RMRShaders.html
*
* veinedmarble.sl -- surface shader for a nice veined marble.
*
* DESCRIPTION:
* Makes solid marble texture with strong veins. The "veincolor" parameter
* controls the color of the veins. The background color is given by the
* surface color (Cs).
*
* PARAMETERS:
* Ka, Kd, Ks, roughness, specularcolor - same as plastic
* veinfreq - controls fhe lowest frequency of the color veins
* veinlevels - how many "levels" of vein tendrills it has
* warpfreq - lowest frequency of the turbulent warping in the marble
* warping - controls how much turbulent warping there will be
* veincolor - the color of the veins
* sharpness - controls how sharp or fuzzy the veins are (higher = sharper)
*
*
* AUTHOR: Larry Gritz, the George Washington University
* email: gritz AT seas DOT gwu DOT edu
* This file is licensed under Apache 2.0 license
* HISTORY:
*
* last modified 29 Jun 1994 by Larry Gritz
* 2012-12-19 converted to blender osl shader by Shane Ambler
* 2020-4-27 converted to a Redshift Shader by Saul Espinosa, added coating Microfact GGX & Oren Nayer closure,
* new defaults, min/max values, label and page metadata.
* 2022-03-08 Added World, Object space controls for the Noise
*/
shader VeinedMarble
[[ string help = "Marble Closure Based Material",
string label = "Marble" ]]
(
// Input Paramaters
color diffuse_color = color(0.946,0.788,0.829)
[[
string label = "Diffuse Color",
string page = "Diffuse"
]],
float diffuse_weight = 0.8
[[
string label = "Diffuse Weight" ,
string page = "Diffuse",
float min = 0, float max = 1
]],
float diffuse_rough = 0.0
[[
string label = "Diffuse Roughness" ,
string page = "Diffuse",
float min = 0, float max = 1
]],
color SpecularColor = color(1.0)
[[
string page = "Specular",
string label = "Specular Color"
]],
float SpecularWeight = 1.0
[[
string label = "Specular Weight" ,
string page = "Specular",
float min = 0, float max = 1
]],
float Roughness = 0.4
[[
string label = "Roughness" ,
string page = "Specular",
float min = 0, float max = 1
]],
float IOR = 1.48
[[
string label = "IOR",
string page = "Specular",
float min = 0, float max = 25
]],
color coat_color = color(1.0)
[[
string label = "Coat Color",
string page = "Coat",
]],
float coat_weight = 1.0
[[
string label = "Coat Weight" ,
string page = "Coat",
float min = 0, float max = 1
]],
float coat_roughness = 0.005
[[
string label = "Coat Roughness" ,
string page = "Coat",
float min = 0, float max = 1
]],
float coat_IOR = 1.52
[[
string label = "Coat IOR" ,
string page = "Coat",
float min = 0, float max = 25
]],
color VeinColor = color(0.663, 0.319, 0.371)
[[
string label = "Vein Color",
string page = "Marble Vein"
]],
float VeinFreq = 1.0
[[
string label = "Vein Frequency" ,
string page = "Marble Vein",
float min = 0, float max = 10
]],
float VeinLevels = 2.0
[[
string label = "Vein Levels" ,
string page = "Marble Vein",
float min = 0, float max = 25
]],
float WarpFreq = 1.0
[[
string label = "Warp Frequency" ,
string page = "Marble Vein",
float min = 0, float max = 25
]],
float Warping = 0.5
[[
string label = "Vein Warping" ,
string page = "Marble Vein",
float min = 0, float max = 25
]],
float Sharpness = 8.0
[[
string label = "Vein Sharpness" ,
string page = "Marble Vein",
float min = 0, float max = 25
]],
int Space = 1
[[
string page = "Co-ordinates",
string widget = "mapper",
string options = "World:0|Object:1|Fixed:2",
int connectable = 0
]],
vector Origin = 0
[[
string page = "Co-ordinates"
]],
// Output Closure
output closure color outColor = diffuse(N) )
{
#define snoise(x) (2*noise(x)-1)
color Ct;
point Nf;
point PP, offset;
float i, turb, freq, j;
float turbsum;
if (Space == 0)
PP = P + Origin;
else if (Space == 1)
PP = transform("object", P) + Origin;
else
PP = Origin;
/* perturb the lookup */
freq = 1;
offset = 0;
for (i = 0; i < 6; i += 1) {
offset += 2 * Warping * ( noise (WarpFreq * freq * PP) - 0.5) / freq;
freq *= 2;
}
PP += offset;
/* Now calculate the veining function for the lookup area */
turbsum = 0; freq = 1;
PP *= VeinFreq;
for (i = 0; i < VeinLevels; i += 1) {
turb = abs (snoise (PP));
turb = pow (smoothstep (0.8, 1, 1 - turb), Sharpness) / freq;
turbsum += (1-turbsum) * turb;
freq *= 3;
PP *= 3;
}
color Out = mix (diffuse_color, VeinColor, turbsum);
Nf = normalize(N);
outColor = Out * diffuse_weight * oren_nayar(Nf, diffuse_rough);
outColor += (SpecularColor * SpecularWeight * microfacet("ggx",Nf,Roughness,IOR,0)) + (coat_color * coat_weight * microfacet("ggx",Nf,coat_roughness,coat_IOR,0));
}