three打造一个魔幻水晶体内魔法气体动画效果代码

代码语言:html

所属分类:三维

代码描述:three打造一个魔幻水晶体内魔法气体动画效果代码

代码标签: 魔幻 水晶 体内 魔法 气体 动画 效果

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

<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
  
  
  
<style>
* {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    #world {
      position: relative;
      width: 100%;
      height: 100vh;
    }
</style>


</head>

<body translate="no" >
  <div id="world"></div>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.r118.js"></script>
  
      <script  type="module">
import { EffectComposer } from "https://unpkg.com/three@0.120.0/examples/jsm/postprocessing/EffectComposer.js";
import { RenderPass } from "https://unpkg.com/three@0.120.0/examples/jsm/postprocessing/RenderPass.js";
import { UnrealBloomPass } from "https://unpkg.com/three@0.120.0/examples/jsm/postprocessing/UnrealBloomPass.js";
import { OrbitControls } from "https://unpkg.com/three@0.120.0/examples/jsm/controls/OrbitControls";


var options = {
  exposure: 2.8,
  bloomStrength: 1.9,
  bloomThreshold: 0,
  bloomRadius: 0.55,
  color0: [74, 30, 0],
  color1: [201, 158, 72] };

// var gui = new dat.GUI();

// var bloom = gui.addFolder("Bloom");
// // bloom.add(options, "exposure", 0.0, 5.0).name("exposure").listen();
// bloom.add(options, "bloomStrength", 0.0, 5.0).name("bloomStrength").listen();
// // bloom.add(options, "bloomThreshold", 0.0, 1.0).name("bloomThreshold").listen();
// bloom.add(options, "bloomRadius", 0.1, 2.0).name("bloomRadius").listen();
// bloom.open();

// var color = gui.addFolder("Colors");
// color.addColor(options, "color0").name("Border");
// color.addColor(options, "color1").name("Base");
// color.open();

const vert = `
      varying vec3 vNormal;
      varying vec3 camPos;
      varying vec3 vPosition;
      varying vec2 vUv;
      varying vec3 eyeVector;
      attribute vec3 center;
      varying vec3 vCenter;

      
      void main() {
        vNormal = normal;
        vCenter = center;
        camPos = cameraPosition;
        vPosition = position;
        vUv= uv;
        vec4 worldPosition = modelViewMatrix * vec4( position, 1.0);
        eyeVector = normalize(worldPosition.xyz - cameraPosition);
        gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
      }

`;

const frag = `

      #ifdef GL_ES
      precision lowp float;
      #endif

      #define NUM_OCTAVES 5
      uniform vec4 resolution;
      uniform vec3 color1;
      uniform vec3 color0;
      uniform float utime;
      uniform sampler2D colorRamp;
      uniform sampler2D noiseTex;
      varying vec3 camPos;
      varying vec3 vNormal;
      varying vec3 vPosition;
      varying vec2 vUv;
      varying vec3 eyeVector;
      varying vec3 vCenter; 

      float rand(vec2 n) {
        return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
      }

      float noise(vec2 p){
        vec2 ip = floor(p);
        vec2 u = fract(p);
        u = u*u*(3.0-2.0*u);

        float res = mix(
          mix(rand(ip),rand(ip+vec2(1.0,0.0)),u.x),
          mix(rand(ip+vec2(0.0,1.0)),rand(ip+vec2(1.0,1.0)),u.x),u.y);
        return res*res;
      }

      float fbm(vec2 x) {
        float v = 0.0;
        float a = 0.5;
        vec2 shift = vec2(100);
        // Rotate to reduce axial bias
          mat2 rot = mat2(cos(0.5), sin(0.5), -sin(0.5), cos(0.50));
        for (int i = 0; i < NUM_OCTAVES; ++i) {
          v += a * noise(x);
          x = rot * x * 2.0 + shift;
          a *= 0.5;
        }
        return v;
      }

      vec3 rgbcol(float r, float g, float b) {
        return vec3(r/255.0,g/255.0,b/255.0);
      }

      float setOpacity(float r, float g, float b) {
        float tone = (r + g + b) / 3.0;
        float alpha = 1.0;
        if(tone<0.99) {
          alpha = 0.0;
        }
        return alpha;
      }

      float Fresnel(vec3 eyeVector, vec3 worldNormal) {
        return pow( 1.0 + dot( eyeVector, worldNormal), 3.0 );
      }


      float getTone(vec3 color){
        float tone = (color.r + color.g + color.b) / 3.0;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0