Skip to content

Instantly share code, notes, and snippets.

@shutosg
Last active March 4, 2017 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shutosg/921a8a75f796725f337fe45537e1322b to your computer and use it in GitHub Desktop.
Save shutosg/921a8a75f796725f337fe45537e1322b to your computer and use it in GitHub Desktop.
glslスニペット
// 距離に応じたフォグ
// rLenがカメラと衝突点との距離
float fogCoef = 0.03;
float fogAmount = 1.0 - exp(-rLen * fogCoef);
vec3 fogColor = vec3(0.9, 0.6, 0.7);
gl_FragColor = vec4(mix(color, fogColor, fogAmount), 1.0);
// 無限に続く柱
// 11行目のabs(p.y)をp.yに変えればy<0方向にも伸びる
vec3 repeat(vec3 p, float interval){
float x = mod(p.x, interval) - interval * 0.5;
float y = p.y;
float z = mod(p.z, interval) - interval * 0.5;
return vec3(x, y, z);
}
float distBox(vec3 p, float interval, float width){
vec3 q = abs(repeat(p, interval)) - vec3(width, abs(p.y), width);
return length(max(q, 0.0));
}
// sinc関数を利用したカメラシェイク
// speed=角速度の倍率、cycleSec=振動の周期(sinc関数の使う範囲)
// speed=3.0、cycleSec=6.0だと、-6.0*PI~6.0*PIの範囲を3倍角速度で使うので実際には2sごとに揺れる
// 範囲を狭めれば恒常的に揺れることになる
float sinc(float x){
return sin(PI * x) / (PI * x);
}
float sincWave(float speed, float cycleSec){
return sinc(mod(time * speed * PI, cycleSec * PI) - cycleSec * 0.5 * PI);
}
// 距離(rayStep)に応じた疑似フォグ
gl_FragColor = vec4(color + (stepCount / float(maxRayStep)), 1.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment