vault backup: 2024-12-17 12:08:05

This commit is contained in:
BlueRose 2024-12-17 12:08:05 +08:00
parent f4440d36e5
commit fedf9594cc
2 changed files with 96 additions and 2 deletions
.obsidian/plugins/various-complements
03-UnrealEngine/卡通渲染相关资料/渲染功能/阴影控制

@ -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}}}}
{"SequoiaCamShotEvalTemplate":{"SequoiaCamShotEvalTemplate":{"currentFile":{"count":1,"lastUpdated":1732609264076}}},"c++内存泄漏分析工具":{"c++内存泄漏分析工具":{"internalLink":{"count":1,"lastUpdated":1733137754779}}},"Lights":{"Lights":{"currentFile":{"count":1,"lastUpdated":1733637911876}}},"FShadowProjectionNoTransformVSShadowProjectionNoTransformVS、FShadowVolumeBoundProjectionVSShadowVolumeBoundProjectionVS":{"FShadowProjectionNoTransformVSShadowProjectionNoTransformVS、FShadowVolumeBoundProjectionVSShadowVolumeBoundProjectionVS":{"currentFile":{"count":1,"lastUpdated":1734345863513}}},"DecodeLightAttenuation":{"DecodeLightAttenuation":{"currentFile":{"count":1,"lastUpdated":1734406452310}}}}

@ -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提出