Sign in to follow this  

depth map with more than 255 values

Recommended Posts

You could use a 16 or 32 bit render target. See "Render Target" or FBO(OpenGL) tutorials. When you create a texture, you can usually tell which format it is (rgba 8 bit, RGBA16, RGBA32, etcetera). RGBA16 means that each color channel has 16 bits of data (thus in total 4 x 16 = 64 bit).

If you don't have that option due limited hardware, you can also encode the depth value over the multiple color channels. Most shader languages have pack/unpack functions to get the individual bytes out of a value:

byte b[3] = unpack_4byte( depthFloatValue ); // split a 32 bit float up in 4 bytes
out.color.r = b[0];
out.color.g = b[1];
out.color.b = b[2];
out.color.a = b[3];
/// When reading the depth texture again in another shader:
byte4 depthPixel = tex2D( depthMap, texcoords );
float depthValue = pack_4byte( depthPixel.xyzw );

Packing and unpacking is slower of course, so first check if you can simply use a texture with more bits per channel.

A third option is not to render to a texture, but to a depth buffer (24 or 32 bit) directly. When rendering to a texture, you usually bind a depthMap and a texture. But it is also possible to render to a depthMap only.


Share this post

Link to post
Share on other sites
Or you could stick to 8 bit colour channels and pack the float into, say, two channels. These functions work for me (I think I got them from a post on GameDev so thanks to the author whoever it was!)

// Pack / unpack a float into two 8 bit channels
float2 F32_Compress(float f)
float u,v;
float res_u;
u = floor(f*256.0);
res_u = f*256.0 - u;
v = floor(res_u * 256.0);
return (1/256.0*float2(u,v));

float F32_Decompress(float2 vec)
return (vec.x+vec.y*1.0/256.0);

Share this post

Link to post
Share on other sites
hmm.. if you wish to use 8bit hegthmap, then there is option of using detail height maps. Basicaly you offset heght maps value by another texture, but offsets scale is much smaller.

heightmap 256 == 2560m (height resolution 10m)
detailmap 256 == 10m (height resolution 0.04m)

If tilling is problem, use multible octaves of detail texture.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this