Halloween Costume ideas 2015

OSL / Circle Scatter and Bombing - Part One



In this post, I am trying to defragment some of previous collected information and to make a bit more sense of the bits and pieces of codes for further modification.

I am writing this while having Blender open and I am actually testing the OSL code and I did make lots of mistakes and fixing it along the ways. I might change the code variables (lowercase or capital) --- I tried not to do that too often.

Hopefully by the end of article, we will get something nice and interesting. If I am stuck, there will be "to be continued".

One day, perhaps I will attempt a LIVE coding.

START FROM SOMETHING, NOT NOTHING

Sometimes it is nice to start with a blank code. However, often that is not the case, it is a better idea to start with some kind of template or prepared plan.

Ok, I started by looking at my old code "OSL Grid"
http://blendersushi.blogspot.com.au/2013/08/osl-disk-grid.html

I will also reference this post where I create random stripes.
http://blendersushi.blogspot.com.au/2013/10/osl-wooly-mummy-osl.html

The OSL code from "OSL Grid" will render out as:

  • Grid of Circles/Disks (Polka Dots)
  • Radius of Circle is adjustable (same size of every circle, because it is just a repeat)
  • Circle Fuzz (blur) parameter is included.

From that polka dots code, I am now modifying it to fit the previous concept on LAYERING. I may strip out some code to get to the essence (create Circle ONLY) and then expand from that idea.

FIRST MODIFICATION - Layering

Below is my first attempt to include the LAYERING concept, while keeping most of the old code and commenting out some of older code.

CODE:

/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(
    point center = point (0.5, 0.5, 0.0),
    float fuzz = 0.025,
    float Radius = 0.5,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // initialize coordinate
    float x = Pos[0];
    float y = Pos[1];
    
    float s = x;
    float t = y;

    float ss = mod(s*RepeatS, 1);
    float tt = mod(t*RepeatT, 1);
    
    // background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // create Circle on top of background layer
    point here = point (ss, tt, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - fuzz, Radius/2.0+fuzz, dist);
    
    surface_color = blend(surface_color, layer_color, inDisk);
    
    // output final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}


MODIFICATION #001 - Just Create A Circle

Having equation to repeat the pattern is nice. This is possible because of the MOD() function. But before we get there, let's strip out all the code so we have just a code that creates just a circle.

The code seems to work better with UV setup.


Code stripped out and it is creating Circle ONLY!

CODE:


/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(
    point center = point (0.5, 0.5, 0.0),
    float fuzz = 0.025,
    float Radius = 0.5,
    //float RepeatS = 5,
    //float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    // float ss = mod(s*RepeatS, 1);
    // float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Create Circle on top of background layer
    point here = point (s, t, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - fuzz, Radius/2.0+fuzz, dist);
    
    surface_color = blend(surface_color, layer_color, inDisk);
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}


MODIFICATION #002 - User Control for Position

Ok, now that we can create a single dot. Can we adjust its position? Yes.

You may notice there is this point attribute called "center" that is declared above the function. So, I decided to give the user real-time ability to modify this "center" attribute, and by doing so, user can now place the Circle or Dot at any position they like.

User now have control over the placement of the Circle. A sun at the corner of one fine blue sky.

CODE:

/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(    
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    //float RepeatS = 5,
    //float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    // float ss = mod(s*RepeatS, 1);
    // float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Create Circle on top of background layer
    point here = point (s, t, 0);
    float dist = distance(center, here);
    float inDisk = 1 - smoothstep(Radius/2.0 - Fuzzy, Radius/2.0+Fuzzy, dist);
    
    surface_color = blend(surface_color, layer_color, inDisk);
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}


NOTE: I think it is kind of nice to write the code like this:
  • variable that is exposed to user = write in Capital
  • variable that is hidden to user = write in lowercase

MODIFICATION #003 - Radius and Color Random

Ok, what is the next thing we can do to make this texture interesting? We have a very basic OSL code with functions and equations that:
  • Create CIRCLE 
  • at POSITION specified
  • with SIZE
  • and FUZZINESS that we can adjust in realtime.
How about SCATTER? I always like the ability to scatter points at random places.

There is this thing in Shader Writing called "bombing", from my understanding it is like scattering shapes:

Before we get to "bombing", I want to test whether we can simply use the LAYERING and LOOP to randomly stamp some circles? The "looping and stamping" method is probably slower than "bombing", however, let's try it anyway:

CODE:
/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(    
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    int Seed = 0,
    int Iteration = 20,
    //float RepeatS = 5,
    //float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    // float ss = mod(s*RepeatS, 1);
    // float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Do the Loop to stamp Many Circles
    
    
    // Generate repeatable sequences of 'random' numbers - based on nrand and seed settings.
     float nrand = 0;
          
     // Random helper function
     float urand () {
        nrand += 1; 
        return cellnoise(nrand, Seed);
     } 


    for (float i=0.0; i<Iteration; i++){
    
        float R=ColorB[0];
        float G=ColorB[1];
        float B=ColorB[2];
    
        float newRadius = Radius / i;    
    
        // Create Circle on top of background layer
        point here = point (s, t, 0);
        float dist = distance(center, here);
        float inDisk = 1 - smoothstep(newRadius/1.0 - Fuzzy, newRadius/1.0+Fuzzy, dist);
        
        
        //layer_color = color((i+1)/Iteration * urand(), G , B);
        
        layer_color = color(urand(), G , B);
        layer_opac = inDisk;

        surface_color = blend(surface_color, layer_color, layer_opac);
    }
    
    


    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}

Eye of a tiger?
What is happening above is we are creating Circle that goes smaller and smaller at every iteration and the color is random because for every iteration, we randomize the RED value.

MODIFICATION #004 - Positions Random Scatter


Further on, we can randomize the positions of every Circle at each iteration.



CODE:
/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(    
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    int Seed = 0,
    int Iteration = 20,
    //float RepeatS = 5,
    //float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    // float ss = mod(s*RepeatS, 1);
    // float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Do the Loop to stamp Many Circles
    
    
    // Generate repeatable sequences of 'random' numbers - based on nrand and seed settings.
     float nrand = 0;
          
     // Random helper function
     float urand () {
        nrand += 1; 
        return cellnoise(nrand, Seed);
     } 


    for (float i=0.0; i<Iteration; i++){
    
        float R=ColorB[0];
        float G=ColorB[1];
        float B=ColorB[2];
    
        point newPosition = center + point((urand()-0.5) * 0.75, (urand()-0.5) * 0.75, 0);
        float newRadius = Radius * urand() * 0.2;    
    
        // Create Circle on top of background layer
        point here = point (s, t, 0);
        float dist = distance(newPosition, here);
        float inDisk = 1 - smoothstep(newRadius/1.0 - Fuzzy, newRadius/1.0+Fuzzy, dist);
        
        
        //layer_color = color((i+1)/Iteration * urand(), G , B);
        
        layer_color = color(urand(), G , B);
        layer_opac = inDisk;

        surface_color = blend(surface_color, layer_color, layer_opac);
    }
    
    
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}

I found that at this stage, things started to get more interesting. 

Although our code is rather SIMPLE, we started to be able to create COMPLEX looking shader. Just by "stamping" Circles.

Out of curiosity, I plugged an image texture into the INPUT of color:

Interesting result, right? I didn't quite expect that. There is some kind of additive result. Probably because inside the iteration, I am referencing the ColorB.

Probably would be nice if the UV actually got distorted at each iterations. Wonder how we can do that? Save this for the future.

At present, by adjusting the Seed value, we are getting all kind of random results.

I am testing this render at around 100-500 Iterations. 1000 still work, but starting to get slow at around 5000. 10000 still works, just a bit slower with CPU render. But to think about it, the code is actually running quite fast in term of cycles.

We probably want to keep it at small value iteration while testing, but we can always push the limit.
I tidied up the code a bit, this one is more correct and correspond to user input of ColorA and ColorB:

CODE:
/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(    
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    int Seed = 0,
    int Iteration = 20,
    //float RepeatS = 5,
    //float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    // float ss = mod(s*RepeatS, 1);
    // float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Do the Loop to stamp Many Circles
    
    
    // Generate repeatable sequences of 'random' numbers - based on nrand and seed settings.
     float nrand = 0;
          
     // Random helper function
     float urand () {
        nrand += 1; 
        return cellnoise(nrand, Seed);
     } 


    for (float i=0.0; i<Iteration; i++){
    
        float R=ColorB[0];
        float G=ColorB[1];
        float B=ColorB[2];
    
        point newPosition = center + point((urand()-0.5) * 0.75, (urand()-0.5) * 0.75, 0);
        float newRadius = Radius * urand() * 0.2; 

        // Create Circle on top of background layer
        point here = point (s, t, 0);
        float dist = distance(newPosition, here);
        float inDisk = 1 - smoothstep(newRadius/1.0 - Fuzzy, newRadius/1.0+Fuzzy, dist);
        
        
        //layer_color = color((i+1)/Iteration * urand(), G , B);
        
        layer_color = color(R * urand(), G * urand() , B* urand());
        layer_opac = inDisk;

        surface_color = blend(surface_color, layer_color, layer_opac);
    }
    
    
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}



MODIFICATION #005 - Bombing
For bombing, I will follow the example here:

Seems like we just need to add some noise jitter to the s and t. Something like that.

First of all, I will bring back our REPEAT function:

CODE:
/* HELPER FUNCTIONS */

void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(    
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    int Seed = 0,
    int Iteration = 20,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    float ss = mod(s*RepeatS, 1);
    float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Do the Loop to stamp Many Circles
    
    
    // Generate repeatable sequences of 'random' numbers - based on nrand and seed settings.
     float nrand = 0;
          
     // Random helper function
     float urand () {
        nrand += 1; 
        return cellnoise(nrand, Seed);
     } 


    for (float i=0.0; i<Iteration; i++){
    
        float R=ColorB[0];
        float G=ColorB[1];
        float B=ColorB[2];
    
        point newPosition = center + point((urand()-0.5) * 0.75, (urand()-0.5) * 0.75, 0);
        float newRadius = Radius * urand() * 0.2; 

        // Create Circle on top of background layer
        point here = point (ss, tt, 0);
        float dist = distance(newPosition, here);
        float inDisk = 1 - smoothstep(newRadius/1.0 - Fuzzy, newRadius/1.0+Fuzzy, dist);
        
        
        //layer_color = color((i+1)/Iteration * urand(), G , B);
        
        layer_color = color(R * urand(), G * urand() , B* urand());
        layer_opac = inDisk;

        surface_color = blend(surface_color, layer_color, layer_opac);
    }
    
    
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}


Then, I will try to incorporate the "bombing code":



CODE:
/* HELPER FUNCTIONS */


// RMS 
// whichtile(x,freq) (floor((x) * (freq)))

float whichtile (
    float x,
    float freq
)
{
    return (floor( (x) * (freq) ));
}

// udn(x,lo,hi) (smoothstep(.25, .75, noise(x)) * ((hi) - (lo)) + (lo))

float udn(
    float x,
    float lo,
    float hi
)
{
    return ( smoothstep(.25, .75, noise(x)) * ((hi) - (lo)) + (lo) );
}

float repeat(
    float x,
    float freq
)
{
    return (mod((x) * (freq), 1.0));
}


void rotate2d (
    float x,
    float y,
    float rad,
    float ox,
    float oy,
    float rx,
    float ry
)
{
    rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);
    ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy);
}

color blend(
    color a,
    color b,
    color x
)

{
    return ((a) * (1-(x)) + (b) * (x));
}

float pulse (
    float a, 
    float b, 
    float fuzz, 
    float x
)
{
    return (smoothstep((a)-(fuzz), (a), (x)) - smoothstep((b)-(fuzz), (b), (x)));
}



/* THE ACTUAL SHADER */
shader 
DiskScatter(
    float freq = 4,
    float OffsetX = 0.5,
    float OffsetY = 0.5,
    float Fuzzy = 0.025,
    float Radius = 0.5,
    int Seed = 0,
    int Iteration = 20,
    float RepeatS = 5,
    float RepeatT = 5,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    point Pos = P,
    output color Col_Out = color(0.2)
)

{
    // Bombing Code
    float col;
    float row;
    float noi;
    float tmps;
    float tmpt;
    

    // Initialize coordinate
    point center = point (OffsetX, OffsetY, 0.0);
    float x = Pos[0];
    float y = Pos[1];
    
    // Shift it to center
    float s = x;
    float t = y;

    // Repeat grid of pattern
    float ss = mod(s*RepeatS, 1);
    float tt = mod(t*RepeatT, 1);
    
    // Background layer
    color surface_color = ColorA;
    color surface_opac = color(1.0);
    
    color layer_color = ColorB;
    color layer_opac = color(1.0);

    // Do the Loop to stamp Many Circles
    
    
    // Generate repeatable sequences of 'random' numbers - based on nrand and seed settings.
     float nrand = 0;
          
     // Random helper function
     float urand () {
        nrand += 1; 
        return cellnoise(nrand, Seed);
     } 


    for (float i=0.0; i<Iteration; i++){
    
        float R=ColorB[0];
        float G=ColorB[1];
        float B=ColorB[2];
    
        point newPosition = center + point((urand()-0.5) * 0.75, (urand()-0.5) * 0.75, 0);
        float newRadius = Radius * urand() * 0.2; 

        // Bombing
        /* base seed to udn on current row and column of tile */

        col = whichtile(s, freq);
        row = whichtile(t, freq);
        noi = noise(col * 10 + 0.5, row * 10 + 0.5);
        
        /* repeat texture coords, jitter tiles by plus or minus 0.35, 
         and rotate by 45 */
    
        tmps = repeat(s, freq) + udn(noi * 1183, -0.35, 0.35);
        tmpt = repeat(t, freq) + udn(noi * 999, -0.35, 0.35);
        
        rotate2d(tmps, tmpt, radians(45), 0.5, 0.5, ss, tt);

        
        // Create Circle on top of background layer
        point here = point (ss, tt, 0);
        float dist = distance(newPosition, here);
        float inDisk = 1 - smoothstep(newRadius/1.0 - Fuzzy, newRadius/1.0+Fuzzy, dist);
        
        
        
        layer_color = color(R * urand(), G * urand() , B* urand());
        layer_opac = inDisk;

        surface_color = blend(surface_color, layer_color, layer_opac);
    }
    
    
    
    // Output the final color
    Col_Out = surface_color;
    
    // Col_Out = mix(ColorA, ColorB, inDisk);

}

