Shader #4 : ストライプ
Shadertoy
ソースコード
Image
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // ピクセルのX座標 float pixelX = fragCoord.x; // 表示倍率 float ratio = 10.0; // 距離をsin値に変換 float sinVal = sin(pixelX / ratio) / 2.0 + 0.5; // 閾値 float threshold = 0.5f; // 白で描画する判定(sinVal <= threshold) float white = step(sinVal, threshold); // ピクセルの色を設定 fragColor = vec4(white, white, white, 1.0); }
解説
// ピクセルのX座標 float pixelX = fragCoord.x;
- 画面左を0としたピクセル座標
// 表示倍率 float ratio = 10.0; // 距離をsin値に変換 float sinVal = sin(pixelX / ratio) / 2.0 + 0.5; // 閾値 float threshold = 0.5f; // 白で描画する判定(sinVal <= threshold) float white = step(sinVal, threshold); // ピクセルの色を設定 fragColor = vec4(white, white, white, 1.0);
ここは #3 と同じ