WebGLシェーダー(if-elseステートメントおよびforステートメント)
Webgl Shader If Else Statement
この記事は WebGLチュートリアル(eBook) セクション2.6
シェーダー言語GLSL
ifステートメント、forステートメント、およびjavascript
言語の使用についてC
ifステートメントの実行と言語でのステートメントの論理規則は基本的に同じです。ここでは、デフォルトで、すでに特定のプログラミング基盤があるため、説明することはあまりなく、簡単な説明だけです。
単独で使用if
if(x>100){ gl_FragColor = vec4(1.0,0.0,0.0,1.0)//red }
if-else
フォーム
bool colorBool // Set the pixel value of the fragment according to the Boolean value if(bool){ gl_FragColor = vec4(1.0,0.0,0.0,1.0)//red }else { gl_FragColor = vec4(0.0,0.0,1.0,1.0)//blue }
if-else if-else if-...else
フォーム
if(x<10){ }else if (x<20) { }else if (x<30) { }else { }
continue
with break
キーワード
continue
:forループの次のループに直接ジャンプします break
:forループは実行を終了します
for (var i = 0 i < 20 i++) { ... if(i==15){ continue// For the next cycle, execute the cycle corresponding to i = 16 } ... }
for (var i = 0 i < 20 i++) { ... if(i==15){ break// Directly terminate the loop execution, the loop after i = 16, 17 etc. will not be executed } ... }