youli 发表于 2024-6-7 13:44:41

噪声入门

习惯使用OneNote采用图的方式记笔记,不知道看不看的惯

可以看这个up的视频讲解……或者说笔记就是通过这视频记录的

(https://www.bilibili.com/video/BV1Lr421g7SB/?spm_id_from=333.880.my_history.page.click&vd_source=f92a2f3367b863030638e1aca838fb57)

在笔记中,一维伪随机函数对应一维噪声;二维伪随机函数对应二维噪声

![噪声函数.png](data/attachment/forum/202406/07/133813v4ccisw75m0z0aaz.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/300 "噪声函数.png")

以下是最终的代码:



| floatrandom21(vec2st) {returnfract(sin(dot(st.xy, vec2(12.9898,78.233)))*43758.5453); } floatnoise(vec2 st){ vec2 i = floor(st); vec2 f = fract(st);    floata = random21(i);floatb = random21(i + vec2(1.0,0.0));floatc = random21(i + vec2(0.0,1.0));floatd = random21(i + vec2(1.0,1.0));   vec2 u = f * f * (3.0-2.0* f);returnmix(a, b, u.x) + (c - a) * u.y * (1.0- u.x) + (d - b)* u.x * u.y; } voidmainImage( outvec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 uv = fragCoord/iResolution.xy; uv = uv *2.0-1.0; uv.x *= iResolution.x / iResolution.y;   // show circleconst floatkRadiusBase =0.5; // 基本半径const floatkChangeRateFactor =0.1;//平滑程度因为是噪声图上采样,因此 数值越小越容易连续   const floatkSpeedFactor =1.0;//速度变化参数,采样中心点 偏移的速度.因为是噪声图上采样,中心点位移越块,变化速率越块const floatkRadiusBuffer =0.3;//噪声采样,对半径影响有多大.值越大 形变 范围越大floatdis = distance(uv,vec2(0.0));   vec2 dir = normalize(uv - vec2(0.0));floatnoiseValue = noise(uv + dir * kChangeRateFactor +vec2(iTime) * kSpeedFactor); noiseValue *= kRadiusBuffer;   vec4 red = vec4(1.0,0.0,0.0,1.0); vec4 bgColor = vec4(1.0,0.9,0.1,1.0); fragColor = mix(bgColor, red,step(dis,kRadiusBase + noiseValue)); } |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

碎碎念:嗯……突然发现其他笔记记的都好乱,感觉直接发出来不一定方便学习
页: [1]
查看完整版本: 噪声入门