Created
May 27, 2015 12:23
-
-
Save 0b5vr/0eed4aa6abd84be430be to your computer and use it in GitHub Desktop.
GLSL Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gl_FragColor : ここに色()[vec4]を代入する | |
// gl_FragCoord.x : 実行中のピクセルのx座標 [float] | |
// gl_FragCoord.y : 実行中のピクセルのy座標 [float] | |
// gl_FragCoord.xy : 実行中のピクセルのxy座標 [vec2] | |
// おまじない(しっかり説明すると、GLESで浮動小数点の精度を低めないと動かない端末が多い) | |
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
uniform float time; // JavaScript から投げられてくる時間 [秒] | |
uniform vec2 resolution; // JavaScript から投げられてくる画面解像度 | |
void main() | |
{ | |
gl_FragColor = vec4( // gl_FragColorに4次元ベクトル(赤,緑,青,透明度)を代入すると、実行中のピクセルの色がそれになる | |
gl_FragCoord.x / resolution.x, // 赤:左から右に 0.0 ~ 1.0 | |
gl_FragCoord.y / resolution.y, // 緑:下から上に 0.0 ~ 1.0 | |
0.5 + 0.5 * sin( time ), // 青:時間軸方向に揺れる | |
1.0 // 透明度:とりあえず1.0にしておこう | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment