Jump to content
  • Advertisement
Sign in to follow this  
Butabee

depth map with more than 255 values

This topic is 2851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to create a depth map with more than one channel of values but I'm unsure how to mix the colors to go through up to the full color range.

Share this post


Link to post
Share on other sites
Advertisement
Why not just use a single-channel image with more than 8 bits per channel? Most image software can handle 16 bits/pixel images, and support for HDR (i.e. 32 bit floating point) is becoming pretty common.

Share this post


Link to post
Share on other sites
Do pixel shaders support 16 bit images?

Anyways, while it's not exactly what I was planning, I'm just using 1020 depth values now with a combination of rgba.

Share this post


Link to post
Share on other sites
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.

Rick

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.

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

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

/Tyrian

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!