Issues with OSL texture

Generic forum to discuss Octane Render, post ideas and suggest improvements.
Forum rules
Please add your OS and Hardware Configuration in your signature, it makes it easier for us to help you analyze problems. Example: Win 7 64 | Geforce GTX680 | i7 3770 | 16GB
Post Reply
User avatar
blackshore
Licensed Customer
Posts: 117
Joined: Wed Jul 31, 2013 6:22 pm

Do anyone know how to get this OSL texture working with Octane:
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
    );
}
User avatar
bepeg4d
Octane Guru
Posts: 10397
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy
Contact:

Hi,
sorry, not a Maya user, but your osl script is working correctly in both Standalone 2020.2.5, and 2021.1-RC3 here:
F51A7B65-C425-4354-9385-28A3548B0DE3.jpeg
8B832495-A38F-406B-A5DB-30A1AADF8134.jpeg
And also in Standalone 4.05:
CFE58D1B-E430-42B5-B02A-F6310447C88C.jpeg
Please post the issue in the related Maya discussion here:
viewtopic.php?f=109&t=74712

ciao
Beppe
User avatar
blackshore
Licensed Customer
Posts: 117
Joined: Wed Jul 31, 2013 6:22 pm

You are correct, not sure on why it works without any issues in standalone. I did not check that. Thanks, I will lay it to the maya forum
User avatar
jobigoud
OctaneRender Team
Posts: 250
Joined: Sat Aug 15, 2015 1:28 pm

The shader compiles in standalone but it's currently not quite possible to reproduce exactly the effect seen in the project's repository, because the Anisotropy field on the Material node is a single float not a texture. The shader output needs to be split into three grayscale textures for roughness, anisotropy and anisotropy rotation, and defines different values for each depending on whether we are on a scratch or not. We can use Channel picker nodes to split the result but we can't connect the anisotropy.

This is scheduled to be addressed in Octane 2022.
Post Reply

Return to “General Discussion”