Tags

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

I was trying to explain a fragment shader to Arkwood.

‘It is a little program that can run many times in parallel on a GPU. It helps put the pixels into the Oculus Rift virtual reality headset, so you can see pretty virtual rooms.’ Yes, condescending I was.

Arkwood scratched his head. ‘A bit like Hegel then,’ he replied.

What?

‘Hegel,’ he went on, ‘you know, The Phenomenology of Spirit. I was turning a few pages last night, for fun. This fragment shader of yours, it’s like the consciousness of many beings feeding the big beast.’

‘What the fuck are you on about?’ I snapped.

My post OpenGL specular lighting on Oculus Rift demonstrates how OpenGL and the Oculus SDK for Windows can implement a Phong lighting model of ambient, diffuse and specular components.

All well and dandy. But not all objects in my virtual room should react to light in the same way. After all, a steel box will react differently to light than a wooden box. What I need do is set materials for my objects!

The Learn OpenGL Materials article has all the detail. It shows how to adjust a fragment shader to handle materials and light. I cranked open my C++ Microsoft Visual Studio application and got busy.

Here’s my first box with a material shininess of 32:

And here’s the box beside it, with its shininess set to 256:

Splendid. Let’s take things a stage further and turn one of our boxes into gold, using the table linked into the Learn OpenGL article.

As mentioned in the article, we set the light intensities to vec3(1.0f) when using the table.

And here’s our other box turned into yellow rubber:

I told Arkwood the good news. ‘My fragment shader now handles materials!’ the words from my smug face.

‘Your journey to self-certainty has ended,’ he cryptically replied.

Unspeakable, he is.

Ciao!

Advertisements