Pages

Se afișează postările cu eticheta Open Shading Language. Afișați toate postările
Se afișează postările cu eticheta Open Shading Language. Afișați toate postările

miercuri, 4 octombrie 2017

Blender 3D - Open Shading Language tutorial - part 001 .

Using this tutorial about Open Shading Language, you can try a glass shader. The source code show a simple use for Fresnel equations. The backfacing() and raytype() are two functions that provide the shader some information about the state of the renderer and the scene at the time of evaluation. I used just backfacing(), because is a raw example of this Fresnel equations. As you can see the I, N, eta inputs from Fresnel_Dielectric() is used to get a result variable fr. The all result of this shader is bsdf like a equation. See the next code:
#define IOR_THRESHOLD 1.000000001

float Fresnel_Dielectric(vector i, normal n, float eta)
{
//see https://en.wikipedia.org/wiki/Fresnel_equations
    float c = fabs(dot(i, n));
    float g = eta * eta - 1 + c * c;
    float result = 1.0;
    
    if (g > 0) {
        g = sqrt(g);
        float a = (g - c) / (g + c);
        float b = (c * (g + c) - 1) / (c * (g + c) + 1);
        result = 0.5 * a * a * (1 + b * b);
    }
    
    return result;
}

shader glass(
    color diffuse_col = 1.8, 
    float ior = 1.45, 
    output closure color bsdf = 0)
{
    float real_ior = max(ior, IOR_THRESHOLD);
    float eta = backfacing()? 1.0 / real_ior : real_ior;
    float fr = Fresnel_Dielectric(I, N, eta);
    
    bsdf = diffuse_col * (fr * reflection(N) + (1.0 - fr) * refraction(N, eta));
}

miercuri, 27 septembrie 2017

Blender 3D - Open Shading Language tutorial.

Today, I will show you how to use the Open Shading Language with Blender 3D version 2.79.
Use the Scripting area from Screen layout and Cycles for rendering.
Select from Render tab and check the option:Open Shading Language.
Add your object to test this tool.
For example you can use the default Cube.
Add a material to this object.
The Scripting area from Screen layout come with editor text.
Use Templates - > Open Shading Language -> Empty Shader and add this OSL script:
shader marble (color Col = .5, float freq = 1.0,  
           output color result = 0)  
{  
float sum = 0;  
float freq_value = freq;  

point pixel_shader = transform ("object", P);  
for (int i = 0; i < 6; i++)   
{  
    sum = sum + 1/freq_value * abs(.5 - noise( 4 * freq_value * pixel_shader)) ;  
    freq_value = 2 * freq_value;  
}  
result = Col * sum;  
}  
Save this script into your folder . Add a OSL script interface into Node Editor using : Add -> Script -> Script.
This will come with a open dialog icon to add your OSL script.
Link result to Color from your material Diffuse BSDF. All this steps I tell you is on the next image: