ターミナルエミュレータGhosttyのシェーダ機能を試してみました。

以下のサイトのコードがほぼそのまま利用できました。
残念ながらテクスチャを利用するコードは使えませんでした。
https://www.shadertoy.com/

コードを改造することによりターミナルエミュレータとして利用可能になります。

iChannel0にはターミナルエミュレータの出力が割り当てられていて変更はできないようです。
custom-shader-ichannel1 = ./texture.png みたいなテクスチャのローダが実装されないかなぁ。

環境

  • Arch Linux
  • GNOME 47.5
  • ghostty 1.1.2

構築

以下のサイトのサンプルコードを利用します。
https://www.shadertoy.com/

サンプル1

  1. 以下のサンプルコードをファイルに保存します。
    URLhttps://www.shadertoy.com/view/Xds3zN
    FILE$HOME/.config/ghostty/shaders/raymarching_primitives.glsl
  2. Ghosttyの設定ファイルでGLSLファイルを指定します。
    $HOME/.config/ghostty/config
    custom-shader = ./shaders/raymarching_primitives.glsl

サンプル2

  1. 以下のサンプルコードをファイルに保存します。
    URLhttps://www.shadertoy.com/view/Ms2XzK
    FILE$HOME/.config/ghostty/shaders/nyancat.glsl
  2. 最後の方のコードを修正します
    $HOME/.config/ghostty/shaders/mario.glsl
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
        vec4 rainbow = getRainbowAt(uv, nyan_p);
    col = mix(col, rainbow, rainbow.a);
    //vec4 nyan = getNyanAt(uv, nyan_p, nyan_s);

    //col = mix(col, nyan, nyan.a);

    //fragColor = vec4(col);

    vec4 terminalColor = texture(iChannel0, uv);
    fragColor = vec4(col + terminalColor);
    }
  3. Ghosttyの設定ファイルでGLSLファイルを指定します。
    $HOME/.config/ghostty/config
    custom-shader = ./shaders/nyancat.glsl

サンプル3

  1. 以下のサンプルコードをファイルに保存します。
    URLhttps://www.shadertoy.com/view/XtlSD7
    FILE$HOME/.config/ghostty/shaders/mario.glsl
  2. 最後の方のコードを修正します
    $HOME/.config/ghostty/shaders/mario.glsl
    1424
    1425
    1426
    1427
    1428
    1429
    1430
        // fragColor.xyz 	= color;
    // fragColor.w = 1.0;

    vec4 col = vec4(color, 1.0);
    vec4 terminalColor = texture(iChannel0, uv);
    fragColor = vec4(col + terminalColor);
    }
  3. Ghosttyの設定ファイルでGLSLファイルを指定します。
    $HOME/.config/ghostty/config
    custom-shader = ./shaders/mario.glsl