Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Texture Matrix for Cube Maps

  1. #1
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2

    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. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    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
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2
    Yes, I have shaders to do the light. But how I can use shaders instead of make the texture matrix?

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,208
    Quote Originally Posted by JojoBoomba View Post
    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;
    vec4 result = shadowCube(shadow, vec4(position_ls.xyz, depth));

    You can find this code in a complete working test program on this in this OpenGL.org forum thread post by deadc0de.
    Last edited by Dark Photon; 01-08-2013 at 06:18 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •