• 追加された行はこの色です。
  • 削除された行はこの色です。
#contents

----
UE4.15.1で検証

- G-Bufferについてはコチラを参照
[[エンジン改造-Gバッファの拡張]]

* 参考 [#m33dd291]
- グラフィック プログラミングの概要 - Unreal Engine Documents
https://docs.unrealengine.com/latest/JPN/Programming/Rendering/Overview/index.html

* レンダリングの流れ [#ba1608ac]

** Deferred Shaing [#l9749b95]
- COLOR(#30c030){動的影生成}
Main COLOR(#3030c0){(ShadowProjectionPixelShader.usf)}
- COLOR(#30c030){GBufferへの書き込み}
MainPS COLOR(#3030c0){(PixelShaderOutputCommon.usf)}
 FPixelShaderInOut_MainPS  COLOR(#3030c0){(BasePassPixelShader.usf)}
-- COLOR(#30c030){Indirect Light、Sky Lightの計算}
GetPrecomputedIndirectLightingAndSkyLight COLOR(#3030c0){(BasePassPixelShader.usf)}
---COLOR(#30c030){Sky Lightの計算}
GetSkyLighting COLOR(#3030c0){(BasePassPixelShader.usf)}

- COLOR(#30c030){Gバッファからシェーディング}
DirectionalPixelMain COLOR(#3030c0){(DeferredLightPixelShaders.usf)}
-- COLOR(#30c030){動的ライトの計算。キャストシャドウもここで合成}
GetDynamicLighting COLOR(#3030c0){(DeferredLightingCommon.usf)}
--- COLOR(#30c030){シェーディングの計算}
SurfaceShading COLOR(#3030c0){(ShadingModels.usf)}

** Forward Shading [#q4fa7cd0]

- COLOR(#30c030){シェーディング}
FPixelShaderInOut_MainPS COLOR(#3030c0){(BasePassPixelShaders.usf)}
-- COLOR(#30c030){ライトの数だけ回して計算する}
GetForwardDirectLighting COLOR(#3030c0){(ForwardLightingCommon.usf)}
--- COLOR(#30c030){GBuffer構造体への書き込みをしてDeferredと同じ処理を回せるようにしている}
--- COLOR(#30c030){動的ライトの計算。キャストシャドウもここで合成}
GetDynamicLighting COLOR(#3030c0){(DeferredLightingCommon.usf)}

https://twitter.com/com04/status/877511284354277381

* 動的影生成 [#zcab6479]
** メモ [#r54d1d4a]
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 [#b1fca4b2]
- COLOR(#3030c0){(BasePassPixelShader.usf)}
GBufferのMRT[0]に書き出される

* 動的ライト、キャストシャドウの計算 - GetDynamicLighting [#k7f3b590]
- COLOR(#3030c0){(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

** 基本パラメーター [#l94a890a]
- Default Lit
&ref(Rendering-DefaultLit.png,,50%);
- GBuffer.DiffuseColor
&ref(Rendering-GBuffer.DeffuseColor.png,,50%);
- GBuffer.SpecularColor
&ref(Rendering-GBuffer.SpecularColor.png,,50%);
- LightColor
&ref(Rendering-LightColor.png,,50%);

** ライティングフロー [#x1bcecfc]

SurfaceShading
 ↓
LightAccumulator_Add

** キャストシャドウ [#cb677cf5]
SurfaceShadow変数に格納。SurfaceAttenuation変数に受け継がれる。
1.0で影無し。


*** SurfaceLighting [#odb01557]
#code(C,nonumber,nomenu){{
float3 SurfaceLighting = SurfaceShading(GBuffer, LobeRoughness, LobeEnergy, L, V, N, Random);
}}
&ref(Rendering-SurfaceLighting.png,,50%);

- SurfaceShadingの中身
#code(C,nonumber,nomenu){{
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) );
	
	// Generalized microfacet specular
	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 );
	//float3 Diffuse = Diffuse_Burley( DiffuseColor, LobeRoughness[1], NoV, NoL, VoH );
	//float3 Diffuse = Diffuse_OrenNayar( DiffuseColor, LobeRoughness[1], NoV, NoL, VoH );

	return Diffuse * LobeEnergy[2] + (D * Vis) * F;
}
}}
++ Diffuse * LobeEnergy[2] = x
&ref(Rendering-SurfaceLighting-Diffuse.png,,50%); * &ref(Rendering-SurfaceLighting-LobeEnegy[2].png,,50%); = &ref(Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2].png,,50%);
++ (D * Vis) * F = y
(&ref(Rendering-SurfaceLighting-D(Roughness_1.0).png,,50%); * &ref(Rendering-SurfaceLighting-Vis(Roughness_1.0).png,,50%); ) * &ref(Rendering-SurfaceLighting-F.png,,50%); = &ref(Rendering-SurfaceLighting-(D-x-Vis)-x-F.png,,50%);
++ x + y = return
&ref(Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2].png,,50%); + &ref(Rendering-SurfaceLighting-(D-x-Vis)-x-F.png,,50%); = &ref(Rendering-SurfaceLighting.png,,50%);


----
-- Roughness = 0.0の時
++ Diffuse * LobeEnergy[2] = x
&ref(Rendering-SurfaceLighting-Diffuse.png,,50%); * &ref(Rendering-SurfaceLighting-LobeEnegy[2](Roughness_0.0).png,,50%); = &ref(Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2](Roughness_0.0).png,,50%);
++ (D * Vis) * F = y
(&ref(Rendering-SurfaceLighting-D(Roughness_0.0).png,,50%); * &ref(Rendering-SurfaceLighting-Vis(Roughness_0.0).png,,50%); ) * &ref(Rendering-SurfaceLighting-F.png,,50%); = &ref(Rendering-SurfaceLighting-(D-x-Vis)-x-F(Roughtness_0.0).png,,50%);
++ x + y = return
&ref(Rendering-SurfaceLighting-Diffuse-x-LobeEnegy[2](Roughness_0.0).png,,50%); + &ref(Rendering-SurfaceLighting-(D-x-Vis)-x-F(Roughtness_0.0).png,,50%); = &ref(Rendering-SurfaceLighting(Roughness_0.0).png,,50%);

-- マテリアルのBaseColorを調整してみるとSurface Lightingにスペキュラが入っているのが確認できる
&ref(Rendering-SurfaceLighting-Roughness_0.0_Adjust.png,,50%);



*** ライトカラーとの合成 [#j09d29bc]
#code(C,nonumber,nomenu){{
LightAccumulator_Add(LightAccumulator, SurfaceLighting, (1.0/PI), LightColor * (NoL * SurfaceAttenuation), bNeedsSeparateSubsurfaceLightAccumulation);
}}
- (NoL * SurfaceAttenuation) = 
&ref(Rendering-NoL.png,,50%); * &ref(Rendering-SurfaceAttenuation.png,,50%); = &ref(Rendering-NoL-x-SurfaceAttenuation.png,,50%);
- LightColor * (NoL * SurfaceAttenuation) = x
&ref(Rendering-LightColor.png,,50%); * &ref(Rendering-NoL-x-SurfaceAttenuation.png,,50%); = &ref(Rendering-LightColor-x-(NoL-x-SurfaceAttenuation).png,,50%);

- SurfaceLighting * x = 
&ref(Rendering-SurfaceLighting.png,,50%); * &ref(Rendering-LightColor-x-(NoL-x-SurfaceAttenuation).png,,50%); = &ref(Rendering-GetDynamicLighting.png,,50%);

----
- Roughness = 0.0の時
+ SurfaceLighting * x = 
&ref(Rendering-SurfaceLighting(Roughness_0.0).png,,50%); * &ref(Rendering-LightColor-x-(NoL-x-SurfaceAttenuation).png,,50%); = &ref(Rendering-GetDynamicLighting(Roughness_0.0).png,,50%);


    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS