开发者

Bit-wise alternative

I'm trying to write a shader that needs pseudo-random number generation per pixel - fetching from a texture is just too expensive.

All of the generators I've found use ^, <<, & operators, but the shader model I'm working on doesn't support these. Is there a mathematical equivalent of these operators I can use instead?

For ref开发者_C百科erence, I'm valuing speed over precision.

Thanks!


Of those, the only one I know the mathematical equivalent to is the << operator. Namely:

N << X = N * (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc)

e.g.

N << 5 = N * 32

Simply create a lookup for the value (2 ^ X), and multiply by that value.

The others are going to be more complicated, and will probably require that you write an algorithm to solve them. I don't think they have any direct mathematical equivalents.

The source code for a C runtime implementation might be useful for that. Or simply search for algorithms to implement each, such as: Fast implementation/approximation of pow() function in C/C++

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