LoginSignup
4
2

More than 5 years have passed since last update.

隕石の衝突デモをGLSLに投稿してみたw

Last updated at Posted at 2016-12-18

Web3Dもくもく会(WebGL,WebVR,Unityなどなど)で、GLSLでレイマーチングのデモを書いたので、投稿してみる。

投稿先、GLSLSoundBoxに投稿しましたw

ソースの説明

隕石の衝突(球体の関数)

float sphere(vec3 p){
    return length(p - vec3(1.0 - 1.0 * time, 6.0 - 6.0 * time, 3.0 - 3.0 * time)) - 1.0;
}

座標(1.0,6.0,3.0)から等速直線運動で書いている。

衝突後の盛り上が方

float g = 2.0 * sin(useTime) * exp(-(p.x * p.x)/(30.0*sin(useTime*0.1)) -(p.z * p.z)/(30.0*sin(useTime*0.1)));

ガウス関数を使用

地表のデコボコのつけ方。

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

float noise(vec2 p){
    vec2 v = floor(p);
    vec2 u = fract(p);
    u = u * u * (3.0 - 2.0 * u);
    float r = mix(
        mix(rnd(v), rnd(v + vec2(1.0, 0.0)), u.x),
        mix(rnd(v + vec2(0.0, 1.0)), rnd(v + vec2(1.0, 1.0)), u.x),
        u.y
    );
    return r * r;
}

float snoise(vec2 p){
    float n = 0.0;
    for(float i = 0.0; i < 4.0; ++i){
        float v = pow(2.0, 2.0 + i);
        float w = pow(2.0, -1.0 - i);
        n += noise(p * v) * w;
    }
    return n;
}

で、ノイズをつける。
参考:[連載 GLSL 物語] チカラが欲しいか……(最終話)

inseki.PNG

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2