Tags

, , , , , , , , , , , , ,

Arkwood has pig intestines wrapped around his neck.

‘That is disgusting!’ I screamed.

Arkwood sniffed. ‘It died of natural causes,’ he said, taking a sip of his soda from a curly straw.

‘Oh, that’s fine then.’ I put down some newspaper on the lounge carpet, to catch the drips.

My chum had popped round to see how I was going with OpenGL lighting for the Oculus Rift virtual reality headset. I cranked up my C++ Microsoft Visual Studio application – making use of the Oculus SDK for Windows – and showed him the changes to the fragment shader.

In my last post I embellished my Phong lighting model of ambient, diffuse and specular components with a diffuse and specular map. The container I rendered had detailed wood with shiny steel borders.

In this post I will cast directional light upon lots of containers. Think of directional light as the sun, a light source that is infinitely far away with its rays hitting all objects from the same direction. The Learn OpenGL article Light casters has all the detail.

All we need do is supply the light source direction to our fragment shader, along with the ambient, diffuse and specular components:

glUniform3f(glGetUniformLocation(Fill->program, "light.direction"), -0.2f, -1.0f, -0.3f);
glUniform3f(glGetUniformLocation(Fill->program, "light.ambient"), 0.01f, 0.01f, 0.01f);
glUniform3f(glGetUniformLocation(Fill->program, "light.diffuse"), 0.5f, 0.5f, 0.5f);
glUniform3f(glGetUniformLocation(Fill->program, "light.specular"), 1.0f, 1.0f, 1.0f);

And make use of the light source direction in the fragment shader:

vec3 lightDir = normalize(-light.direction);

Here’s how our sun-like light source shines upon our bunch of containers:

See how it lights up the wood facing upward, and makes the steel borders sparkle:

Note that I have granted only ambient light to the ceiling, walls and floor of the room.

‘Do you want to bask in the sun?’ I asked Arkwood, placing the Rift onto his head.

‘Yes, please,’ my sordid Belgian chum replied, ‘The sun will help cook my pig intestines, just in time for supper.’

I opened a window to waft away the stink.

Ciao!

P.S.

Here’s a video of directional light upon those containers:

And here’s directional light upon the ceiling, walls and floor of the room (as well as those containers, which have been scattered about a bit):

Advertisements