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 want to map out a 2D array of depth elements for the fragment shader to use to check depth against to create shadows. I want to be able to copy a float array into the GPU, but using large uniform arrays causes segfaults in openGL so that is not an option. I tried texturing but the best i got was to use GL_DEPTH_COMPONENT

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 512, 512, 0, GL_DEPTH_COMPONENT, GL_FLOAT, smap);

Which doesn't work because that stores depth components (0.0 - 1.0) which I don't want because I have no idea how to calculate them using the depth value produced by the light sources MVP matrix multiplied by the coordinate of each vertex.

Is there any way to store and access large 2D arrays of floats in openGL?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

To pass big amounts of data for random access using textures is the correct way. Setting large amounts of uniforms is very slow and you only have a very limited amout of constant registers on most hardware.

You can use GL_R32F or GL_DEPTH_COMPONENT32F as a texture format, which has to be supported by your target hardware, to store a single single precision floating point value per sample.

A shadow map texture is normally done using a normalized depth between the near and far planes of your shadow light, eg by using the depth value after projective divide. This gives you are higher precision, fixed point textures are often more efficient than floating point textuers and are supported by a wider range of hardware.

share|improve this answer
    
If I had the rep I'd upvote, that was a very detailed answer thanks! I managed to fix it to work with openGL depths now, so I'm using that! Thanks! –  James Dec 8 '12 at 19:16
add comment

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.