Small Request: Update OSL code for Flakes texture

Forums: Small Request: Update OSL code for Flakes texture
Sub forum for feature requests etc

Moderator: aoktar

Small Request: Update OSL code for Flakes texture

Postby leehenshall » Tue Jun 23, 2020 5:28 pm

leehenshall Tue Jun 23, 2020 5:28 pm
When the osl flakes were originally compiled for Octane OSL a user called "funk" edited the original code from Chaos Group to include a projection pin so that you can triplanar the flakes texture over complex/non UV'd objects.

Here is the original post:

viewtopic.php?f=33&t=63905&hilit=osl+flakes&start=10

Here is the code from that post:

Code: Select all
shader
flakes
(
    float flake_scale = 10.0 [[ string description = "Smaller values zoom into the flake map, larger values zoom out" ]],
    float flake_size = 0.5 [[ string description = "Relative size of the flakes" ]],
    float flake_size_variance = 0.0 [[ string description = "0.0 makes all flakes the same size, 1.0 assigns random size between 0 and the given flake size" ]],
    float flake_normal_orientation = 0.0 [[ string description = "Blend between the flake normals (0.0) and the surface normal (1.0)" ]],
    point proj = point(u, v, 0) [[string label = "Projection"]],
    output color result = 1.0
)
{
    float safe_flake_size_variance = clamp(flake_size_variance, 0.1, 1.0);
    vector cellCenters[9] = {
        vector( 0.5,  0.5,  0.0),
        vector( 1.5,  0.5,  0.0),
        vector( 1.5,  1.5,  0.0),
        vector( 0.5,  1.5,  0.0),
        vector(-0.5,  1.5,  0.0),
        vector(-0.5,  0.5,  0.0),
        vector(-0.5, -0.5,  0.0),
        vector( 0.5, -0.5,  0.0),
        vector( 1.5, -0.5,  0.0)
    };
     
    //point position = vector(u, v, 0.0);
    point position = flake_scale * proj;

    point base = floor(position);
     
    point nearestCell = point(0.0, 0.0, 1.0);
    int nearestCellIndex = -1;
    for(int cellIndex = 0; cellIndex < 9; ++cellIndex)   {
        point cellCenter = base + cellCenters[cellIndex];
         
        vector centerOffset = cellnoise(cellCenter) * 2.0 - 1.0;
        centerOffset[2] *= safe_flake_size_variance;
        centerOffset = normalize(centerOffset);
         
        cellCenter += 0.5 * centerOffset;
        float cellDistance = distance(position, cellCenter);
        if(cellDistance < flake_size && cellCenter[2] < nearestCell[2]) {
            nearestCell = cellCenter;
            nearestCellIndex = cellIndex;
        }
    }
     
    result = color(0.5, 0.5, 1.0);
     
    if (nearestCellIndex != -1) {
        vector randomNormal = cellnoise(base + cellCenters[nearestCellIndex] + vector(0.0, 0.0, 1.5));
        randomNormal = 2.0 * randomNormal - 1.0;
        randomNormal = faceforward(randomNormal, I, randomNormal);
        randomNormal = normalize(mix(randomNormal, vector(0.0, 0.0, 1.0), flake_normal_orientation));
         
        result = color(0.5*randomNormal[0]+0.5, 0.5*randomNormal[1]+0.5, randomNormal[2]);
    }
}


I really like that you have provided easy access to community OSL scripts in your node editor. It is really handy.

Please can you update the quick access pre-set in the Octane Node Editor to this more advanced version of OSL flakes?

OSL-Flakes.jpg
Win 10 64 | 2 X 2080Ti | Threadripper 2970WX | 128GB + Win 10 64 | 4 X Titan X | Threadripper 1950x | 128GB
leehenshall
Licensed Customer
Licensed Customer
 
Posts: 142
Joined: Sun Oct 25, 2015 5:44 pm
Location: England

Re: Small Request: Update OSL code for Flakes texture

Postby aoktar » Tue Jun 23, 2020 5:41 pm

aoktar Tue Jun 23, 2020 5:41 pm
You can organize it by yourself. Isn't a good idea to do it?
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 13516
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: Small Request: Update OSL code for Flakes texture

Postby leehenshall » Tue Jun 23, 2020 6:26 pm

leehenshall Tue Jun 23, 2020 6:26 pm
I've just been pasting the updated OSL shader code into the OSL node to overwrite the old osl flakes code that comes with the plugin.

I didn't know it was an option to edit these node editor pre-sets. How do I do that?

Regardless, wouldn't you rather include the best version of this OSL script? It's objectively better, it doesn't change any of the core features other than append the ability for it talk to octane projections.
Win 10 64 | 2 X 2080Ti | Threadripper 2970WX | 128GB + Win 10 64 | 4 X Titan X | Threadripper 1950x | 128GB
leehenshall
Licensed Customer
Licensed Customer
 
Posts: 142
Joined: Sun Oct 25, 2015 5:44 pm
Location: England

Return to User requests


Who is online

Users browsing this forum: No registered users and 1 guest

Thu Aug 13, 2020 12:21 am [ UTC ]