hi everyone hope someone can help me
i’ve just recently started glsl as part of project and am using 3ds models which require a two sided light model. I have the book by randi rost and have put together a vertex shader but i have no idea if its right and no idea what goes into the fragment shader.
This is what i have so far (taken from chapter 9 of the orange book)
vertex shader
varying vec3 normal;
void DirectionalLight(in int i, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
float nDotVP; // normal . light direction
float nDotHV; // normal . light half vector
float pf; // power factor
nDotVP = max(0.0, dot(normal, vec3(gl_LightSource[0].position)));
nDotHV = max(0.0, dot(normal, vec3(gl_LightSource[0].halfVector)));
if(nDotVP == 0.0)
pf = 0.0;
else
pf = pow(nDotHV, gl_FrontMaterial.shininess);
ambient += gl_LightSource[0].ambient;
diffuse += gl_LightSource[0].diffuse;
specular += gl_LightSource[0].specular * pf;
}
void main(void)
{
// Vertex transformation
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
// Normal transformation
normal = gl_NormalMatrix * gl_Normal;
normal = normalize(normal);
vec4 amb;
vec4 diff;
vec4 spec;
vec4 color;
// Clear light intensity accumulators
amb = vec4(0.0);
diff = vec4(0.0);
spec = vec4(0.0);
if(gl_LightSource[0].position.w == 0.0)
DirectionalLight(0, normal, amb, diff, spec);
color = gl_FrontLightModelProduct.sceneColor +
amb * gl_FrontMaterial.ambient +
diff * gl_FrontMaterial.diffuse;
color += spec * gl_FrontMaterial.specular;
gl_FrontColor = color;
// Compute back sided surface
normal = -normal;
// CLear light intensity accumulators
amb = vec4(0.0);
diff = vec4(0.0);
spec = vec4(0.0);
if(gl_LightSource[0].position.w == 0.0)
DirectionalLight(0, normal, amb, diff, spec);
color = gl_BackLightModelProduct.sceneColor +
amb * gl_BackMaterial.ambient +
diff * gl_BackMaterial.diffuse;
color += spec * gl_BackMaterial.specular;
gl_BackColor = color;
}
fragment shader
varying vec3 normal;
void main(void)
{
}
any help would be much appreciated
thanks in advance
matt