UE4.15.1で検証
参考 †
レンダリングの流れ †
Deferred Shaing †
- 動的影生成
Main (ShadowProjectionPixelShader.usf)
- GBufferへの書き込み
MainPS (PixelShaderOutputCommon.usf)
FPixelShaderInOut_MainPS (BasePassPixelShader.usf)
- Indirect Light、Sky Lightの計算
GetPrecomputedIndirectLightingAndSkyLight (BasePassPixelShader.usf)
- Sky Lightの計算
GetSkyLighting (BasePassPixelShader.usf)
- Gバッファからシェーディング
DirectionalPixelMain (DeferredLightPixelShaders.usf)
- 動的ライトの計算。キャストシャドウもここで合成
GetDynamicLighting (DeferredLightingCommon.usf)
- シェーディングの計算
SurfaceShading (ShadingModels.usf)
Forward Shading †
- シェーディング
FPixelShaderInOut_MainPS (BasePassPixelShaders.usf)
- ライトの数だけ回して計算する
GetForwardDirectLighting (ForwardLightingCommon.usf)
- GBuffer構造体への書き込みをしてDeferredと同じ処理を回せるようにしている
- 動的ライトの計算。キャストシャドウもここで合成
GetDynamicLighting (DeferredLightingCommon.usf)
https://twitter.com/com04/status/877511284354277381
動的影生成 †
メモ †
Shadow変数が影の強さ。0.0 - 影
→FadedShadow変数フェード付き
→OutColor変数に最終出力。
OutColor.r値のみ参照されているっぽい。
MODULATED_SHADOWSがmobile時のみ使える?
Engine\Source\Runtime\Renderer\Private\ShadowRendering.cpp
https://docs.unrealengine.com/latest/JPN/Platforms/Mobile/Lighting/HowTo/ModulatedShadows/index.html
- 描画元
FDeferredShadingSceneRenderer::RenderLights (Engine\Source\Runtime\Renderer\Private\LightRendering.cpp)
FDeferredShadingSceneRenderer::RenderShadowProjections (Engine\Source\Runtime\Renderer\Private\ShadowRendering.cpp)
FSceneRenderer::RenderShadowProjections (Engine\Source\Runtime\Renderer\Private\ShadowRendering.cpp)
- モバイル用
FMobileSceneRenderer::Render (Engine\Source\Runtime\Renderer\Private\MobileShadingRenderer.cpp)
FMobileSceneRenderer::RenderModulatedShadowProjections (Engine\Source\Runtime\Renderer\Private\ShadowRendering.cpp)
FSceneRenderer::RenderShadowProjections (Engine\Source\Runtime\Renderer\Private\ShadowRendering.cpp)
Indirect Light、Sky Lightの計算 - GetPrecomputedIndirectLightingAndSkyLight †
- (BasePassPixelShader.usf)
GBufferのMRT[0]に書き出される
動的ライト、キャストシャドウの計算 - GetDynamicLighting †
- (DeferredLightingCommon.usf)
記述が無い場合は下記設定でスクリーンショット
- マテリアル
- BaseColor : 1.0, 1.0, 1.0
- Metalic : 0.0
- Roughtness 1.0
- Specular : 0.5
- ライト
- ディフューズライト1灯のみ
- Intencity : 6.0
- Color : 0.0, 1.0, 0.0
基本パラメーター †
- Default Lit

- GBuffer.DiffuseColor

- GBuffer.SpecularColor

- LightColor

SurfaceShading
↓
LightAccumulator_Add
キャストシャドウ †
SurfaceShadow変数に格納。SurfaceAttenuation変数に受け継がれる。
1.0で影無し。
SurfaceLighting †
| float3 SurfaceLighting = SurfaceShading(GBuffer, LobeRoughness, LobeEnergy, L, V, N, Random);
|

- SurfaceShadingの中身
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
| float3 StandardShading( float3 DiffuseColor, float3 SpecularColor, float3 LobeRoughness, float3 LobeEnergy, float3 L, float3 V, half3 N )
{
float3 H = normalize(V + L);
float NoL = saturate( dot(N, L) );
float NoV = saturate( abs( dot(N, V) ) + 1e-5 );
float NoH = saturate( dot(N, H) );
float VoH = saturate( dot(V, H) );
float D = D_GGX( LobeRoughness[1], NoH ) * LobeEnergy[1];
float Vis = Vis_SmithJointApprox( LobeRoughness[1], NoV, NoL );
float3 F = F_Schlick( SpecularColor, VoH );
float3 Diffuse = Diffuse_Lambert( DiffuseColor );
return Diffuse * LobeEnergy[2] + (D * Vis) * F;
}
|
- Diffuse * LobeEnergy[2] = x
*
= ![Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2].png Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2].png](http://com04.sakura.ne.jp/unreal/wiki/index.php?plugin=ref&page=%A5%A8%A5%F3%A5%B8%A5%F3%B2%FE%C2%A4-%A5%E9%A5%A4%A5%C6%A5%A3%A5%F3%A5%B0%B2%F2%C0%CF&src=Rendering-SurfaceLighting-Diffuse-x-LobeEnegy%5B2%5D.png)
- (D * Vis) * F = y
(
*
) *
= 
- x + y = return
+
= 
- Diffuse * LobeEnergy[2] = x
*
= .png Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2](Roughness_0.0).png](http://com04.sakura.ne.jp/unreal/wiki/index.php?plugin=ref&page=%A5%A8%A5%F3%A5%B8%A5%F3%B2%FE%C2%A4-%A5%E9%A5%A4%A5%C6%A5%A3%A5%F3%A5%B0%B2%F2%C0%CF&src=Rendering-SurfaceLighting-Diffuse-x-LobeEnegy%5B2%5D%28Roughness_0.0%29.png)
- (D * Vis) * F = y
(
*
) *
= 
- x + y = return
+
= 
- マテリアルのBaseColorを調整してみるとSurface Lightingにスペキュラが入っているのが確認できる

ライトカラーとの合成 †
| LightAccumulator_Add(LightAccumulator, SurfaceLighting, (1.0/PI), LightColor * (NoL * SurfaceAttenuation), bNeedsSeparateSubsurfaceLightAccumulation);
|
- (NoL * SurfaceAttenuation) =
*
= 
- LightColor * (NoL * SurfaceAttenuation) = x
*
= 
- SurfaceLighting * x =
*
= 
- SurfaceLighting * x =
*
= 