# Thread: Texture Matrix for Cube Maps

1. ## Texture Matrix for Cube Maps

Hey guys,
I tried to implement Shadow Mapping in my OpenGL Game. For directional light it worked perfectly, but now I need point lights. I have created 6 depth maps and combined them into a cube map. For directional light I needed a texture matrix for the shader. I calculated the texture matrix like that: Bias * LightProjection * LightView * CameraViewInvert. Now my question: Do I need a texture matrix for cube maps (point lights) too? And if yes, how I can calculate it? Because the point light has 6 light view and projection matrices.

Thanks!

2. Sure you need. First, you definitely have to transform your vectors using the CameraViewInvert and your LightView matrix (choose the negative Z face's LightView matrix for the purpose), the tricky part will be applying the projection and bias. I cannot recall by hearth how to do it exactly, but if you do the math you should figure it out.

Btw, you shouldn't use fixed function texturing, it's 2013, use shaders

3. Yes, I have shaders to do the light. But how I can use shaders instead of make the texture matrix?

4. Originally Posted by JojoBoomba
For directional light ... Bias * LightProjection * LightView * CameraViewInvert. ... Do I need a texture matrix for cube maps (point lights) too? And if yes, how I can calculate it? Because the point light has 6 light view and projection matrices.
If you use the same projection for all faces of the cube map (likely) you can get away with only 2 texture matrices: one for LightProjection and one for LightView*... -- with just a little glue math in between to grab the correct depth to compare against for that cube map face. Here's the trick:

Code glsl:
```vec4 position_ls = light_view_matrix * camera_view_matrix_inv * position_cs;
vec4 abs_position = abs(position_ls);
float fs_z = -max(abs_position.x, max(abs_position.y, abs_position.z));
vec4 clip = light_projection_matrix * vec4(0.0, 0.0, fs_z, 1.0);
float depth = (clip.z / clip.w) * 0.5 + 0.5;