概要
参考:
Shader 言語について HLSL/GLSL/Cg – teratail
導入
参考:
最近分かってきた Unity Cg/HLSL シェーダのあれこれ | Mugichoko’s blog
データ型
参考:
ベクトル
参考:
Vector 型 | Microsoft Docs [公式]
Per-Component 算術演算 | Microsoft Docs [公式]
dot
ドキュメント:
dot | Cg Toolkit Documentation [Official]
参考:
hlsl dot function – Stack Overflow
What’s the difference between dot and * in HLSL – GameDev.net
Dot product vs Direct vector components sum performance in shaders – Stack Overflow
関数
ドキュメント:
組み込み関数 – HLSL | Microsoft Learn [公式]
参考:
手続き的にテクスチャ生成など行うとき使用頻度の高い関数 – Qiita
線形補間 (lerp)
ドキュメント:
lerp | Cg Toolkit Documentation [Official]
saturate
ドキュメント:
saturate | Microsoft Learn [公式]
saturate | Cg Toolkit Documentation [Official]
参考:
saturate vs max | Nyahoon Games Pte. Ltd.
clamp
ドキュメント:
smoothstep
三次関数近似
float smoothstep(float edge0, float edge1, float x)
{
float t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}
Code language: Arduino (arduino)
参考:
smoothstep | The Book of Shaders
ノイズ
参考:
互換命令
参考:
GLSL / HLSL / Metal 命令対応表 | HYPER でんち
GLSL と HLSL の対応を示すリファレンス | Microsoft Docs [公式]
implicit truncation of vector type 警告
現象:
暗黙的にベクトルの長さを切り詰めている旨の警告が発生する。
implicit truncation of vector type
対処法:
- スウィズルを使用する。
- 適切な長さのベクトル型を使用する。
- 適切にキャストする。
参考:
shader warnings? – Unity Forum
implicit truncation of vector type error – Stack Overflow
ドキュメント
Cg Standard Library Documentation | NVIDIA [Official]
リファレンス – HLSL | Microsoft Learn [公式]
言語構文 – HLSL | Microsoft Learn [公式]
エラーと警告 – HLSL | Microsoft Learn [公式]
プログラミング ガイド – HLSL | Microsoft Learn [公式]
上位レベルシェーダー言語 (HLSL) | Microsoft Learn [公式]
まとめ
チュートリアル
Unity で暖を取る! GLSL を Cg/HLSL に書き換えて楽しもう!! | Unity Learning Materials
Noise Shader
リポジトリ:
keijiro/NoiseShader: Noise Shader Library for Unity – GitHub
WebGL Noise
リポジトリ:
ashima/webgl-noise: Procedural Noise Shader Routines Compatible with WebGL – GitHub