Hey guys:
I am trying to shade opengl point sprites to make them look like spheres. The shading model I am using is (color = emissive + ambient + diffuse + specular). Could any one help to see what kind of mistake might cause this problem. To see what problem is, please have a look at attached screenshot. They supposed to look like spheres with lighting effect. But the current resulting effect looks so strange.
I also attach the CG fragment program code here.
vec4 mesh_fragment(uniform float4 c:COLOR,
float2 texCoord:TEXCOORD0,
uniform sampler2D decal):COLOR
{
float4 position=float4(texCoord,0,1);
float2 normal;
normal= texCoord.xy* 2.0 - vec2(1.0);
float mag = dot(normal.xy, normal.xy);
if (mag > 1.0) discard; //clip the point sprite to make it a circle
//start initializing shading model parameters
float3 Ke={0,0,0};
float3 Ka={0,0,0};
float3 Ks={1, 1, 1};
float3 Kd={1, 1, 1};
float3 globalAmbient={1,1,1};
float3 lightColor={1,1,1};
vec3 lightPosition=vec3(-100,100,-100);
float3 eyePosition={0, 0, 13};
float shininess=32.0;
//Start performing shading model algorithm
float3 P = position.xyz;
float3 N = float3(normalize(normal),0);
// Compute emissive term
float3 emissive = Ke;
// Compute ambient term
float3 ambient = Ka * globalAmbient;
// Compute the diffuse term
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N,L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;
// Compute the specular term
float3 V = normalize(eyePosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(N,H), 0), shininess);
if (diffuseLight <= 0) specularLight = 0;
float3 specular = Ks * lightColor * specularLight;
float4 color;
color.xyz = emissive + ambient + diffuse + specular;
color.w = 1;
return color;
}