Shader Graph中有两种Custom Function方式,一种是通过字符串,也就是直接把代码写上去,第二种是通过外部文件,把代码写到外部,如果下面的一个自定义的外部hlsl文件;
#ifndef CUSTOMFUNC_INCLUDE
#define CUSTOMFUNC_INCLUDE
void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = mainLight.shadowAttenuation;
#endif
}
#endif
在shader Graph中选择这个文件 注意Name写MainLight,不要加_half,并且Shader Graph上面的Precision 中要选择Half。
|