Blender Cycles OSL: Sierpinski Squares

Hi everybody. Today I'm going to show you a Sierpinski Squares material using OSL and blender.


The code for the sierpinski squares pattern is as follows:

/*
*   Migrated from "http://glsl.heroku.com/e#1891.0"
*   By: elbrujodelatribu
*/

float genCheck(vector p, float res)
{
    return (mod(res * p[0], 1.0) < 0.5 ^ mod(res * p[1], 1.0) < 0.5) ?
        0.0 : 1.0;
}

shader node_sierpinski_squares(
    float Scale = 1.0,
    float Zoom = 1.0,
    vector Vector = P,
    float MaxIterations = 10.0,
    output float Fac = 1.0,
    output color ColorOut = 0.8)    
{
    vector p = Vector*Scale/(2.0*Zoom);
    float diExp = 1.0;
    float result = genCheck(p,1.0);

    for(float i = 0.7; i <= MaxIterations; i++)
    {
        result += genCheck(p,diExp) / i;

        diExp *= 2.0;
    }
    result /= MaxIterations / 2.0;

    Fac = result;
    ColorOut = color(result,result,result);
}

This will be a basic render colored by the pattern:


I have applied this pattern to an anisotropic shader. This is the node setup:


 Here there are other renders and their node setups:





 And this is the node setup of my first render in this article:


The Scale and Zoom parameters can be used to see different levels of detail. In this renders I have used a Mapping node instead.

I hope you like them.

Bye

Comentarios

Entradas populares de este blog

Santa Alejandra

Stucco Material III

Blender Cycles: Vector Transform for Texturing (New Feature in Blender 2.69)