3D引擎,图形开发,C++

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

packing a float into a A8R8G8B8 texture (shader)

encode (fDist is the normalized distance):
	const float4 bitSh	= float4(   256*256*256, 256*256,   256,         1);
const float4 bitMsk = float4( 0, 1.0/256.0, 1.0/256.0, 1.0/256.0);

float4 comp;
comp = fDist * bitSh;
comp = frac(comp);
comp -= comp.xxyz * bitMsk;
return comp;


decode (vec is the rgba encoded value):
	const float4 bitShifts = float4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1);
return dot(vec.xyzw , bitShifts);
posted on 2007-06-21 15:34  灵隐西湖  阅读(362)  评论(0)    收藏  举报