Halloween Costume ideas 2015

OSL / A Simple Pixar Eye Ball

Procedural Pixar Eyes, based on Inigo Quilez "A Simple Eye" code.

ORIGIN OF THE CODE

Based on this video by Inigo Quilez:
http://www.youtube.com/watch?v=emjuqqyq_qc

OSL PROCEDURAL EYE (roughly translated)

I am converting the GLSL code into OSL code below:

// original code by by Inigo Quilez
// http://www.youtube.com/watch?v=emjuqqyq_qc
// translated by Jimmy Gunawan
// 2013.08.19

// the matrix stuff is not added , yet...
// and I need to tweak the OSL code so that Texture Coordinate can be used



// fractional brownian motion
float fbm( vector Pos )
{
    // this will return the classic cloud pattern noise
    float f = 0.0;
    f += 0.500 * noise(Pos); Pos *=2.02;
    f += 0.250 * noise(Pos); Pos *=2.03;
    f += 0.125 * noise(Pos); Pos *= 2.01;
    f += 0.0625 * noise(Pos); Pos *- 2.04;
    f /= 0.9375;
    return f;
}

shader pixarEye(
    color ColorBase = color(1,1,1),
    color ColorEye = color(1,0,0),
    color ColorGlow = color(0,1,0),
    float myTime = 0.0,
    output color ColOut = color(0.2)

)

{
    //float myNoise = noise(1.0 * P); // frequency adjustable
    // color myNoise = noise(1.0 * P); // frequency adjustable
    // float myNoise = fbm(P);
    
    //float background = smoothstep(-0.25, 0.25, P[0]);
    
    float r = sqrt (dot(P,P));
    float a = atan2(P[1], P[0]);
    
    // this moves the pixel 
    // P[0] -= 1000;
    
    //color col = color(1.0); 
    color col = ColorBase;
    
    // adding some animation to the eyes
    float ss = 0.5 + 0.5*sin(myTime);
    float anim = 1.0 + 0.1*ss; 
    r *= anim;
    
    if( r<0.8 )
    {
        //col = color(0.0, 0.3, 0.4);
        col = ColorEye;
        
        // adding the fbm noise
        float f = fbm( 5.0 * P );
        col = mix(col, color(0.2, 0.5, 0.4), f);
        
        // adding glow yellow area?
        f = 1 - smoothstep(0.2, 0.5, r);
        //col = mix(col, color(0.9, 0.6, 0.2), f);
        col = mix(col, ColorGlow, f);
        
        // crazy wavy modulation 
        a += 0.1 * fbm ( 20.0*P );
        
        
        
        // adding white fiber
        f = smoothstep(0.3, 1.0, fbm( vector( 6.0*r, 20.0*a, 0.0 ) ) ); // changing contrast
        col = mix(col, color(1.0), f);
        
        // adding black fiber
        f = smoothstep( 0.4, 0.9, fbm( vector( 10.0*r, 15.0*a, 0.0) ) );
        col *= 1.0 - 0.9*f;
        
        // multiplying with black on the edge
        f = smoothstep( 0.6, 0.8, r);
        col *= 1.0 - 0.8*f;
        
        // adding dark circle to the center of the eyes
        f = smoothstep(0.2, 0.25, r);
        col *= f;

        // fake reflection, the glint in the eye
        f = 1.0 - smoothstep( 0.0, 0.3, length( P-vector(0.25,0.1,0.0)) ); 
        col += color(1.0, 0.9, 0.8) * f * 0.9;
        
        
        
        // the edge was too antialias, so added this blur on the eye edge
        f = smoothstep(0.7, 0.8, r);
        //col = mix(col, color(1.0), f);
        col = mix(col, ColorBase, f);
        
    }
    
    ColOut = col;
}


Feel free to tweak the code, add parameters, replacing values with variables, but I think being able to write this code yourself and understand every steps that is explained by Inigo Quilez will be more beneficial to your OSL study.

I honestly learned a lot by converting and rewriting the code from Inigo's video, I think I will do that a couple of times until it really sticks in my brain.



EYEBALL TWEAK #001


  • Vector INPUT is now added, so that you can use Texture Coordinate and adjust the Mapping
  • Size of the Eye (Iris) is adjustable
  • Size of the Pupil is adjustable (that black part)
  • Eye Glint (fake reflection) is adjustable in position and actual contrast
Updated Code:

// origin by Inigo Quilez
// translated by Jimmy Gunawan
// 2013.08.19

// the matrix stuff is not added , yet...
// and I need to tweak the OSL code so that Texture Coordinate can be used



// fractional brownian motion
float fbm( vector Pos )
{
    // this will return the classic cloud pattern noise
    float f = 0.0;
    f += 0.500 * noise(Pos); Pos *=2.02;
    f += 0.250 * noise(Pos); Pos *=2.03;
    f += 0.125 * noise(Pos); Pos *= 2.01;
    f += 0.0625 * noise(Pos); Pos *- 2.04;
    f /= 0.9375;
    return f;
}

shader pixarEye(
    color ColorBase = color(1,1,1),
    color ColorEye = color(1,0,0),
    color ColorGlow = color(0,1,0),
    vector Vec = P,
    float Scale = 0.5,
    float PupilSize = 1.0,
    float GlintPosX = 0.25,
    float GlintPosY = 0.1,
    float GlintMin = 0.0,
    float GlintMax = 0.24,
    float myTime = 0.0,
    output color ColOut = color(0.2)

)

{
    //float myNoise = noise(1.0 * P); // frequency adjustable
    // color myNoise = noise(1.0 * P); // frequency adjustable
    // float myNoise = fbm(P);
    
    //float background = smoothstep(-0.25, 0.25, P[0]);
    
    vector p = Vec;
    
    float r = sqrt (dot(p/Scale,p/Scale));
    float a = atan2(p[1], p[0]);
    
    // this moves the pixel 
    // P[0] -= 1000;
    
    //color col = color(1.0); 
    color col = ColorBase;
    
    // adding some animation to the eyes
    float ss = 0.5 + 0.5*sin(myTime);
    float anim = 1.0 + 0.1*ss; 
    r *= anim;
    
    if( r<0.8 )
    {
        //col = color(0.0, 0.3, 0.4);
        col = ColorEye;
        
        // adding the fbm noise
        float f = fbm( 5.0 * p );
        col = mix(col, color(0.2, 0.5, 0.4), f);
        
        // adding glow yellow area?
        f = 1 - smoothstep(0.2, 0.5, r);
        //col = mix(col, color(0.9, 0.6, 0.2), f);
        col = mix(col, ColorGlow, f);
        
        // crazy wavy modulation 
        a += 0.1 * fbm ( 20.0*p );
              
        
        // adding white fiber
        f = smoothstep(0.3, 1.0, fbm( vector( 6.0*r, 20.0*a, 0.0 ) ) ); // changing contrast
        col = mix(col, color(1.0), f);
        
        // adding black fiber
        f = smoothstep( 0.4, 0.9, fbm( vector( 10.0*r, 15.0*a, 0.0) ) );
        col *= 1.0 - 0.9*f;
        
        // multiplying with black on the edge
        f = smoothstep( 0.6, 0.8, r);
        col *= 1.0 - 0.8*f;
        
        // adding dark circle to the center of the eyes = PUPIL
        f = smoothstep(0.2, 0.25, r/PupilSize);
        col *= f;

        // fake reflection, the glint in the eye
        f = 1.0 - smoothstep( GlintMin, GlintMax, length( p-vector(GlintPosX,GlintPosY,0.0)) ); 
        col += color(1.0, 0.9, 0.8) * f * 0.9;
        
        
        
        // the edge was too antialias, so added this blur on the eye edge
        f = smoothstep(0.7, 0.8, r);
        //col = mix(col, color(1.0), f);
        col = mix(col, ColorBase, f);
        
    }
    
    ColOut = col;
}





When applying to another mesh, you may need to tweak the Texture Mapping coordinate.

Suzanne with procedural OSL Pixar Eyes.

Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

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