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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| const vertexShader = ` uniform float time; varying vec2 vUv; varying vec3 vNormal;
void main() { vUv = uv; vNormal = normal;
// 波浪效果 float wave = sin(uv.y * 15.0 + time * 3.0) * 0.05; vec3 newPosition = position + normal * wave;
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0); } `; const fragmentShader = ` uniform float time; uniform vec3 colorStart; uniform vec3 colorEnd; varying vec2 vUv; varying vec3 vNormal;
void main() { // 渐变颜色 vec3 color = mix(colorStart, colorEnd, vUv.y);
// 添加发光效果 float glow = abs(sin(vUv.y * 10.0 + time * 2.0)) * 0.3; color += glow * vec3(0.5, 0.8, 1.0);
// 网格线效果 float gridSize = 5.0; float gridWidth = 0.3; vec2 gridUv = fract(vUv * gridSize);
// float verticalGrid = step(1.0 - gridWidth, gridUv.x); // 竖线 float horizontalGrid = step(1.0 - gridWidth, gridUv.y); // 横线
// 横向网格线透明 if (horizontalGrid > 0.0) { discard; // 直接丢弃像素,完全透明 }
// 竖向网格线高亮 // if (verticalGrid > 0.0) { // color = mix(color, vec3(1.0, 1.0, 1.0), 0.7); // }
// gl_FragColor = vec4(color, color.r); // gl_FragColor = vec4(color, 0.6 + 0.4 * vUv.y); // 下方0.6,上方1.0 gl_FragColor = vec4(color, 0.3 + 0.3 * vUv.y); // 下方0.3,上方0.6 } `
const material = new THREE.ShaderMaterial({ uniforms: { time: { value: 0 }, colorStart: { value: new THREE.Color(0x0984f7) }, colorEnd: { value: new THREE.Color(0x60b0d6) } }, vertexShader: vertexShader, fragmentShader: fragmentShader, transparent: true, side: THREE.DoubleSide, wireframe: false });
|