miércoles, 25 de septiembre de 2013

Blender Cycles OSL: Copper Material

Hi everybody. Today I'm going to show you a migration to OSL of my Copper Material:



This is the Cycles version:



As I did with my OSL Gold Material, I have migrated all the nodes information included in that material to the code, trying to minimize the overhead of the node system. This time the facing value is an input parameter in the script. So the OSL code is as follows:

/*
*   Migrated from "http://elbrujodelatribu.blogspot.com/2013/07/cooper-material.html"
*   By: elbrujodelatribu
*/
 
shader node_metal_copper(
    color ForeColor = 0.8,
    color MiddleColor = 0.4,
    float Facing = 0.665,
    float ForeRoughness = 0.01,
    color BackColor = 0.1,
    float BackRoughness = 0.04,
    normal Normal = N,
    output closure color Metal = 0.0)
{
    closure color ForeClosure = background();
    closure color BackClosure = background();
 
    // Facing colors - formula and code from Blender OSL code
    float aux = fabs(dot(I,(vector)Normal));
    float facing = Facing;

    // code from Blender 2.68
    if (facing != 0.5) {
        facing = clamp(facing, 0.0, 1.0 - 1e-5);
        facing = (facing < 0.5) ? 2.0 * facing : 0.5 / (1.0 - facing);

        facing = pow(aux, facing);
    }

    float Factor1 = 1.0 - facing;
     
    // Dot vectors
    float Factor2 = clamp(pow(dot((vector)Normal,I),1.3), 0.0, 1.0 - 1e-5);

    // Create and mix closures    
    ForeClosure = ((1-Factor1)*ForeColor + MiddleColor*Factor1)*microfacet_beckmann(Normal,ForeRoughness);
    BackClosure = BackColor*microfacet_beckmann(Normal,BackRoughness);
     
    Metal = ((1-Factor2)*BackClosure)+(ForeClosure*Factor2);
}

The node setup of the copper material is this:


By changing the colors you can get a yellowish version of this kind of material:


You can download this material for cycles (no OSL) inside my metal pack available in blendswap.

Bye

1 comentario:

Unknown dijo...

Hey very useful tutorials, congratulations and thaks for sharing. You Rock!

Este sitio emplea cookies de Google para prestar sus servicios, para personalizar anuncios y para analizar el tráfico. Google recibe información sobre tu uso de este sitio web. Si utilizas este sitio web, se sobreentiende que aceptas el uso de cookies. Más información Entendido