KITASENJU DESIGN BLOG

memo, html, javascript, unity

math

ふたつのsmoothstep

//return x * x * (3.0 - 2.0 * x); return 6.0*x*x*x*x*x - 15.0*x*x*x*x + 10.0*x*x*x;

微分と積分を位置・速度・加速度で理解する

微分=傾き 位置が時間とともに変化していく 位置の変化量=速度 速度の変化量=加速度(→速度一定なら加速度0) 積分=面積 速度の積分=距離(=位置) 加速度の積分=速度(加速度が一定の値なら、その面積(速度)は一定で増えていく)

circle wave 円弧波

glslのコード float circleWave(float t) { float d=1.0; float st = sin(d * 3.1415 / 2.0); float p = (mod(t * 4.0, 2.0) - 1.0) * st; float a = sqrt(1.0 - pow(p, 2.0)); float amax = sqrt(1.0 - pow(st, 2.0)); float b = sign(mod(t, 1.0) - 0.5); …

Mapping function - マッピング関数

js function map (value, fromMin, fromMax, toMin, toMax){ return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin; } glsl float map (float value, float fromMin, float fromMax, float toMin, float toMax){ if(value<fromMin)value=fromMin; if(value>fromMax)valu</frommin)value=frommin;>…

smooth floor

float y(float x) { return floor(x) + smoothstep(0.4,1.0,fract(x)); }

三角波的なfract

fract like triangle wave UVをミラー的に折り返したいとき。 GLSL Grapher で描画 float y(float x) { return abs(2.0*fract(0.5*x-0.5)-1.0); } unityのシェーダーで。 //hlsl float2 sankaku(float2 x) { return abs(2.0*frac(0.5*x-0.5)-1.0); } 参考 gl…

内積でベクトルの方向が同じかどうか

//方向が一緒なら1、逆なら-1 直角なら0 if( Vector3.Dot( velocity.normalized, Vector3.down) > 0.5f){ }

オレオレ 極座標変換

rectangular/polar coord void Update() { var vv = transform.position; var amp = vv.magnitude; var radX = (-Mathf.Atan2(vv.z,vv.x) + Mathf.PI/2f); var radY = Mathf.Asin(vv.y/amp); //適当に変える。 //radX+=offsetX; //radY+=offsetY; var xx = a…

斜面に沿うベクトル

Vector3.ProjectOnPlane Unityで斜面に沿ったベクトルはVector3.ProjectOnPlaneで作ろう+その解説 - んななのゲーム開発備忘録 関連:垂線 線分にある点から垂線を下ろしたときの交点 - ◎ kitasenju design blog ◎

"FOOTER"