Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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"!)

share|improve this question

3 Answers 3

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.

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

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.

share|improve this answer
up vote 0 down vote accepted

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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