习惯使用OneNote采用图的方式记笔记,不知道看不看的惯
可以看这个up的视频讲解……或者说笔记就是通过这视频记录的
Shader里说到噪声和扰动,到底是在扰动什么?一个视频用shader做噪声入门_哔哩哔哩_bilibili
在笔记中,一维伪随机函数对应一维噪声;二维伪随机函数对应二维噪声
以下是最终的代码:
floatrandom21(vec2 st) { 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( out vec4 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 circle const 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)); } |
碎碎念:嗯……突然发现其他笔记记的都好乱,感觉直接发出来不一定方便学习 |