Blender Cycles OSL: Gold Material

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


In that article I used a mix of colors I called Colombia Gold. Here I have called this mix as Egypt Gold. This is the same node setup in cycles without OSL:


In most of the posts you can find in Blender Artist, the OSL code is used to get a pattern or a texture. This time I have migrated all the nodes information included in that material to the code, trying to minimize the overhead of the node system. So the OSL code is as follows:

/*
*   Migrated from "http://elbrujodelatribu.blogspot.com.es/2013/01/gold-material.html"
*   By: elbrujodelatribu
*/

shader node_metal_gold(
    color ForeColor = 0.8,
    color MiddleColor = 0.4,
    color BackColor = 0.1,
    vector Normal = N,
    float ForeRoughness = 0.01,
    float BackRoughness = 0.04,
    output closure color Metal = 0.0)
{
    closure color ForeClosure = background();
    closure color BackClosure = background();

    // Facing colors - formula from Blender OSL code
    float Factor1 = 1.0 - pow(fabs(dot(I,Normal)),2.0*0.465);
    
    // Dot vectors
    float Factor2 = clamp(pow(dot(Normal,I),1.3),0.0,1.0);

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

And the node setup is this:


And you only need to change the colors for the Colombia Gold:


If you are interested in the render times, in my CPU this material renders 111% longer than the Cycles version without OSL.

Remember you can download these materials for cycles in blendswap.

Bye

Comentarios

Unknown ha dicho que…
Hola.

Me parece interesante el tema de OSL, tomé el código que colocaste en este post, al principio me costo trabajo entender porque no corria el programa pero vi que hay que agregar al inicio.
#include "oslutil.h"
Una vez generado esto hay que agregar un nodo tipo Script y ahí cargar el script del material, pero ahora ya con todo listo no logro hacer que se renderice el material, el objeto se mantiene en color negro en la imagen final, ¿estoy omitiendo algo? saludos y grecias por compartir

Entradas populares de este blog

Santa Alejandra

Stucco Material III

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