|
|
发表于 2008-5-25 00:34:00
|
显示全部楼层
Re:shadowmap怎么才能透射alpha透明贴图?
When we use integer textures, we need to pack the squared distance value and write it into the color channel. How can we pack a floating-point number into an integer texture? Here are two ways:
1.
Out.r = SquaredDistance * 2^0
Out.g = SquaredDistance * 2^8
Out.b = SquaredDistance * 2^16
Out.a = SquaredDistance * 2^24
float4 vPack = {1.0f, 256.0f, 65536.0, 16777216.0f};
return vPack * dot(vLight, vLight);Out.r = floor(fDepth) / 256.0;
2.
Out.g = frac(fDepth);
float fDepth = dot(vLight, vLight);
return float(floor(fDepth) / 256.0, frac(fDepth),frac(fDepth), frac(fDepth));
By writing frac(fDepth) into the green and alpha channels, we save this pixel shader instruction (otherwise, we need an additional instruction to fill these channels):
mov r2.gba, r0.g // r0.g contains frac(fDepth)
Method 1 is computationally cheaper, but the second one gives you higher precision.
---gpu gems chapter 12
http://http.developer.nvidia.com/GPUGems/gpugems_ch12.html |
|