Using VEX to create a basic plastic lighting model.
A .vfl file that generates a basic light shader.
Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Tuesday July 29th, 2008 11:29 PM

#pragma hint Ka color
#pragma hint Kd color
#pragma hint Ks color
#pragma label Ka "Ambient"
#pragma label Kd "Diffuse"
#pragma label Ks "Specular"
#pragma label roughness "Roughness"
#include <math.h>
#include <shading.h>
vector
d_amb(vector P, Nn)
{
vector amb=0;
illuminance(P,Nn,PI*2,LIGHT_AMBIENT) {
amb += Cl;
}
amb += .1;
return amb;
}
vector
d_diff(vector P, Nn)
{
vector diffuse = 0;
illuminance(P,Nn,PI/2,LIGHT_DIFFUSE) {
shadow(Cl);
diffuse += Cl * dot(Nn,normalize(L));
}
return diffuse;
}
vector
d_spec(vector P, Nn, In; float rough)
{
vector spec = 0;
vector IandL;
illuminance(P,Nn,PI/2,LIGHT_DIFFUSE)
{
shadow(Cl);
IandL = normalize(In + normalize(L));
spec += Cl * pow(max(0,dot(Nn,IandL)),1/(rough*.1));
}
return spec;
}
surface
d_plastic
(
vector Ka=1, Kd=1, Ks=1;
float roughness = .1;
)
{
vector Nn = normalize(N);
vector In = normalize(I);
Cf = d_amb(P,Nn)*Ka;
Cf += d_diff(P,Nn)*Kd;
Cf += d_spec(P,Nn,-In,roughness)*Ks;
}
Downloads:
Download: lighting_model.vfl 1 KB
Please login or Click Here to register for downloads
Plastic Lighting Model by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
