Halloween Costume ideas 2015

OSL / Sun Flower

I was studying some videos from Inigo Quilez YouTube Channel and this one I think is also a good study, better and simpler "flower" or "clover":
http://www.youtube.com/watch?v=_1FgCX0-Ny4

Nothing fancy with this code, it is supposedly really simple and good to read through and to actually understand what is happening. Would be nice to sit down and understand the Math function.


THE CODE

/*
SOURCE: 
    http://www.youtube.com/watch?v=_1FgCX0-Ny4
    forumlanimations :: creating a smiley sun
    Live Coding by Inigo Quilez

Translated to OSL and modified by Jimmy Gunawan 2013.08.19 @ Blender Sushi Blog
    
*/ 

shader sunflower(
    color ColorBase = color(1,1,0),
    color ColorA = color(0,0,1),
    float Scale = 1.0,
    float Rotation = 0.0,
    float offsetX = 0.0,
    float offsetY = 0.0,
    float offsetZ = 0.0,
    float s1 = 0.5,
    float s2 = 0.5,
    float d1 = 0.5,
    float d2 = 0.2,
    int Petal = 13,
    float CurveExp = 0.2,
    vector Vec = P,
    output color ColOut = color(0.2)
    
)
{
    
    vector p = Vec;
    
    // OFFSET?
    p -= vector(offsetX, offsetY, offsetZ);
    
    // The Petals
    float r = length(p/Scale);
    float a = atan2(p[0], p[1]) - Rotation;
    float s = s1 + s2*sin(a*Petal);
    float d = d1 + d2*pow(s, CurveExp);

    float f = (r<d)? 1.0 : 0.0;
    
    //color col = color(f,f,f);
    
    
    color colmix = mix(ColorBase, ColorA, f);

    ColOut = colmix;

}



TEXTURE COORDINATE AND MAPPING

I have this big question regarding "the right way" to do texture coordinate and mapping. Depending on the OSL code itself, sometimes the texture would work only on flat mesh and need to be tweaked.


OSL REPEATER by Gottfried of Blender Diplom

By Gottfried of "Blender Dilpom"

#include "stdosl.h"

shader node_Repeater(
    float Size = 1.0,
    float SpacingX = 1.0,
    float SpacingY = 1.0,
    point TextureVector = P,
    output point NewVec = 0
)
{
    point tempVec = TextureVector;
    
    tempVec[0] = mod(tempVec[0]/Size,SpacingX) - 0.5;
    tempVec[1] = mod(tempVec[1]/Size,SpacingY) - 0.5;
    
    NewVec = tempVec;



I like the idea of "modularity" of code within a node that does one thing or certain function well. Gottfried kindly showed this OSL Repeater code that works with any texture to do the repetition in a grid pattern. Rotation is also allowed. The texture cannot overlap though.

Gottfried "Blender Diplom" style of repeating OSL Texture.



So, I think at this stage, I should slow down and re-thinking the basic we have so far so we can expand the knowledge. I think the next step is in Masking and Layering. But it would be nice to understand the Math a little bit for every functions.




Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

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