Okay, so here is the vertex shader:
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
varying vec2 uvVarying;
varying vec3 normalVarying;
varying vec3 posVarying;
uniform vec4 uvBounds0;
uniform vec4 startUV;
uniform vec4 endUV;
uniform mat4 agk_World;
uniform mat4 agk_ViewProj;
uniform mat3 agk_WorldNormal;
void main()
{
vec4 pos = agk_World * vec4(position,1);
gl_Position = agk_ViewProj * pos;
vec3 norm = agk_WorldNormal * normal;
posVarying = pos.xyz;
normalVarying = norm;
uvVarying = uv * uvBounds0.xy + uvBounds0.zw;
}
And the pixel shader:
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
uniform sampler2D texture0;
uniform sampler2D texture1;
varying vec2 uvVarying;
varying vec3 normalVarying;
varying vec3 posVarying;
uniform vec4 agk_PLightPos;
uniform vec4 agk_PLightColor;
uniform vec4 agk_MeshDiffuse;
// used to set light-falloff range for fog
uniform float lightRange;
void main()
{
vec3 dir = agk_PLightPos.xyz - posVarying;
vec3 norm = normalize(normalVarying);
float atten = dot(dir,dir);
atten = clamp(agk_PLightPos.w/atten,0.0,1.0);
float intensity = dot(normalize(dir),norm);
// fog-distance
float fog = clamp(length(dir),0.01,10000.0)/lightRange;
intensity = clamp(intensity,0.0,1.0);
vec3 color = agk_PLightColor.rgb * intensity * atten;
gl_FragColor = clamp((texture2D(texture0, uvVarying ) * vec4(color,1) * agk_MeshDiffuse)/fog,0.00001,1.0);
}
And the way I call it, at the start of the program:
LoadShader(ShaderID, "shaders/org_shader-texture-pointlight_fog.vs", "shaders/org_shader-texture-pointlight_fog.ps")
SetShaderConstantByName(ShaderID, "lightRange", ObjectSize# * 2.1, 0, 0, 0 )
I've already changed agk_ObjColor to agk_MeshDiffuse, but alas... no dice as yet.