three模拟逼真可调参数的黑洞运行三维动画代码

代码语言:html

所属分类:三维

代码描述:three模拟逼真可调参数的黑洞运行三维动画代码

代码标签: three 模拟 逼真 参数 黑洞 运行 三维 动画 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <style>
        body { margin: 0; padding: 0; overflow: hidden; background-color: #000; }
        #canvas-container { width: 100vw; height: 100vh; display: block; }
        #loader {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: #000; display: flex; justify-content: center; align-items: center;
            color: white; font-family: monospace; letter-spacing: 0.5em; z-index: 9999;
            transition: opacity 1s ease-out; pointer-events: none;
        }
    </style>
    <!-- Import Maps for Three.js and lil-gui -->
    <script type="importmap">
        {
            "imports": {
                "three": "https://unpkg.com/three@0.160.0/build/three.module.js",
                "three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/",
                "lil-gui": "https://unpkg.com/lil-gui@0.19.1/dist/lil-gui.esm.min.js"
            }
        }
    </script>
</head>
<body>

<div id="loader">INITIALIZING SINGULARITY...</div>
<div id="canvas-container"></div>

<script type="module">
    import * as THREE from 'three';
    import GUI from 'lil-gui';

    // --- SHADERS ---
    // 1. Vertex Shader (Standard Passthrough)
    const vertexShader = `
        varying vec2 vUv;
        void main() {
            vUv = uv;
            gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
        }
    `;

    // 2. Main Black Hole Shader (Interstellar Logic)
    const fragmentShaderMain = `
        uniform vec3 iResolution;
        uniform float iTime;
        uniform float uIterations;
        uniform vec3 uMainColor;
        uniform float uDiscRadius;
        uniform float uDiscWidth;
        uniform float uDiscThickness;
        uniform float uPCurveA;
        uniform float uPCurveB;
        uniform float uWarpAmount;
        uniform float uSpeed;
        uniform float uZoom;
        uniform vec2 uCameraRotation;
        uniform float uIsMoving;
        uniform float uEventHorizonRadius;
        uniform float uPhotonRingIntensity;
        uniform vec3 uPhotonRingColor;
        uniform float uViewportAspect;
        uniform float uDopplerStrength;
        uniform float uSelfShadowing;
        uniform float uAmbient;
        uniform float uBgSpeed;
        uniform float uBgBrightness;
        uniform float uBgDarkMatter;
        uniform float uBgDistFading;
        uniform float uBgSaturation;
        uniform vec3 uBgColor;
        uniform float uShadowSoftness;
        uniform float uShadowIntensity;
        uniform float uStarTwinkleSpeed;
        uniform float uStarVariation;
        uniform float uShootingStars;
        uniform float uNoiseScale;
        uniform float uNoiseSpeed;
        uniform float uTurbulence;
        uniform float uEmissionIntensity;
        uniform float uGlowSharpness;
        
        uniform sampler2D iChannel0; // noise
        uniform sampler2D iChannel1; // dust
        uniform sampler2D iChannel2; // TAA feedback (previous frame)
        
        varying vec2 vUv;
        
        const float pi = 3.14159265;
        
        float saturate(float x) { return clamp(x, 0.0, 1.0); }
        float rand(vec2 coord) { return saturate(fract(sin(dot(coord, vec2(12.9898, 78.223))) * 43758.5453)); }
        float pcurve(float x, float a, float b) {
            float k = pow(a + b, a + b) / (pow(a, a) * pow(b, b));
            return k * pow(x, a) * pow(1.0 - x, b);
        }
        float sdTorus(vec3 p, vec2 t) {
            vec2 q = vec2(length(p.xz) - t.x, p.y);
            retur.........完整代码请登录后点击上方下载按钮下载查看

网友评论0