three打造的走光效果

代码语言:html

所属分类:三维

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<title> Carpe Noctem</title>
<style>
      body {
  margin: 0;
  padding: 0;
}

#container {
  position: fixed;
  touch-action: none;
}

    </style>

</head>
<body translate="no">
<script src="http://repo.bfw.wiki/bfwrepo/js/three.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
    void main() {
        gl_Position = vec4( position, 1.0 );
    }
</script>

<script id="fragmentShader" type="x-shader/x-fragment">
  
  uniform vec2 u_resolution;
  uniform vec2 u_mouse;
  uniform float u_time;
  uniform sampler2D u_noise;
  uniform bool u_mousemoved;

  const bool shapeTest = false; // Whether to just show the shape test
  const bool addNoise = true; // Whether to add noise to the rays
  const float decay = .98; // the amount to decay each sample by
  const float exposure = .2; // the screen exposure
  const vec3 lightcolour = vec3(.5); // the colour of the light
  const vec3 falloffcolour = vec3(1.0, 1.0, 1.3); // the colour of the falloff
  const vec3 bgcolour = vec3(.05, 0.1, .1); // the base colour of the render
  const float falloff = .5;
  const int samples = 16; // The number of samples to take
  const float density = .95; // The density of the "smoke"
  const float weight = .25; // how heavily to apply each step of the supersample
  const int octaves = 1; // the number of octaves to generate in the FBM noise
  const float seed = 43758.5453123; // A random seed :)
  
  #define PI 3.141592653589793
  #define TAU 6.283185307179586
  
  float starSDF(vec2 st, int V, float s) {
      // st = st*4.-2.;
      float a = atan(st.y, st.x)/TAU;
      float seg = a * float(V);
      a = ((floor(seg) + 0.5)/float(V) + 
          mix(s,-s,step(.5,fract(seg)))) 
          * TAU;
      return abs(dot(vec2(cos(a),sin(a)),
                     st));
  }
  
  float random2d(vec2 uv) {
    uv /= 256.;
    vec4 tex = texture2D(u_noise, uv, 0.);
    return mix(tex.x, tex.y, tex.a);
  }
  vec2 random2(vec2 st, float seed){
      st = vec2( dot(st,vec2(127.1,311.7)),
                dot(st,vec2(269.5,183.3)) );
      return -1.0 + 2.0*fract(sin(st)*seed);
  }
  
  // Value Noise by Inigo Quilez - iq/2013
  // https://www.shadertoy.com/view/lsf3WH
  float noise(vec2 st, float seed) {
    vec3 x = vec3(st, 1.);
    vec3 p = floor(x);
    vec3 f = fract(x);
    f = f*f*(3.0-2.0*f);
    vec2 uv = (p.xy+vec2(37.0,17.0)*p.z) + f.xy;
    vec2 rg = texture2D(u_noise, (uv+0.5) / 256., 0.).yx - .5;
    return mix( rg.x, rg.y, f.z );
  }
  
  float fbm1(in vec2 _st, float seed) {
    float v = 0.0;
    float a = 0.5;
    vec2 shift = vec2(100.0);
    // 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 < octaves; ++i) {
        v += a * noise(_st, seed);
        _st = rot * _st * 2.0 + shift;
        a *= 0.4;
    }
    return v + .4;
  }
  // Card 4
  float stroke(float x, float s, float w) {
    float d = step(s, x+w*.5) - step(s, x-w*.5);
    return clamp(d, 0., 1.);
  }
  float circle(vec2 uv) {
    return length(uv-.5)*2.;
  }
  float star(vec2 uv, int V, float s) {
    float v = float(V);
    uv = uv * 4. - 2.;
    float a = atan(uv.y, uv.x)/TAU;
    float seg = a * v;
    a = (
          (floor(seg) + .5)/v +
          mix(s, -s, step(.5, fract(seg)))
        ) * TAU;
    return abs( dot( vec2(cos(a), sin(a)), uv ) );
  }
  
  float pattern(vec2 uv, float seed, float time, inout vec2 q, inout vec2 r) {

    q = vec2( fbm1( uv + vec2(0.0,0.0), seed ),
                   fbm1( uv + vec.........完整代码请登录后点击上方下载按钮下载查看

网友评论0