(学习记录)value noise

float value_noise (float2 xy) 
        {
            float g = 0.0; 
            float2 uv = xy * 8.0;
            float2x2 m = float2x2( 1.6,  1.2, -1.2,  1.6 );

            for(int k = 1;k < 5; k++)
            {
                float2 i = floor(uv);
                float2 f = frac(uv);
                float2 a1 = 50.0*frac((i + float2(0.0, 0.0))*0.3183099 + float2(0.71,0.113)); 
                float a = -1.0+2.0*frac(a1.x*a1.y*(a1.x+a1.y));
                float2 b1 = 50.0*frac((i + float2(1.0, 0.0))*0.3183099 + float2(0.71,0.113)); 
                float b = -1.0+2.0*frac(b1.x*b1.y*(b1.x+b1.y));
                float2 c1 = 50.0*frac((i + float2(0.0, 1.0))*0.3183099 + float2(0.71,0.113)); 
                float c = -1.0+2.0*frac(c1.x*c1.y*(c1.x+c1.y));
                float2 d1 = 50.0*frac((i + float2(1.0, 1.0))*0.3183099 + float2(0.71,0.113)); 
                float d = -1.0+2.0*frac(d1.x*d1.y*(d1.x+d1.y));
                float2 u = f*f*(3.0-2.0*f);         // u = smoothstep(0.,1.,f)
                float e = mix(mix(a,b,u.x),mix(c,d,u.x),u.y);
                g += pow(0.5, k)*e;
                uv = mul(m,uv);
            }
            g = 0.5 + 0.5*g;
            g *= smoothstep( 0.0, 0.005, abs(xy.x) );
            return g;
        }

Noise - value - 2D (shadertoy.com)的函数进行了一个整合,只需要把UV输入就可以直接获得value noise

posted @ 2022-04-09 14:40  terrificia  阅读(32)  评论(0编辑  收藏  举报