Jump to content
  • Advertisement
Sign in to follow this  

Really basic GLSL question

This topic is 4977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!