【UE4】4.24,4.25增加自定义光照

4.24之后源码有所改动,网上的方法用不了。我改了一下成功了,在这里记录一下怕之后忘记,请不要吐槽我

1.UnrealEngine\Engine\Source\Runtime\Engine\Classes\Engine\EngineTypes.h

就还是叫这个名字吧MSM_StylizedShadow

 

2. UnrealEngine\Engine\Source\Runtime\Engine\Private\Materials\Material.cpp

找到 static bool IsPropertyActive_Internal这个函数:

 

 

3.UnrealEngine\Engine\Source\Runtime\Engine\Private\Materials\HLSLMaterialTranslator.h

找到Line 1520.

(4.25在HLSLMaterialTranslator.cpp)

 

 

4. UnrealEngine\Engine\Shaders\Private\ShadingCommon.ush

 

 

 

5. UnrealEngine\Engine\Shaders\Private\ShadingCommon.ush

找到 float3 GetShadingModelColor(uint ShadingModelID):

 

 

 

6. UnrealEngine\Engine\Shaders\Private\ShadingModelsMaterial.ush

找到 void SetGBufferForShadingModel:

#if MATERIAL_SHADINGMODEL_STYLIZED_SHADOW
    GBuffer.ShadingModelID = SHADINGMODELID_STYLIZED_SHADOW;
    GBuffer.CustomData.x = GetMaterialCustomData0(MaterialParameters);
#endif

 

 

7. UnrealEngine\Engine\Shaders\Private\BasePassCommon.ush

找到 #define WRITES_CUSTOMDATA_TO_GBUFFER

 

 

至此准备工作完成

 

8. UnrealEngine\Engine\Shaders\Private\DeferredLightingCommon.ush

 

找到GetDynamicLighting函数:

在Line373.左右

 

float3 AttenuationColor = 0.f;

                     float NoL = saturate( dot(N, L) );

                     float DistanceAttenuation = 1;

                     float LightRadiusMask = 1;

                     float SpotFalloff = 1;

                     BRANCH

                     if(ShadingModelID == SHADINGMODELID_STYLIZED_SHADOW)

                     {

                            float Range = GBuffer.CustomData.x * 0.5f;

                            AttenuationColor = LightColor * ((DistanceAttenuation * LightRadiusMask * SpotFalloff) * smoothstep(0.5f - Range, 0.5f + Range, SurfaceShadow) * 0.1f);

 

                            float3 H = normalize(V+L);

                            float NoH = saturate( dot(N, H));

                            float3 SurfaceLighting = GBuffer.DiffuseColor + saturate(smoothstep(0.5f - Range, 0.5f + Range, D_GGX(GBuffer.Roughness, NoH)) * GBuffer.SpecularColor);

                           

                            LightAccumulator_Add( LightAccumulator, SurfaceLighting, Lighting.Diffuse, AttenuationColor * LightMask * Shadow.SurfaceShadow, bNeedsSeparateSubsurfaceLightAccumulation );

                     }

                     else

                     {

                            float SurfaceAttenuation = (DistanceAttenuation * LightRadiusMask * SpotFalloff) * SurfaceShadow;

                            AttenuationColor = LightColor * (NoL * SurfaceAttenuation);

                           

                            Lighting.Specular *= LightData.SpecularScale;

                           

                            LightAccumulator_Add( LightAccumulator, Lighting.Diffuse + Lighting.Specular, Lighting.Diffuse, AttenuationColor * LightMask * Shadow.SurfaceShadow, bNeedsSeparateSubsurfaceLightAccumulation );

                            LightAccumulator_Add( LightAccumulator, Lighting.Transmission, Lighting.Transmission, AttenuationColor * LightMask * Shadow.TransmissionShadow, bNeedsSeparateSubsurfaceLightAccumulation );

                     }

 

就是,判断一下是否是SHADINGMODELID_STYLIZED_SHADOW,然后在LightAccumulator_Add里替换成我们自己的AttenuationColor与SurfaceLighting

 

4.25要注意LightAccumulator_Add换成LightAccumulator_AddSplit,并且多了一个参数

最终会是这样

 

 

 

 

 

9.编译一下,然后找个场景把里面物体的材质挨个换成SHADINGMODELID_STYLIZED_SHADOW就好啦

 

 

 

 

 

 

 

10. UnrealEngine\Engine\Shaders\Private\BasePassPixelShader.usf

找到注释// Volume lighting for lit translucency

 

11.Engine\Source\Editor\PixelInspector\Private\PixelInspectorResult.h

 

 

12.Engine\Source\Editor\PixelInspector\Private\PixelInspectorResult.cpp

Line:211.DecodeShadingModel()

 

 

 

13.Engine\Shaders\Private\TiledDeferredLightShaders.usf

Line.345

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值