我是靠谱客的博主 留胡子白昼,最近开发中收集的这篇文章主要介绍HLSL Tips 2:伪随机数生成器,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Preface
PRNG on the GPU. Two pseudo random numbers per iteration (from the BA channels). Inspired by Pete Warden's fragment program for pseudo-random number generation. In turn based on an algorithm described by Francois Grieu, sci.crypt, 5th February 2004. Implementd in Cg by Alex Campbell. 7th August 2006. Thanks for their works. I implement it in HLSL now.

Function
#define cMult 0.0001002707309736288
#define aSubtract 0.2727272727272727
float4 randGrieu(float4 t)
{
float a=t.x+t.z*cMult+aSubtract-floor(t.x);
a*=a;
float b=t.y+a;
b-=floor(b);
float c=t.z+b;
c-=floor(c);
float d=c;
a+=c*cMult+aSubtract-floor(a);
a*=a;
b+=a;
b-=floor(b);
c+=b;
c-=floor(c);
return float4(a,b,c,d);
}

Application
Code snippet:
float4 color=tex2D(TextureSampler, In.TexCoord0);
color=randGrieu(color);
Out.color=color;

The original texture is as follows:

 

After called randGrieu() once, the result texture is:

 RandTexture2.jpg

转载于:https://www.cnblogs.com/skyman/archive/2007/07/05/hlsltips2.html

最后

以上就是留胡子白昼为你收集整理的HLSL Tips 2:伪随机数生成器的全部内容,希望文章能够帮你解决HLSL Tips 2:伪随机数生成器所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部