Creating a simple specular shader to test out vex.
Problem: I do not get a specular even though it seems to calculate specular. Please Help.
#ifndef VOP_SHADING
#define VOP_SHADING
#endif
#ifndef VOP_SURFACE
#define VOP_SURFACE
#endif
#pragma opname HelloWorld
#pragma oplabel “VEX Builder Surface”
#pragma opmininputs 0
#pragma opmaxinputs 0
#pragma label surfaceColor “Surface Color”
#pragma label surfaceOpac “Opacity Color”
#pragma label specularColor “Specular Color”
#pragma hint surfaceColor color
#pragma hint surfaceOpac color
#pragma hint specularColor color
#pragma range Ka 0 1.0
#include <shading.h>
#include <math.h>
surface
helloWorld(float Ka = 0.5;
float Kd = 0.85;
float Ks = 1;
float roughness = 0.2;
vector surfaceColor = {1,1,1};
vector surfaceOpac = {1,1,1};
vector specularColor = {1,1,1}
{
vector Nn = normalize(N);
vector V = -1 * normalize(N);
Of = surfaceOpac;
vector temp = Ka * ambient() + Kd * diffuse (Nn);
vector col = Of * surfaceColor * temp;
Nn = frontface(Nn,V);
vector spec = specularColor * Ks * specular( Nn, V, roughness );
Cf = col + spec ;
}
Specular Shader
1932 2 1- som
- Member
- 40 posts
- Joined: Oct. 2012
- Offline
- danylyon
- Member
- 8 posts
- Joined: June 2008
- Offline
I think your vectors are a bit off. Its generally a good Idea to define them once and not change them. I normally do this at the beginning:
vector Nn = normalize(N);
vector Nf = normalize(frontface(N, I)); // normal facing to the viewer
vector Vn = normalize(-I); // points towards the viewer
your V vector is actually an inverted N vector.
Also note the difference between I and V vectors. I goes from the Eye to the surface. Most of the time you will want the inverted (the V vector)
vector Nn = normalize(N);
vector Nf = normalize(frontface(N, I)); // normal facing to the viewer
vector Vn = normalize(-I); // points towards the viewer
your V vector is actually an inverted N vector.
Also note the difference between I and V vectors. I goes from the Eye to the surface. Most of the time you will want the inverted (the V vector)
- som
- Member
- 40 posts
- Joined: Oct. 2012
- Offline
-
- Quick Links