!!ARBfp1.0 # computes 3D noise based on 2D texture containing # 2D noise in red and z gradient in green ATTRIB frame = fragment.texcoord[0]; ATTRIB noiseInput = fragment.texcoord[1]; # base for blum blum shub should be product of two primes # but I couldn't find any product that looked good and didn't # result in huge texture sizes. 61 is a single prime that seemed # to produce reasonably good results PARAM base = {61., 0.0163934}; # base, 1/base # integer and fractional components of input Z TEMP intArg, fracArg; FLR intArg.x, noiseInput.z; FRC fracArg.x,noiseInput.z; # compute fade values from fractional location in grid cell # fade(t) = t*t*t*(t*(6*t-15)+10) TEMP fade; MAD fade.x,fracArg,-2,3; # old fade function t*t*(-2*t+3) MUL fade.x,fade,fracArg; MUL fade.x,fade,fracArg; # hash will hold values for z and z+1 TEMP hash, htmp; # compute z & z+1 terms and run through hash function # I scaled by a number relatively prime to base to bootstrap it into # the more interesting part of the hash function a better choice may # have been to just apply the hash multiple times. Note that # this is JUST for hash purposes, it does not scale the frequency of # the noise MAD hash.xy,intArg.x,3,{0,3}; # 3*{z,z+1} MUL htmp.xy,hash,base.y; # mod base FLR htmp.xy,htmp; MAD hash.xy,htmp,-base.x,hash; MUL hash.xy,hash,hash; # squared MUL hash.xy,hash,base.y; # cheap mod w/ 0..1 result FRC hash.xy,hash; # compute slice texture coordinates tex.xy and tex.xz TEMP t0,t1; MOV t0.x,noiseInput.x; MOV t1.x,noiseInput.x; ADD t0.y,noiseInput.y,hash.x; ADD t1.y,noiseInput.y,hash.y; # look up slices, scaled to -1,1 TEMP n0, n1, noise; TEX n0.xy,t0,texture[0],2D; TEX n1.xy,t1,texture[0],2D; MAD noise.xy,n0,2,-1; MAD noise.zw,n1.xyxy,2,-1; # additional z-gradient terms TEMP grad; ADD grad.xy,fracArg.x,{0,-1}; MUL noise.yw,noise,grad.xxyy; # blend z-slices into final 3D noise ADD noise.xy,noise.zxzx,noise.wywy; LRP noise.x,fade.x,noise.x,noise.y; # combine with diffuse lighting MAD noise.x,noise.x,.5,.5; MUL result.color,noise.x,fragment.color; END