1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
uniform float pointRadius; // point size in world space
uniform vec3 lightDir = vec3(0.577, 0.577, 0.577);
varying vec3 posEye; // position of center in eye space
void main()
{
//const vec3 lightDir = vec3(0.577, 0.577, 0.577);
const float shininess = 50.0;
// calculate normal from texture coordinates
vec3 N;
N.xy = gl_TexCoord[0].xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
float mag = dot(N.xy, N.xy);
if (mag > 1.0) discard; // kill pixels outside circle
N.z = sqrt(1.0-mag);
// point on surface of sphere in eye space
vec3 spherePosEye = posEye + N*pointRadius;
// calculate lighting
float diffuse = max(0.0, dot(lightDir, N));
// gl_FragColor = gl_Color * diffuse;
vec3 v = normalize(-spherePosEye);
vec3 h = normalize(lightDir + v);
float specular = pow(max(0.0, dot(N, h)), shininess);
gl_FragColor = gl_Color * diffuse + specular;
}
); |
Partager