UE4:Mobile Spot Ligth shadow

如需转载本文,请声明作者及出处。

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--------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值