Something seems to start to happen, however, we can see an issue in term of how the Circles got LAYERED.

At this stage, I guess it is a good idea to take a step back and study the "bombing" example.

You may notice that I started to add more "helper code". Now that is actually taken from the "http://accad.osu.edu/~smay/RManNotes/rmannotes.sl"

I believe those are bunch of helper C code to help with creating pattern. I convert them when I need them. However, I wonder if we can just use #include at the beginning of our OSL shader code in order to use them? We will find out later....

ADDITIONAL NOTE 20140206

Eventually when it comes to programming, the way we structure the code and data will matter in a long run. Below is how we would draw a circle or a dot, but in a more organized matter. Doing it like this will make the code more manageable, especially when we started doing MIXING, LAYERING and MASKING.
http://www.fundza.com/rman_shaders/layered/index.html

// WHAT BECOME THE "INCLUDE" FUNCTIONS
float circle
(
    float locx,
    float locy, 
    float radius, 
    float x, 
    float y
)
{
    float result = 0;
    float d = distance(point(locx,locy,0), point(x,y,0));
    if(d <= radius)
        result = 1;
    return result;
}

// THE ACTUAL SHADERS
shader mixing 
(
    float Radius = 1.0,
    vector Pos = P,
    color ColorA = color(1,0,0),
    color ColorB = color(0,1,0),
    output color Col = 0
)
{
    float f = circle(0,0,Radius,Pos[0], Pos[1]);
    Col = mix(ColorA, ColorB, f);
}



Where to go from here is totally up to you.

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget