Let there be light!

…and then I said, let there be light! …and there was light!

So after having studied OpenGL shaders a bit in my book, I’ve made another textured cube: this time the texture is a wooden box instead of the OpenGL logo. Also I’ve added lighting using vertex and fragment shaders.

Basically how it works is, there’s a diffuse light source in the scene at -100.0, 100.0, 100.0 and some ambient lighting too ( 30% ambient contribution ). The vertex shader interpolates the texture coordinates, and the diffuse lighting between the vertices for the fragment shader, and then the fragment shader samples the texture at the interpolated coordinates and multiplies the color with ( ambient + diffuse ).

Fairly simple, and yet looks pretty nice imho. So enjoy!



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: