Overview of OSL Shaders in Octane

A forum where development builds are posted for testing by the community.
Forum rules
NOTE: The software in this forum is not %100 reliable, they are development builds and are meant for testing by experienced octane users. If you are a new octane user, we recommend to use the current stable release from the 'Commercial Product News & Releases' forum.
Post Reply
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

J.C wrote:Thanks calus. This compiles now but it does not work as advertised by Chaos group. The flakes does not scale. I just can see some two big triangles.
hum, it works as expected for me, but take care as there is no input for projection , Octane use UVprojection by default so your geometry need some UV, or if you want to work without UV triplanar proj should work.
Attachments
octane_2017-11-07_23-42-38.png
Last edited by calus on Tue Nov 07, 2017 10:45 pm, edited 1 time in total.
Pascal ANDRE
User avatar
aoktar
Octane Plugin Developer
Posts: 16066
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

J.C wrote:Thanks calus. This compiles now but it does not work as advertised by Chaos group. The flakes does not scale. I just can see some two big triangles.
You should slightly modify parameters and code. See image.
Attachments
a1.jpg
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
J.C
Licensed Customer
Posts: 1857
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Thanks guys for the tip, it works! :)
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
User avatar
aoktar
Octane Plugin Developer
Posts: 16066
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

Doing some tests with codes from internet while improving the stuff.

simple deformation with osl_projection.

Code: Select all

shader OslProjection
(
     color dist=0,
    output point uvw = 0
    )
{
    uvw = 2*point(u, v, 0)+dist;
}
Brick

Code: Select all

shader brick(
        float thick=0.02,
        float rat=5.6,
        float  rep=6,
        color MainColor = color(1.0,0.0,0.6),
        color EdgeColor = color(1.0,0.0,0.0),
        output color c = 0 )
{
    color col=color(1,0.23,0.13);
    float x=rep*u;
    float y=rat*rep*v;
    
    if(mod(y, 2.0) < 1.0) x=x+0.5;
    
    x *= (1+0.7*noise("cell", y));
    
    float nx=x-floor(x);
    float ny=y-floor(y);
    
    if(nx>1-thick || ny<rat*thick) { 
        col=color(0.9); 
    }
    else {
        float brg = 0.5*noise("cell", point(floor(x),floor(y),0))+0.3;    
        col = brg*col;
    }
    c = col;
}
Crazy parquet script

Code: Select all

