• Three.js柏林噪音 流动球体


    代码:https://gitee.com/honbingitee/three-template-next.js/tree/shader/
    参考油管视频:https://www.youtube.com/watch?v=oKbCaj1J6EI
    核心: 创建循环的图形 应用噪声 顶点按照法相偏移

    在这里插入图片描述

    在这里插入图片描述

    
        CustomMaterial(): ShaderMaterial {
            const material = new ShaderMaterial({
                side: DoubleSide,
                uniforms: {
                    iTime: { value: 1 },
                },
                vertexShader: `
                uniform float iTime;
                varying vec3 vNormal;
                varying vec3 vColor;
                #define PI 3.141592653589793
                ${perlinNoiseFragment}
                ${smoothModFragment}
                ${fitFragment}
                void main() {
                    vec3 transformed = position;
                    vNormal = normal;
                    //vec3 myNormal = normal * 3. ; 
                    vec3 myNormal = normal ;
                    myNormal.y += iTime;
                    float noiseValue = noise(myNormal) ;
                    float pattern = fit(smoothMod(noiseValue * 5.,1.0,1.5),0.4,0.6,0.,1.);
                    transformed += vec3(pattern) * normal;
                    vColor = vec3(pattern);
                    vec4 modelViewPosition = modelViewMatrix * vec4(transformed, 1.0);
                    gl_Position = projectionMatrix * modelViewPosition;
                }`,
                fragmentShader: `
                varying vec3 vNormal;
                varying vec3 vColor;
                void main() {
                    vec3 color = vec3(vColor);
                    gl_FragColor = vec4(color, 1.0);
                }`,
            });
    
            return material;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    替换MeshStandardMaterial

     ReplaceMaterial(): MeshStandardMaterial {
            const material = new MeshStandardMaterial({
                color: "#aaa",
                emissive: "#ff3311",
                metalness: 0.5,
                roughness: 0.5,
            });
            
            material.onBeforeCompile = (shader) => {
                Object.assign(shader.uniforms, this.appendUniforms);
                shader.vertexShader = shader.vertexShader.replace(
                    "#include ",
                    `
                    #include 
                    uniform float iTime;
                    uniform float iStepCount;
                    #define PI 3.141592653589793
                    ${perlinNoiseFragment}
                    ${smoothModFragment}
                    ${fitFragment}
                `
                );
                shader.vertexShader = shader.vertexShader.replace(
                    "#include ",
                    `
                    #include 
                    vec3 myNormal = normal;
                    myNormal.y += iTime;
                    float noiseValue = noise(myNormal);
                    float pattern = fit(smoothMod(noiseValue * iStepCount,1.0,1.5),0.4,0.6,0.,1.);
                    transformed += vec3(pattern) * normal;
                `
                );
            };
    
            return material;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
  • 相关阅读:
    飞桨部署到地平线
    springboot毕设项目大学生请假系统 fq91k(java+VUE+Mybatis+Maven+Mysql)
    《计算机视觉40例》内容简介
    Docker的那些事
    创建 gstreamer 插件的几种方式
    Appium和Android常用9种自动化测试框架对比有哪些优势?
    11-DMA控制器
    java定义一个方法sum(),求1—n中所有能够被2或者3整除的数字之和,n由键盘输入。
    使用sipParseArgs/sipBuildResult进行python/C++对象的转换
    忘记MySQL密码如何重置再到重新设置密码
  • 原文地址:https://blog.csdn.net/printf_hello/article/details/133882982