Really basic GLSL question

Started by
2 comments, last by theZapper 19 years ago
This is my really basic shader

uniform vec4 lightPosition;

varying vec3 N; // transformed Normal
varying vec3 v; // transformed co-ordinates


void main (void)
{
// get a vector from the light to the fragment
vec3 L = normalize(lightPosition.xyz - v);

// need co-ordinates of the eye to work out specular 
vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)

// Get the reflection vector between the light and the normal
vec3 R = normalize(-reflect(L,N)); 
//R = normalize(R/=3.0);

//calculate Ambient Term:
vec4 Iamb = vec4(0.0, 0.0, 0.0, 1.0);

//calculate Diffuse Term:
// dot(N,L) gives angle between light and normal
vec4 Idiff = vec4(0.0, 0.0, 1.0, 0.0) * dot(N,L);

// calculate Specular Term:
// dot(R,E) gives angle between reflection vector and eye
vec4 Ispec = vec4(1.0, 0.0, 0.0, 0.0) * dot(E,R);


// write Total Color:
gl_FragColor = Iamb + Idiff + Ispec; 

}
How do I change the specular component so it gives me a smaller more focused highlight? i.e. make the object more glossy. Thanks
---When I'm in command, every mission's a suicide mission!
Advertisement
Unless you calculate the lighting in a fragment shader, the size of the highlight is dictated by the object tesselation.
In a fragment shader you could bias your normals to increase or descrease the size of your specular highlight.

Otherwise, the light will be interpolated by the rasterizer from the vertex to the fragment processer.

raise the spec value to a power (fiddle to suit)
 float spec = max(dot(reflection,local_EyeDir), 0.0); spec = pow(spec, 6.0);	// give it some exponent


(above is a fragment from my Doom3 style normal mapping code)
Cheers Phantom, that did it.
---When I'm in command, every mission's a suicide mission!

This topic is closed to new replies.

Advertisement