Automatic shader/material generation from .compeito snippets,
for writing GPGPU procedures for VRChat in a ComputeShader-like style.
.compeito ファイルからシェーダ・マテリアルを自動生成します。
VRChat で GPGPUっぽいことをするときに Compute Shader っぽく書けるようにするための仕組みです。
Install from VPM: https://phi16.github.io/VRC_Packages/
- Create a new
.compeitofile from the context menu, or from scratch. - Write your shader function (e.g.
float4 Main(uint2 id) { ... }) in HLSL as usual.- Input: Texel location (
uint2, in pixels) of the output texture - Output: The value (typically
float4) to output
- Input: Texel location (
- Declare
#pragma kernel Mainto create a shader pass.- You can declare multiple passes.
- You must declare all kernels at the top of the
.compeitofile. - You can also declare the output type, like
#pragma kernel Main float4.
- You've got the generated shader and material! 🎉
passIndex = material.FindPass("Main");to get the pass index.Compeito.Dispatch(material, passIndex, outputTexture);to dispatch the kernel.
- 新規
.compeitoファイルを右クリックメニューから (か新規ファイルとして) 作成します。 - シェーダ関数をHLSLで普通に (
float4 Main(uint2 id) { ... }という感じで) 書きます。- 入力: 書き込み先のテクセル座標 (
uint2, ピクセル単位) - 出力: 書き込みたい値 (典型的には
float4)
- 入力: 書き込み先のテクセル座標 (
#pragma kernel Mainを宣言するとシェーダパスが作成されます。- 複数パス宣言することもできます。
- 全てのカーネル宣言は
.compeitoファイルの先頭で行う必要があります。 - また、書き込む値の型を
#pragma kernel Main float4のように宣言できます。
- これでシェーダとマテリアルが生成されました! 🎉
passIndex = material.FindPass("Main");と書いてパス (のインデックス) を取得し、Compeito.Dispatch(material, passIndex, outputTexture);で処理を実行します。
- Examples (highly recommended to check out / まず見てもらうといいと思います)
- Main implementation
- Udon utility
こんぺいとう (Konpeito) is a traditional Japanese sugar candy, small and cute.
Add the following to your .vscode/settings.json.
{
"files.associations": {
"*.compeito": "hlsl"
}
}
- PC platform 以外の動作は未確認 (確認予定)
- VRChat SDK が入っていない状態でも一応動きます
MIT
(なお、Compeito を使って生成された shader/material には MIT License は適用されないので、特にワールドクレジットなどに載せる必要はありません。)