ShaderGraph の全貌
UnityShaderGraphLibrary/HeightFog.shadergraph at main · yayorozu/UnityShaderGraphLibrary · GitHub
各処理をちょっとだけ分割してまとめる
UV と Depth から ワールド座標を求めてY のみを出力
float getWorldPosY() { float3 worldPos = ComputeWorldSpacePosition(In.uv, In.depth, UNITY_MATRIX_I_VP); return worldPos.y; }
指定した高さ情報をもとに Fog の強さを算出
float calcIntensity(float y) { float diff = _Height - y; float intensity = inverseLerp(0, _Maxheight, diff); return intensity; }
もとの色とブレンド
half4 blend(float y, float intensity) { float fog = step(y, _Height); float t = fog * intensity; half4 color = lerp(_BlitSource, _FogColor, t); return color; }