如需转载本文,请声明作者及出处。
basepixelshader.txt 知道,计算Cascaded Shadow Map需要的参数,其实跟Cascaded Shadow Map也没多大关系,能计算阴影就行
int4 SpotLightId;
FPCFSamplerSettings Settings;
Settings.ShadowDepthTexture = MobileDirectionalLight.DirectionalLightShadowTexture;
Settings.ShadowDepthTextureSampler = MobileDirectionalLight.DirectionalLightShadowSampler;
Settings.TransitionScale = MobileDirectionalLight.DirectionalLightShadowTransition;
Settings.ShadowBufferSize = MobileDirectionalLight.DirectionalLightShadowSize;
Settings.bSubsurface = false;
Settings.bTreatMaxDepthUnshadowed = false;
Settings.DensityMulConstant = 0;
Settings.ProjectionDepthBiasParameters = 0;
需要修改源码,将所需的参数向gpu传输
MeshPipleLine
CPU---------------------->pass param to GPU------->MobileBasePassPixel.usf
MobileBasePass
------------------------------------------MobileBasePassPixel.usf-----------------------------------
//灯光id传入shader
int4 SpotLightId;
//阴影的计算抄MobileBasePassPixel.usf前面的代码
#if PROJECT_MOBILE_ENABLE_MOVABLE_SPOTLIGHTS
if(SpotLightAngles[i].w > 0.0)
{
Attenuation *= SpotAttenuation(L, -SpotLightDirection[i].xyz, SpotLightAngles[i].xy);
#if RECEIVE_MOBILE_SPOT_LIGHT_SHADOW
if (SpotLightId[i] == MobileSpotLight.SpotLightId)
{
half Shadow = 1;
FPCFSamplerSettings Settings;
//主要参数
Settings.ShadowDepthTexture = MobileSpotLight.SpotLightShadowTexture;
Settings.ShadowDepthTextureSampler = MobileSpotLight.SpotLightShadowSampler;
Settings.TransitionScale = MobileSpotLight.SpotLightTransition;
Settings.ShadowBufferSize = MobileSpotLight.SpotLightShadowSize;
Settings.bSubsurface = false;
Settings.bTreatMaxDepthUnshadowed = false;
Settings.DensityMulConstant = 0;
Settings.ProjectionDepthBiasParameters = 0;
float4 ShadowPosition = float4(0, 0, 0, 0);
// 抄MobileBasePassPixel.usf前面的代码
ShadowPosition = mul(float4(MaterialParameters.ScreenPosition.xyw, 1), MobileSpotLight.SpotLightScreenToShadow);
if (ShadowPosition.z > 0)
{
float LightSpacePixelDepthForOpaque = min(ShadowPosition.z, 0.99999f);
Settings.SceneDepth = LightSpacePixelDepthForOpaque;
half ShadowMap = Manual2x2PCF(float2(ShadowPosition.xy / ShadowPosition.w), Settings);
Shadow = min(Shadow, ShadowMap);
}
// Attenuation计算出阴影强度
Attenuation *= Shadow;
}
#endif
}
#endif
所以一共有两砣参数需要传递
-------------------------------------shader params--------------------------------------------