16-24-32-bit Shader

Share your ZGE-development tips and techniques here!

Moderator: Moderators

Post Reply
User avatar
Posts: 1721
Joined: Sat Feb 23, 2008 11:15 pm

16-24-32-bit Shader

Post by Kjell » Thu Feb 25, 2010 2:20 pm


Handy fragment shader "trick" splitting / storing results exceeding 8-bits in multiple 8-bit color channels ( when rendering to a signed 32-bit RGBA RenderTarget ). Example illustrates the concept of storing a 16-bit depth map in 2 channels.

Code: Select all

void main()
  int depth = gl_FragCoord.w*65536;

  int byte1 = depth/256;
  int byte2 = depth-byte1*256;

  gl_FragColor = vec4(byte1/256.0,byte2/256.0,0.0,1.0);
In the case of a depth map ..

8-bit : Way too little
16-bit : Usually sufficient
24-bit : More then enough
32-bit : Overkill


Post Reply