|
|
发表于 2008-12-4 23:46:00
|
显示全部楼层
Re:请问在shader里如何获取当前点的深度值?
老显卡就算支持浮点纹理,通常也很慢
可以把深度值编码到普通的rgb32纹理里,
•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);
2.
Out.r = floor(fDepth) / 256.0;
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
详细方法可以看http://http.developer.nvidia.com/GPUGems/gpugems_ch12.html的12.3.3和12.3.6 |
|