Specular Light
Ein Shader mit Glanzlicht.
Screenshot:

Vertex Shader:
uniform vec3 LightPos; varying float LightIntensity; varying float SpecIntensity; vec3 Normal; void main(){ gl_Position = ftransform(); vec3 pos = vec3(gl_ModelViewMatrix * gl_Vertex); Normal = normalize(gl_NormalMatrix * gl_Normal); vec3 posToLight = normalize(LightPos - pos); LightIntensity = max(dot(posToLight, Normal), 0.0); //Specular by Randi Rost: www.3dshaders.com vec3 reflectVec = reflect(-posToLight, Normal); vec3 viewVec = normalize(-pos); SpecIntensity = max(dot(reflectVec, viewVec), 0.0); }
Fragment Shader:
varying float LightIntensity; varying float SpecIntensity; uniform vec3 Color; uniform float SpecularLevel; uniform float SpecularSize; void main(){ vec3 thisColor = Color * LightIntensity; thisColor += max(0.0, SpecularLevel * pow(SpecIntensity, SpecularSize)); gl_FragColor = vec4(thisColor, 1.0); }