Shader #4 : ストライプ

f:id:zonu_a0:20210529173155p:plain

Shadertoy

www.shadertoy.com

ソースコード

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;
    // 表示倍率
    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 と同じ

Shader #3 : 多重リング - zonu's memo