Skip to content

Instantly share code, notes, and snippets.

@2youyou2
Created December 17, 2020 09:35
Show Gist options
  • Save 2youyou2/d2244f33c28e1eb20cff2e302b50c796 to your computer and use it in GitHub Desktop.
Save 2youyou2/d2244f33c28e1eb20cff2e302b50c796 to your computer and use it in GitHub Desktop.
unreal 4.25 subsurface shader 流程
- ShadowProjectionPixelShader.usf/Main (画阴影到 Common.ush/LightAttenuationTexture 中)
- SSSTransmission = ManualPCF(ShadowPosition.xy, Settings); (输出到 FadedSSSShadow)
- OutColor = EncodeLightAttenuation(half4(FadedShadow, FadedSSSShadow, FadedShadow, FadedSSSShadow)) (最终输出)
- BasePassPixelShader.usf/FPixelShaderInOut_MainPS (画基本物体的 pass)
- 调用 MaterialTemplate.ush 提供的方法(材质蓝图会根据 MaterialTemplate.ush 填充对应的方法)
GetMaterialBaseColor
GetMaterialMetallic
GetMaterialSpecular
GetXXX...
- ShadingModelsMaterial.ush/SetGBufferForShadingModel 输出到 DeferredShadingCommon.ush/FGBufferData 结构体中
- DeferredLightPixelShaders.usf/DeferredLightPixelMain
- DeferredShadingCommon.ush/GetScreenSpaceData (获取 GBuffer)
- GetGBufferData {
float4 GBufferA = FramebufferFetchMRT(1);
float4 GBufferB = FramebufferFetchMRT(2);
float4 GBufferC = FramebufferFetchMRT(3);
float4 GBufferD = FramebufferFetchMRT(4);
return DecodeGBufferData(GBufferA, GBufferB, GBufferC, GBufferD, GBufferE, GBufferF, GBufferVelocity, CustomNativeDepth, CustomStencil, SceneDepth, bGetNormalizedNormal, CheckerFromSceneColorUV(UV));
}
- GetPerPixelLightAttenuation (获取阴影贴图)
- GetDynamicLighting
- GetShadowTerms (用阴影贴图获取的数据计算阴影)
- ShadingModels.ush/IntegrateBxDF(根据 shading model 调用对应的 BXDF)
- SubsurfaceBxDF
- OutColor += (Radiance * Attenuation) * OpaqueVisibility;
@2youyou2
Copy link
Author

  • 修改 global shader

recompileshaders /Engine/Private/BasePassPixelShader.usf

https://medium.com/@lordned/unreal-engine-4-rendering-part-5-shader-permutations-2b975e503dd4

  • 修改某个材质

打开材质移动某个节点,点击 应用

@2youyou2
Copy link
Author

2youyou2 commented Mar 4, 2021

PreExposure

PostProcessEyeAdaptation.cpp => FSceneViewState::UpdatePreExposure

以下设置使得:PreExposure = 1

image

DirectionalLightColor

MobileBasePassRendering.cpp => SetupMobileDirectionalLightUniformParameters

Params.DirectionalLightColor = Light->Proxy->GetColor() / PI;

@2youyou2
Copy link
Author

2youyou2 commented Mar 6, 2021

rebuild reflection captures

UEditorEngine::BuildReflectionCaptures => ReadbackCaptureData

FScene::CaptureOrUploadReflectionCapture

@2youyou2
Copy link
Author

2youyou2 commented Mar 16, 2021

Point Light Intensity

inspector 设置 intensity 为 3.14

image

unreal 单位为厘米:

image

creator 单位为米:

image

@2youyou2
Copy link
Author

EditorFactories.cpp

UTextureExporterTGA::ExportBinary

Texture is RGBA16 and cannot be represented at such high bit depth in .tga. Color will be scaled to RGBA8.

@2youyou2
Copy link
Author

IndirectLightRendering.cpp => SetupReflectionUniformParameters

CubeArrayTexture = Scene->ReflectionSceneData.CubemapArray.GetRenderTarget().ShaderResourceTexture

@2youyou2
Copy link
Author

2youyou2 commented May 6, 2021

@2youyou2
Copy link
Author

2youyou2 commented Sep 24, 2021

查找最近反射球

FScene::FindClosestReflectionCaptures(FVector Position, const FReflectionCaptureProxy* (&SortedByDistanceOUT)[FPrimitiveSceneInfo::MaxCachedReflectionCaptureProxies])

更新最近反射球
FPrimitiveSceneInfo::CacheReflectionCaptures

@2youyou2
Copy link
Author

r.CompileShadersForDevelopment=0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment