First off, this is a Uni assignment, but the lecturer is stumped too.
The light (attached to the mouse) only works when inside of the object (a sphere in this case). I've tried multiplying the normals of the sphere by -1 and the distance of the light to the sphere by -1 also. I have no idea what the cause of this is.
Here is the fragment shader:
const float lightWeighting = 0.75;
const float textureWeighting = 0.25;
const float PI = 3.14;
const float lightIntensity = 1.0;
const float constFudge = 0.025;
const float linearFudge = 0.025;
const float quadraticFudge = 0.05;
float rend = 250.0;
float rstart = 50.0;
uniform float Intensity;
uniform sampler2D grabTexture;
//varying sampler2D HeatValues
varying vec3 Normal;
varying vec3 Vertex;
varying vec2 texCoord;
void main(void)
{
vec3 pigPos = Vertex;
vec3 normPigPos = normalize(pigPos);
vec3 lightPos = vec3(gl_LightSource[0].position.xyz);
vec3 normLightPos = normalize(lightPos);
float effectiveIntesity;
vec3 normNormal = normalize(vec3(Normal.xyz));
vec3 t = vec3(pigPos - lightPos);
float distToLight = length(t); //I belive this is where it is going wrong
float d = dot(normNormal.xyz, normLightPos.xyz);
if(d > 0.0)//facing the light
{
effectiveIntesity = d*lightIntensity * (1.0/(constFudge + (linearFudge*distToLight) +(quadraticFudge*distToLight*distToLight)));
}
else
{
effectiveIntesity = 0.0;
}
//TODO: change the colour of the pixel
vec4 lightingColour = vec4(vec4( 1.0 ) * effectiveIntesity); //TODO: improve
gl_FragColor = lightingColour;
}
Vertex Shader as requested:
//I am surprisingly important
uniform float Intensity;
varying vec3 Normal;
varying vec3 Vertex;
varying vec2 texCoord;
void main(void)
{
gl_Position = ftransform();
texCoord = gl_MultiTexCoord0.xy;
Normal = vec3(gl_Normal.xyz);
Vertex = vec3(gl_Vertex.xyz);
}
Normals are as loaded from the obj file which was produced with blender
vec3 lP = vec3(abs(gl_LightSource[0].position.x/100), abs(gl_LightSource[0].position.y/100), abs(gl_LightSource[0].position.z/100));
\$\endgroup\$