HLSL 伪随机数生成器

1649 篇文章 11 订阅
1623 篇文章 22 订阅

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:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值