UnityURP渲染管线中使用ShaderGraph获取光源方向

ShaderGraph中并未为我们提供光源方向,所以我们需要自行获取

会使用到ShaderGraph中的CustomFunction(自定义方法)节点,

img

最新版本的URP请使用以下代码

#if defined(SHADERGRAPH_PREVIEW)
    Direction = half3(0.5,0.5,0);
    Color = 1;
#else
    Light light = GetMainLight();
    Direction = light.direction;
    Color = light.color;
#endif

老版本的URP请使用以下代码

#if SHADERGRAPH_PREVIEW
    Direction = half3(0.5,0.5,0);
    Color = 1;
#else
    Light light = GetMainLight();
    Direction = light.direction;
    Color = light.color;
#endif

这样,我们就获取到了光源的方向和颜色

注:这样获取的光源方向是基于WordSpace(世界空间坐标系)的;

最后修改:2023 年 09 月 20 日
如果觉得我的文章对你有用,请随意赞赏