You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
1.1 KiB

#ifndef TOON_MAINLIGHT_INCLUDED
#define TOON_MAINLIGHT_INCLUDED
void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float ShadowAtten)
{
#ifdef SHADERGRAPH_PREVIEW
Direction = normalize(float3(0.5, 0.5, -0.5));
Color = 1;
ShadowAtten = 1;
#else
float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
Light mainLight = GetMainLight();
Direction = mainLight.direction;
Color = mainLight.color;
// 直接採樣主光陰影貼圖,繞過 MAIN_LIGHT_CALCULATE_SHADOWS keyword 條件。
ShadowSamplingData samplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
real shadowStrength = shadowParams.x;
// PCF 過濾採樣 → 柔邊、消鋸齒(不依賴 _SHADOWS_SOFT keyword)
real atten = SampleShadowmapFiltered(
TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_LinearClampCompare),
shadowCoord, samplingData);
atten = LerpWhiteTo(atten, shadowStrength);
// 超出陰影最遠距離 = 不打陰影
ShadowAtten = BEYOND_SHADOW_FAR(shadowCoord) ? 1.0 : atten;
#endif
}
#endif