-1

I am currently working on a project where I have to texture a cube using the reflection vector between the normal of a fragment and the camera.

I have the sampler2D picture, and I somehow have to implement it to a cube using reflection.

The question is: Can someone explain how this process goes. That would help me finish my project and further understand the process behind texturing.

The thing is that I can't use textureCube(), but texture2D(), so that the fragment shader is applicable to not only cubes but to every surface.

Thank you in advance for the answer!

ficabj5
  • 111
  • 10
  • "*I somehow have to implement it to a cube using reflection.*" How can we know how you want to do that? There are many ways to "use reflection" to map a texture onto a surface. – Nicol Bolas Dec 03 '16 at 20:00
  • Can you explain at least one? – ficabj5 Dec 03 '16 at 22:05
  • Well you dont want to use `textureCube` so no cube maps, that leaves only a custom mapping that *you* have to choose depending on *your* requirements. – LJᛃ Dec 04 '16 at 02:18
  • I am sorry, I have not used the terminology properly. I have to implement cube mapping with texture2D(). I just don't have an idea on how to map the reflected vector to the 2D image (texture). – ficabj5 Dec 04 '16 at 19:19

1 Answers1

0

The thing is that I can't use textureCube(), but texture2D(), so that the fragment shader is applicable to not only cubes but to every surface.

Why do you have to do this? Implementing this yourself with texture2D (...) is going to involve multiple texture lookups. textureCube (...) will leave the implementation details hidden and can even seamlessly filter stuff on supported hardware.

In all cases, the fact that it is called a cubemap means nothing about the surface you are mapping it onto, it is actually the texture itself that is a cube (six 2D textures define all of the cube faces).

When you sample a cubemap, you are shooting a ray through this virtual cube and the color or depth returned is where that ray intersects it. The sampled value will come from at least one of the six cube faces, possibly multiple cube faces depending on the texture filter setup.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106