From fedf9594cc011943f956114c106765b7443cdc91 Mon Sep 17 00:00:00 2001 From: BlueRose <378100977@qq.com> Date: Tue, 17 Dec 2024 12:08:05 +0800 Subject: [PATCH] vault backup: 2024-12-17 12:08:05 --- .../various-complements/histories.json | 2 +- .../渲染功能/阴影控制/ToonShadow.md | 96 ++++++++++++++++++- 2 files changed, 96 insertions(+), 2 deletions(-) diff --git a/.obsidian/plugins/various-complements/histories.json b/.obsidian/plugins/various-complements/histories.json index fc040fe..4c6818d 100644 --- a/.obsidian/plugins/various-complements/histories.json +++ b/.obsidian/plugins/various-complements/histories.json @@ -1 +1 @@ -{"SequoiaCamShotEvalTemplate":{"SequoiaCamShotEvalTemplate":{"currentFile":{"count":1,"lastUpdated":1732609264076}}},"c++内存泄漏分析工具":{"c++内存泄漏分析工具":{"internalLink":{"count":1,"lastUpdated":1733137754779}}},"Lights":{"Lights":{"currentFile":{"count":1,"lastUpdated":1733637911876}}},"渲染屏幕空间阴影遮罩,并用于光照计算。":{"渲染屏幕空间阴影遮罩,并用于光照计算。":{"currentFile":{"count":1,"lastUpdated":1734354537396}}}} \ No newline at end of file +{"SequoiaCamShotEvalTemplate":{"SequoiaCamShotEvalTemplate":{"currentFile":{"count":1,"lastUpdated":1732609264076}}},"c++内存泄漏分析工具":{"c++内存泄漏分析工具":{"internalLink":{"count":1,"lastUpdated":1733137754779}}},"Lights":{"Lights":{"currentFile":{"count":1,"lastUpdated":1733637911876}}},"FShadowProjectionNoTransformVS(ShadowProjectionNoTransformVS)、FShadowVolumeBoundProjectionVS(ShadowVolumeBoundProjectionVS)":{"FShadowProjectionNoTransformVS(ShadowProjectionNoTransformVS)、FShadowVolumeBoundProjectionVS(ShadowVolumeBoundProjectionVS)":{"currentFile":{"count":1,"lastUpdated":1734345863513}}},"DecodeLightAttenuation":{"DecodeLightAttenuation":{"currentFile":{"count":1,"lastUpdated":1734406452310}}}} \ No newline at end of file diff --git a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md index a5a9f2d..a42b20e 100644 --- a/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md +++ b/03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制/ToonShadow.md @@ -963,7 +963,101 @@ if (bDirectLighting) } ``` -使用ScreenShadowMaskTexture来渲染阴影。 +在RenderLight()中通过PassParameters->PS = GetDeferredLightPSParameters()传入参数,使用ScreenShadowMaskTexture来渲染阴影(LightAttenuationTexture)。 +### Shader +DeferredLightPixelShaders.usf + +```c++ +void DeferredLightPixelMain( +#if LIGHT_SOURCE_SHAPE > 0 + float4 InScreenPosition : TEXCOORD0, +#else + float2 ScreenUV : TEXCOORD0, + float3 ScreenVector : TEXCOORD1, +#endif + float4 SVPos : SV_POSITION, + out float4 OutColor : SV_Target0 +#if STRATA_OPAQUE_ROUGH_REFRACTION_ENABLED + , out float3 OutOpaqueRoughRefractionSceneColor : SV_Target1 + , out float3 OutSubSurfaceSceneColor : SV_Target2#endif + ) + { + ... + #else // STRATA_ENABLED + + FScreenSpaceData ScreenSpaceData = GetScreenSpaceData(InputParams.ScreenUV); + // Only light pixels marked as using deferred shading + BRANCH if (ScreenSpaceData.GBuffer.ShadingModelID > 0 +#if USE_LIGHTING_CHANNELS + && (GetLightingChannelMask(InputParams.ScreenUV) & DeferredLightUniforms.LightingChannelMask)//灯光通道计算 +#endif + ) + { + const float SceneDepth = CalcSceneDepth(InputParams.ScreenUV); + const FDerivedParams DerivedParams = GetDerivedParams(InputParams, SceneDepth);//FDerivedParams主要存储CameraVector以及摄像机的世界坐标 + + FDeferredLightData LightData = InitDeferredLightFromUniforms(CURRENT_LIGHT_TYPE);//根据灯光类型,填充对应灯光数据。 + UpdateLightDataColor(LightData, InputParams, DerivedParams);//计算IES * Atmosphere * Cloud 的Attenuation。结果输出到LightData.Color + + #if USE_HAIR_COMPLEX_TRANSMITTANCE + if (ScreenSpaceData.GBuffer.ShadingModelID == SHADINGMODELID_HAIR && ShouldUseHairComplexTransmittance(ScreenSpaceData.GBuffer)) + { + LightData.HairTransmittance = EvaluateDualScattering(ScreenSpaceData.GBuffer, DerivedParams.CameraVector, -DeferredLightUniforms.Direction); + } + #endif + + float Dither = InterleavedGradientNoise(InputParams.PixelPos, View.StateFrameIndexMod8);//http://advances.realtimerendering.com/s2014/index.html + + float SurfaceShadow = 1.0f; + + float4 LightAttenuation = GetLightAttenuationFromShadow(InputParams, SceneDepth);//取得ScreenShadowProjection + float4 Radiance = GetDynamicLighting(DerivedParams.TranslatedWorldPosition, DerivedParams.CameraVector, ScreenSpaceData.GBuffer, ScreenSpaceData.AmbientOcclusion, ScreenSpaceData.GBuffer.ShadingModelID, LightData, LightAttenuation, Dither, uint2(InputParams.PixelPos), SurfaceShadow); + + OutColor += Radiance; + } + +#endif // STRATA_ENABLED + + // RGB:SceneColor Specular and Diffuse + // A:Non Specular SceneColor Luminance + // So we need PreExposure for both color and alpha + OutColor.rgba *= GetExposure(); + ... + } +``` + +GetLightAttenuationFromShadow() +```c++ +float4 GetLightAttenuationFromShadow(in FInputParams InputParams, float SceneDepth) +{ + float4 LightAttenuation = float4(1, 1, 1, 1); + +#if USE_VIRTUAL_SHADOW_MAP_MASK + if (VirtualShadowMapId != INDEX_NONE) + { + float ShadowMask = GetVirtualShadowMapMaskForLight( + ShadowMaskBits, + uint2(InputParams.PixelPos), + SceneDepth, + 0, // TODO: EyeIndex + VirtualShadowMapId); + + // TODO: Subsurface...? + return ShadowMask.xxxx; + } + else +#endif + { + return GetPerPixelLightAttenuation(InputParams.ScreenUV); + } +} + +float4 GetPerPixelLightAttenuation(float2 UV) +{ + return DecodeLightAttenuation(Texture2DSampleLevel(LightAttenuationTexture, LightAttenuationTextureSampler, UV, 0));//DecodeLightAttenuation return x * x; +} +``` + # 半程阴影 由晨风&Neverwind提出: