Tags

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

A man went to the Doctor’s and said, “Doctor, Doctor, I feel like a pair of curtains” and the Doctor said, “Pull yourself together, man!”

Arkwood thrust a finger to the ether, enthusiasm bursting out of his face. I’ve got one! I’ve got one! A man went to the Doctor’s and said, “Doctor, Doctor, I feel like a kettle” and the Doctor said, “Pour yourself together!”

I grimaced. ‘Yeah, not really the same thing, Arkwood. What does “pour yourself together” even mean?’

Arkwood looked sadly to the floor. Never mind, I told him, put on this Oculus Rift virtual reality headset. I have updated my C++ Microsoft Visual Studio application (with the Oculus SDK for Windows) to incorporate OpenGL environment mapping. The mountains and lake of my skybox are now reflected in the steel borders of my wooden containers.

Here’s Arkwood exploring said reflections.

But how do we ensure that the mountains et al are only reflected in the steel borders and not the wood itself? Answer: we use a reflection map.

Here’s the code in the fragment shader to handle reflections:

"vec3 I = normalize(FragPos - viewPos);\n"
"vec3 R = reflect(I, normalize(oNormal));\n"
"vec3 refl = vec3(texture(skybox, R).rgb) * vec3(texture(material.specular, oTexCoord));\n"
"FragColor = vec4(result + refl, 1.0);\n"

We do a similar calculation to my previous post, OpenGL environment mapping: reflection. Difference here is that rather than reflect the environment on the whole cube, only the parts of the reflection map that are bright will carry a reflection.

I’m kind of cheating a bit and using the existing specular map as my reflection map, as it already has the steel borders as grey to white pixels and the wood as black.

Arkwood was smiling again. Once more he thrust an index finger into the air. A man went to the Doctor’s and said, “Doctor, Doctor, I feel like a pair of curtains” and the Doctor said, “You are only as old as the curtains you feel!”

I walked Arkwood through the hallway to my front door. I opened my front door and gently pushed Arkwood outside. I shut and locked my front door. And pulled the curtains, Doctor, so I did not need to witness his pathetic wretched soul being drenched by the torrent of rain.

Ciao!

Advertisements