i am using some of the code from the Orange Book to do directional lighting, specifically this:
void DirectionalLight(in int i, in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec4 specular)
{
float nDotVP;
float nDotHV;
float pf;
nDotVP = max(0.0, dot(normal, normalize( vec3(uniLight[i].position) ) ) );
nDotHV = max(0.0, dot(normal, normalize(vryHalfVec[i])));
if(nDotVP == 0.0)
pf = 0.0f;
else
pf = pow(nDotHV, uniMaterial.shininess);
ambient += uniLight[i].ambient;
diffuse += uniLight[i].diffuse * nDotVP;
specular += uniLight[i].specular * pf;
}
It’s changed slightly from the original so as not to use any of the gl_ stuff, the vry are variables and uni are uniforms.
the line nDotHV = max(0.0, dot(normal, normalize(vryHalfVec[i])));
appears to be causing my program to crash on my ATI card, specifically vryHalfVec[i] if I remove the i and use vryHalfVec[0] it works fine, it works fine for any number up to MAX_LIGHTS when given explicitly, but does not work when I use i to access the array.
Even if I call DirectionalLight and give it 0 as the first parameter it crashes. even if i refer to vryHalfVec[i], i.e. putting vec3 temp = vryHalfVec[i]; somewhere in the function it crashes, however outside of this function, in the loop that is calling it i can use this syntax. i.e.
for(int i=0; i< MAX_LIGHTS; i++)
{
if(uniLight[i].initialised == true)
{
vec3 temp = vryHalfVec[i];
DirectionalLight(i, vryNormal, ambient, diffuse, specular);
}
}
this does not crash, but moving vec3 temp = vryHalfVec[i]; inside the function it crashes.
Any thoughts? I’m half hoping i’ve made some really dumb error. It works fine on my Nvidia, and works fine on the ATI everwhere else so long as i don’t reference vryHalfVec using i in the direct lighting function