1
\$\begingroup\$

I'm looking for suggestions on this

Say you have a cube map. You want to rotate it as efficiently as possible.

You can render the cube map, rotate the camera, and render the scene to another cube map.

But it would be faster to rotate the cubemap by operating on the texels.

I'm using D3D11, and I need to read the texels in the code (so I can't use the OpenGL "Texture Matrix"!)

\$\endgroup\$
2
\$\begingroup\$

You can use "texture matrix" also in shaders (D3D or OpenGL - doesn't matter).

Pass float4x4 as uniform to your shader, and multiply it with texture coordinate before fetching texel.

\$\endgroup\$
  • \$\begingroup\$ Ok. But I need to be able to fetch the texels @ CPU. \$\endgroup\$ – bobobobo Jan 19 '12 at 16:30
  • \$\begingroup\$ So? Reading memory on CPU is easy - buffer[index]. Just calculate index correctly. \$\endgroup\$ – Mārtiņš Možeiko Jan 19 '12 at 16:37
0
\$\begingroup\$

If I understand correctly, you have a cubemap and want to generate another cubemap that is a rotated version of the first one, and you have the capability of capturing a cubemap from an in-game scene (by rendering six times with cameras set to match the cube faces, or whatever).

It seems this should be easy to do by setting up a temporary scene that consists of a cube around the camera, with the original cubemap applied onto it; then rotate the cube and use the camera to capture the new cubemap.

\$\endgroup\$
0
\$\begingroup\$

I did it by the following. Create a new cubemap called rotated. To get the color at each texel in rotated, just get the color from the original cubemap that will land there after rotation.

So, for each texel in the rotated cube map, find the vector u from the center of the cubemap towards that texel.

"Unrotate" u by multiplying by the inverse (which is just the transpose) of the rotation matrix to get v. Find the texel that v corresponds to, and grab the color from the original cubemap, and write that value into rotated.

enter image description here

You will get better results by interpolating between the few pixels that v kinda points to (it will almost never point to the dead center of a pixel).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.