GLSL で float <-> RGBA8 変換する例
- http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
- http://www.ozone3d.net/blogs/lab/20080604/glsl-float-to-rgba8-encoder/
- http://http.developer.nvidia.com/GPUGems/gpugems_ch12.html
- http://smt565.blogspot.jp/2011/04/bit-packing-depth-and-normals.html
- http://stackoverflow.com/questions/18453302/how-do-you-pack-one-32bit-int-into-4-8bit-ints-in-glsl-webgl
- http://http.developer.nvidia.com/GPUGems/gpugems_ch12.html
R8 フォーマットに整数を読み書きする場合 ////////////////////////////////////////////////// // // // 書き込み // ////////////////////////////////////////////////// uint i_value = 37; // 最大値は 255 float f_value = ( 37 / 255.0 ); // 0.0-1.0 の範囲に収める gl_FragColor.r = f_value; ////////////////////////////////////////////////// // // 読み込み // ////////////////////////////////////////////////// float f_value = texture( MY_TEXTURE, uv ).r; // uint の値は 37 uint i_value = f_value * 255.0;