shader DWParquetTile (

        float DiffuseAmt = 0.75 ,
        float SpecularAmt = 0.15,
        float Roughness = 0.025,
        color SpecularColor = color(1.0),
        float RingScale = 25.0,
        float GrainScale = 55.0,
        float Grainy = 1.0,
        float Wavy = 0.08,
        float TextureScale = 5.0,
        color LightWood = color (0.57, 0.292, 0.125),
        color DarkWood  = color (0.275, 0.15, 0.06),
        color GrooveColor  = color (0.05, 0.04, 0.015),
        int PlanksPerTile = 1,
        float PlankWidth = 0.2,
        float PlankVary = 0.6,
        float GrooveWidth = 0.1,
        output color BSDF = .5 )
{
#define snoise(x) (2 * noise((x)) - 1)
#define boxstep(a,b,x) (clamp(((x)-(a))/((b)-(a)),0,1))
#define MINFILTERWIDTH 1.0e-7

        vector Vector = P;
    float su = Vector[0];
    float tv = Vector[1];
    float r, r2;
    point Nf;
    float whichrow, whichplank;
    float swidth, twidth, fwidth, ss, tt, w, h, fade, ttt;
    color Ct, woodcolor;
    float groovy;
    float PGWIDTH, PGHEIGHT, GWF, GHF;
    float tilewidth, whichtile, tmp, planklength;

    PGWIDTH = PlankWidth+GrooveWidth;
    planklength = PGWIDTH * PlanksPerTile - GrooveWidth;
    PGHEIGHT = planklength+GrooveWidth;
    GWF = GrooveWidth*0.05/PGWIDTH;
    GHF = GrooveWidth*0.05/PGHEIGHT;

    /* Determine how wide in s-t space one pixel projects to */
    swidth = (max (abs(Dx(su)*su) + abs(Dy(su)*tv), MINFILTERWIDTH) / PGWIDTH) * TextureScale;
    twidth = (max (abs(Dx(tv)*su) + abs(Dy(tv)*tv), MINFILTERWIDTH) / PGHEIGHT) * TextureScale;
    fwidth = max(swidth,twidth);

    ss = (TextureScale * su) / PGWIDTH;
    whichrow = floor (ss);
    tt = (TextureScale * tv) / PGHEIGHT;
    whichplank = floor(tt);
    if (mod (whichrow/PlanksPerTile + whichplank, 2) >= 1) {
        ss = TextureScale * tv / PGWIDTH;
        whichrow = floor (ss);
        tt = TextureScale * su / PGHEIGHT;
        whichplank = floor(tt);
        tmp = swidth;  swidth = twidth;  twidth = tmp;
    } 
    ss -= whichrow;
    tt -= whichplank;
    whichplank += 20*(whichrow+10);

    /*
     * Figure out where the grooves are.  The value groovy is 0 where there
     * are grooves, 1 where the wood grain is visible.  Do some simple
     * antialiasing.
     */
    if (swidth >= 1)
        w = 1 - 2*GWF;
    else {
        w = clamp (boxstep(GWF-swidth,GWF,ss), max(1-GWF/swidth,0), 1)
        - clamp (boxstep(1-GWF-swidth,1-GWF,ss), 0, 2*GWF/swidth);
    }
    if (twidth >= 1)
        h = 1 - 2*GHF;
    else {
        h = clamp (boxstep(GHF-twidth,GHF,tt), max(1-GHF/twidth,0),1)
        - clamp (boxstep(1-GHF-twidth,1-GHF,tt), 0, 2*GHF/twidth);
    }
    /* This would be the non-antialiased version:
     * w = step (GWF,ss) - step(1-GWF,ss);
     * h = step (GHF,tt) - step(1-GHF,tt);
     */
    groovy = w*h;


    /*
     * Add the ring patterns
     */
    fade = smoothstep (1/RingScale, 8/RingScale, fwidth);
    if (fade < 0.999) {
        ttt = tt/4+whichplank/28.38 + Wavy * noise (8*ss, tt/4);
        r = RingScale * noise (ss-whichplank, ttt);
        r -= floor (r);
        r = 0.3 + 0.7 * smoothstep(0.2, 0.55, r) * (1 - smoothstep(0.75, 0.8, r));
        r = (1-fade)*r + 0.65*fade;

        /*
         * Multiply the ring pattern by the fine grain
         */
        fade = smoothstep (2/GrainScale, 8/GrainScale, fwidth);
        if (fade < 0.999) {
            r2 = 1.3 - noise (ss*GrainScale, (tt*GrainScale/4));
            r2 = Grainy * r2*r2 + (1-Grainy);
            r *= (1-fade)*r2 + (0.75*fade);
        }
        else
            r *= 0.75;
    }
    else
        r = 0.4875;
  

    /* Mix the light and dark wood according to the grain pattern */
    woodcolor = mix (LightWood, DarkWood, r);

    /* Add plank-to-plank variation in overall color */
    woodcolor *= (1-PlankVary/2 + PlankVary * noise (whichplank+0.5));

    Ct = mix (GrooveColor, woodcolor, groovy);
    Nf = normalize(N);
BSDF =  Ct * DiffuseAmt;

   // BSDF = Ct * DiffuseAmt * diffuse(Nf);
  //  BSDF += SpecularColor * SpecularAmt;
}
Attachments
a3.jpg
a2.jpg
a1.jpg
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
sbstnc
Licensed Customer
Posts: 120
Joined: Mon Jul 25, 2016 1:21 am

This is amazing, any plans to add an OSL section the Live Database? Would be a handy way to collect and submit these types of materials.
User avatar
aoktar
Octane Plugin Developer
Posts: 16066
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Contact:

camera shader test

Code: Select all

#include <octane-oslintrin.h>

shader OslCamera(
    color dist=0,
    output point  pos  = P,
    output vector dir  = 0,
    output float  tMax = 1.0/0.0)
{
    float pa;
    int res[2];

    getattribute("camera:pixelaspect", pa);
    getattribute("camera:resolution", res);

    //point n = noise("noise", 4*point(u,v,0));
    color  n = _evaluateDelayed(dist, u, v);

    float aspect = pa * res[1] / res[0];

    vector right = cross(I, N);
    dir = I + right * (u - .5) + N * (v - .5) * aspect + 0.1*(n);
}
Attachments
a1.jpg
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
Jolbertoquini
Licensed Customer
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London
Contact:

aoktar wrote:
J.C wrote:Thanks calus. This compiles now but it does not work as advertised by Chaos group. The flakes does not scale. I just can see some two big triangles.
You should slightly modify parameters and code. See image.
Hi Guys,

Quick question? I was looking at the flakes how to use with triplanar projection ? on stadalone? Just a curiosity.

Cheers,
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
funk
Licensed Customer
Posts: 1206
Joined: Mon Feb 07, 2011 1:24 pm
Location: Australia

Jolbertoquini wrote:Quick question? I was looking at the flakes how to use with triplanar projection ? on stadalone? Just a curiosity.
I added a projection pin then used it in the position calculation like this:

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]);
    }
}
Attachments
triplanar_osl_flakes.png
Win10 Pro / Ryzen 5950X / 128GB / RTX 4090 / MODO
"I am the resurrection, and the life: he that believeth in me, though he were dead, yet shall he live" - Jesus Christ
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Well done Funk :)
Pascal ANDRE
User avatar
Jolbertoquini
Licensed Customer
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London
Contact:

funk wrote: I added a projection pin then used it in the position calculation like this:
Hi Funk,

Thanks nice move :) yeah!
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
Post Reply

Return to “Development Build Releases”