https://github.com/cuckon/scratched/blo ... cratch.osl
I'm currently getting following error in maya+octane:
- Code: Select all
// Error: Octane: Failed to compile OSL texture node:
error: No shader function defined
//
System: win7 64bit
Maya: 2018
Octane:4.05
Maya plugin: 13.49
OSL shader:
- Code: Select all
// Micro Scratched Texture
//
// Author: John Su <[email protected]>
//
// An OSL shader that generates texture to make swirly micro scratch look by
// controlling the anistropy and roughness.
// The original idea is from Hang Li(悬挂鲤) and Ben Paschke. Here I implemented
// it using OSL and exposured some arts friendly parameters.
#define DIVISION 40
#define DEBUG(_) Cf=_; return;
float line(point p, float direction, float width){
float theta = direction * M_PI;
float k = tan(theta);
float distance = abs(k * p[0] - p[1])/sqrt(k * k + 1);
return 1 - step(width*0.5, distance);
}
shader scratch(
float density=0.1,
float roughness_min=0.0,
float roughness_max=0.01,
float roughness_default = 0.1,
float anisotropic_min = 0.1,
float anisotropic_max = 0.2,
float anisotropic_default = 0,
float width=0.001,
float offset=0.0,
output color Cf = 0
){
float delta = 1.0/(DIVISION - 1);
float max_radius = sqrt(density);
int max_search_cell = (int)ceil(max_radius/delta);
point index = point(round(u/delta), round(v/delta), 0.0);
point shading_p = point(u, v , 0.0);
point current_index;
point current_origin_p;
float scratch = 0, direction=0;
float roughness = roughness_default, anisotropic = anisotropic_default;
for (int x = -max_search_cell; x <= max_search_cell; ++x){
for (int y = -max_search_cell; y <= max_search_cell; ++y){
current_index = index + point(x, y, 0);
current_origin_p = (current_index + (hashnoise(current_index) - 0.5)) * delta;
direction = hashnoise(current_index + vector(123, 456, 0));
scratch = line(
current_origin_p - shading_p,
direction,
width * hashnoise(current_index)
);
if (scratch)
{
roughness = roughness_default + mix(
roughness_min,
roughness_max,
hashnoise(current_index + vector(123, 456, 1))
);
anisotropic = anisotropic_default + mix(
anisotropic_min,
anisotropic_max,
hashnoise(current_index + vector(123, 456, 2))
);
break;
}
}
if (scratch)
break;
}
Cf = color(
roughness,
(direction * 0.5 + offset) * (scratch > 1e-4),
anisotropic
);
}