17032002(动态AO DOF)
Posted username
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了17032002(动态AO DOF)相关的知识,希望对你有一定的参考价值。
【目标】
摄像机相关的AO DOF
【思路】
1 方案1:
- 想添加一个相机节点放入后期链中
2 方案2:
- 在Uber节点属性中添加是否镜头相关属性
- 远近的两套参数在哪配置
4 整个后期数据流程:
5 主要的数据控制在ULocalPlayer中
6 Blend计算
- 地图可以单独配置出来特效后期链
- 系统设置高中低可以配置后期链的参数或者在后期链的节点上处理(添加等级节点)
- 跟相机相关的后期(DOF、AO)
- PostProcessEditor.h PostProcessEditor.cpp
10 高中低配置方案:
- UPostProcessChain 中添加高中的Effect列表
- 在后期中编辑器连接不同首节点,下图概念图
11 相机相关后期方案:
- 在UberPostProcess节点添加最近参数PostProcessSettings结构
- 新建一个结构,包括Settings和Camera相关参数
- 在根据CameraPitch生成Setting后,再使用ULocalPlayer.OverridePostProcessSettings 去覆盖
12 问题:在平视角 但是需要远景时怎么办(如Matineee中)?
- 所以对话时,打开主角界面时,用的是一个配置PPSettings
- 退出时恢复
- 开启相机相关的,对话等优先级要比相机相关的优先级高
13 在ULocalPlayer 中有个后期链列表
- ULocalPlayer.PlayerPostProcessChains
- 更新这个列表后要Rebuild一次,将列表中所有后期链的Effect加到ULocalPlayer.PlayerPostProcess 中
- 后面统一处理
14 问题:对话 主角界面这种使用PPSettings还是后期链?
【步骤】
1 修改ue3DevelopmentSrcEngineClassesUberPostProcessEffect.uc 添加
struct native NearCameraPostProcessSettings{ var PostProcessSettings Settings; var INT DestCameraPitch;};var (Camera) NearCameraPostProcessSettings NearCameraSettings
2 修改 添加开关、Max Min
struct native NearCameraPostProcessSettings{ var() PostProcessSettings Settings; var() INT CameraPitchMin; var() INT CameraPitchMax; structcpptext{ FNearCameraPostProcessSettings(): CameraPitchMin(64626), CameraPitchMax(58800) { }}};var (Camera) bool bUseNearCameraSettings;var (Camera) NearCameraPostProcessSettings NearCameraSettings;
3 包一个函UPostProcessChain* GetActivePostProccessChain()
UPostProcessChain* ULocalPlayer::GetActivePostProccessChain(const FVector& ViewLocation){ // Find the post-process settings for the view. FPostProcessSettings NewSettings; APostProcessVolume *NewVolume; // LEVEL NewVolume = GWorld->GetWorldInfo()->GetPostProcessSettings(ViewLocation, TRUE, NewSettings); bForceDefaultPostProcessChain = FALSE; if (NewVolume && NewVolume->bOverrideWorldPostProcessChain) { bForceDefaultPostProcessChain = TRUE; } if (GEngine->bForceUseDefaultPostProcess && GWorld->GetWorldInfo()->bDefaultPostProcessPriority) { bForceDefaultPostProcessChain = TRUE; } // Use the default post process instead of the players if it been requested (usually when entering a pp volume) return (bForceDefaultPostProcessChain) ? GEngine->GetDefaultPostProcessChain() : PlayerPostProcess;}
在ULocalPlayer.UpdatePostProcessSettings 之前 调用他,为了获取最终后期链的相机相关开关
UPostProcessChain *ActivePostProccessChain = GetActivePostProccessChain(ViewLocation); // Update the player‘s post process settings. UpdatePostProcessSettings(ViewLocation);
此时需要去遍历后期链的Effect,每个调用一个更新相机相关的函数
需要添加虚函数
4 ue3DevelopmentSrcEngineClassesPostProcessEffect.uc
virtual UBOOL GetPPSettingsForCamera(const FRotator& ViewRotation,FPostProcessSettings& PPS) { }
ue3DevelopmentSrcEngineClassesUberPostProcessEffect.uc中重载
UBOOL UUberPostProcessEffect::GetPPSettingsForCamera(const FRotator& ViewRotation,FPostProcessSettings& PPS){ if (bUseNearCameraSettings) { FLOAT Alpha = (FLOAT)(NearCameraSettings.CameraPitchMax - ViewRotation.Pitch) / (FLOAT)(NearCameraSettings.CameraPitchMax -NearCameraSettings.CameraPitchMin); NearCameraSettings.Settings.OverrideSettingsFor(PPS,Alpha); } return bUseNearCameraSettings;}
5 UUberPostProcessEffect::GetPPSettingsForCamera
UBOOL UUberPostProcessEffect::GetPPSettingsForCamera(const FRotator& ViewRotation,FPostProcessSettings& PPS){ if (bUseNearCameraSettings) { FLOAT Alpha = (FLOAT)(NearCameraSettings.CameraPitchMax - ViewRotation.Pitch) / (FLOAT)(NearCameraSettings.CameraPitchMax -NearCameraSettings.CameraPitchMin); NearCameraSettings.Settings.OverrideSettingsFor(PPS,Alpha); } return bUseNearCameraSettings;}
6 ULocalPlayer.UpdateNearCamPP
void ULocalPlayer::UpdateNearCamPP(UPostProcessChain* PPC, const FRotator& ViewRotation){ if (PPC) { for (INT EffectIndex = 0; EffectIndex < PPC->Effects.Num(); EffectIndex++) { UPostProcessEffect* PPEffect = PPC->Effects(EffectIndex); FPostProcessSettings NewPPS; if (PPEffect && PPEffect->GetPPSettingsForCamera(ViewRotation,NewPPS)) { OverridePostProcessSettings(NewPPS); break; } } }}
ULocalPlayer.CalcSceneView 调用
UPostProcessChain *ActivePostProccessChain = GetActivePostProccessChain(ViewLocation); UpdateNearCamPP(ActivePostProccessChain,ViewRotation); // Update the player‘s post process settings. UpdatePostProcessSettings(ViewLocation);
- 只能修改UpdatePostProcessSettings函数了 添加参数
- 需要在函数中间去取PPsetinggs,中途再去用NearCamPPS去override
ULocalPlayer.UpdatePostProcessSettings 修改为
// CAMERA OVERRIDE // NOTE: Matinee works through this channel if(Actor && Actor->PlayerCamera && Actor->PlayerCamera->CamOverridePostProcessAlpha > 0.f) { //Blend the currently computed level settings with the camera‘s settings at the camera‘s alpha level Actor->PlayerCamera->CamPostProcessSettings.OverrideSettingsFor(CurrentPPInfo.LastSettings, Actor->PlayerCamera->CamOverridePostProcessAlpha); } // END CAMERA OVERRIDE // Near Camera PPS Blend OverridePPSettingsForCamera(PPC,ViewRotation,CurrentPPInfo.LastSettings);
- 必须开启UesWorldSettings开关才能使用,
- 也就是说不能依赖这个开关去应用Settings
- 后面如果需要程序直接控制DOF之类的还需要应用一套Settings
- ACamera.CamPostProcessSettings 还需存一套参数用于镜头的
- AWorldInfo.DefaultPostProcessSettings 也需要添加一套参数用于镜头的
- APostProcessVolume.Settings 还需存一套参数用于镜头的
- 如果没应用PPSettings,如何启用镜头相关?答:必须启用PPSettings
- 修改在FViewInfo.FViewInfo中处理PPSettings的方式
- 要将FAmbientOcclusionSettings 声明到uc中
- AO节点用FAmbientOcclusionSettings
- DOF节点用FDOFSettings
- 各自的CreateSceneProxy去计算相机相关,传递Setttings
struct native AOSettings{ var bool bOverride_LinearColor; var bool bOverride_OcclusionPower; var bool bOverride_OcclusionScale; var bool bOverride_OcclusionBias; var bool bOverride_MinOcclusion; var bool bOverride_OcclusionRadius; var bool bOverride_OcclusionQuality; var bool bOverride_OcclusionFadeoutMinDistance; var bool bOverride_OcclusionFadeoutMaxDistance; var bool bOverride_HaloDistanceThreshold; var bool bOverride_HaloDistanceScale; var bool bOverride_HaloOcclusion; var bool bOverride_EdgeDistanceThreshold; var bool bOverride_EdgeDistanceScale; var bool bOverride_FilterDistanceScale; var bool bOverride_HistoryOcclusionConvergenceTime; var bool bOverride_HistoryWeightConvergenceTime; var bool bOverride_bAngleBasedSSAO; //See AmbientOcclusionEffect.uc for descriptions var() LinearColor OcclusionColor<editcondition=bOverride_OcclusionColor>; var() float OcclusionPower<editcondition=bOverride_OcclusionPower>; var() float OcclusionScale<editcondition=OcclusionScale>; var() float OcclusionBias<editcondition=bOverride_OcclusionBias>; var() float MinOcclusion<editcondition=bOverride_MinOcclusion>; var() float OcclusionRadius<editcondition=bOverride_OcclusionRadius>; var() EAmbientOcclusionQuality OcclusionQuality<editcondition=bOverride_OcclusionQuality>; var() float OcclusionFadeoutMinDistance<editcondition=bOverride_OcclusionFadeoutMinDistance>; var() float OcclusionFadeoutMaxDistance<editcondition=bOverride_OcclusionFadeoutMaxDistance>; var() float HaloDistanceThreshold<editcondition=bOverride_HaloDistanceThreshold>; var() float HaloDistanceScale<editcondition=bOverride_HaloDistanceScale>; var() float HaloOcclusion<editcondition=bOverride_HaloOcclusion>; var() float EdgeDistanceThreshold<editcondition=bOverride_EdgeDistanceThreshold>; var() float EdgeDistanceScale<editcondition=bOverride_EdgeDistanceScale>; var() float FilterDistanceScale<editcondition=bOverride_FilterDistanceScale>; var() float HistoryOcclusionConvergenceTime<editcondition=bOverride_HistoryOcclusionConvergenceTime>; var() float HistoryWeightConvergenceTime<editcondition=bOverride_HistoryWeightConvergenceTime>; var() bool bAngleBasedSSAO<editcondition=bOverride_bAngleBasedSSAO>;structcpptext{}};struct native NearCameraAOSettings{ var() AOSettings Settings; var() INT CameraPitchMin; var() INT CameraPitchMax; structcpptext{ FNearCameraAOSettings(): CameraPitchMin(64626), CameraPitchMax(58800) { appMemzero(&Settings, sizeof(FPostProcessSettings)); }}};... var(Camera) bool bUseCamAOSettings;var(Camera) NearCameraAOSettings CamAOSettings<editcondition=bUseCamAOSettings>;
struct native DOFSetings{ /** Determines if DOF_FalloffExponent variable will be overridden. */ var bool bOverride_DOF_FalloffExponent; /** Determines if DOF_BlurKernelSize variable will be overridden. */ var bool bOverride_DOF_BlurKernelSize; /** Determines if DOF_BlurBloomKernelSize variable will be overridden. */ var bool bOverride_DOF_BlurBloomKernelSize; /** Determines if DOF_MaxNearBlurAmount variable will be overridden. */ var bool bOverride_DOF_MaxNearBlurAmount; /** Determines if DOF_MinBlurAmount variable will be overridden. */ var bool bOverride_DOF_MinBlurAmount;
/** Determines if DOF_MaxFarBlurAmount variable will be overridden. */ var bool bOverride_DOF_MaxFarBlurAmount; /** Determines if DOF_FocusType variable will be overridden. */ var bool bOverride_DOF_FocusType; /** Determines if DOF_FocusInnerRadius variable will be overridden. */ var bool bOverride_DOF_FocusInnerRadius; /** Determines if DOF_FocusDistance variable will be overridden. */ var bool bOverride_DOF_FocusDistance; /** Determines if DOF_FocusPosition variable will be overridden. */ var bool bOverride_DOF_FocusPosition; /** Determines if DOF_InterpolationDuration variable will be overridden. */ var bool bOverride_DOF_InterpolationDuration;
/** Determines if DOF_BokehTexture variable will be overridden. */ var bool bOverride_DOF_BokehTexture;
/** Exponent to apply to blur amount after it has been normalized to [0,1]. */ var(DepthOfField) interp float DOF_FalloffExponent<editcondition=bOverride_DOF_FalloffExponent>; /** affects the radius of the DepthOfField bohek / how blurry the scene gets */ var(DepthOfField) interp float DOF_BlurKernelSize<editcondition=bOverride_DOF_BlurKernelSize>; /** [0,1] value for clamping how much blur to apply to items in front of the focus plane. */ var(DepthOfField, BlurAmount) interp float DOF_MaxNearBlurAmount<editcondition=bOverride_DOF_MaxNearBlurAmount | DisplayName=MaxNear>; /** [0,1] value for clamping how much blur to apply. */ var(DepthOfField, BlurAmount) interp float DOF_MinBlurAmount<editcondition=bOverride_DOF_MinBlurAmount | DisplayName=Min>; /** [0,1] value for clamping how much blur to apply to items behind the focus plane. */ var(DepthOfField, BlurAmount) interp float DOF_MaxFarBlurAmount<editcondition=bOverride_DOF_MaxFarBlurAmount | DisplayName=MaxFar>; /** Controls how the focus point is determined. */ var(DepthOfField) EFocusType DOF_FocusType<editcondition=bOverride_DOF_FocusType>; /** Inner focus radius. */ var(DepthOfField) interp float DOF_FocusInnerRadius<editcondition=bOverride_DOF_FocusInnerRadius>; /** Used when FOCUS_Distance is enabled. */ var(DepthOfField) interp float DOF_FocusDistance<editcondition=bOverride_DOF_FocusDistance>; /** Used when FOCUS_Position is enabled. */ var(DepthOfField) vector DOF_FocusPosition<editcondition=bOverride_DOF_FocusPosition>; /** Duration over which to interpolate values to. */ var(DepthOfField) float DOF_InterpolationDuration<editcondition=bOverride_DOF_InterpolationDuration>; /** Name of the Bokeh texture e.g. EngineMaterial.BokehTexture, empty if not used */ var(DepthOfField) Texture2D DOF_BokehTexture<editcondition=bOverride_DOF_BokehTexture>;
};
struct native NearCameraDOFSettings{ var() DOFSetings Settings; var() INT CameraPitchMin; var() INT CameraPitchMax; structcpptext{ FNearCameraDOFSettings(): CameraPitchMin(64626), CameraPitchMax(58800) { }}};
var(Camera) bool bUseCamDOFSettings;var(Camera) NearCameraDOFSettings CamDOFSettings<editcondition=bUseCamDOFSettings>;
struct native NearCameraAOSettings{... void OverrideSettings(const FCameraInfo& CI,FAOSettings& Settings);
structcpptext{ /** * Blends the settings on this structure marked as override setting onto the given settings * * @param ToOverride The settings that get overridden by the overridable settings on this structure. * @param Alpha The opacity of these settings. If Alpha is 1, ToOverride will equal this setting structure. */ void OverrideSettingsFor( FAOSettings& ToOverride, FLOAT Alpha=1.f ) const;}
struct native DepthOfFieldSettings{ var float FalloffExponent; var float BlurKernelSize; var float MaxNearBlurAmount; var float MinBlurAmount; var float MaxFarBlurAmount; var EFocusType FocusType; var float FocusInnerRadius; var float FocusDistance; var vector FocusPosition; var float InterpolationDuration;};
FDepthOfFieldSettings DOFProperty;// FLOAT FalloffExponent;// FLOAT BlurKernelSize; FLOAT BlurBloomKernelSize;// FLOAT MaxNearBlurAmount;// FLOAT MinBlurAmount;// FLOAT MaxFarBlurAmount;// BYTE FocusType;// FLOAT FocusInnerRadius;// FLOAT FocusDistance;// FVector FocusPosition;
// SET_POSTPROCESS_PROPERTY1(DOF, FalloffExponent); SET_POSTPROCESS_PROPERTY1(DOF, BlurKernelSize);// SET_POSTPROCESS_PROPERTY1(DOF, BlurBloomKernelSize);// SET_POSTPROCESS_PROPERTY1(DOF, MaxNearBlurAmount);// SET_POSTPROCESS_PROPERTY1(DOF, MinBlurAmount);// SET_POSTPROCESS_PROPERTY1(DOF, MaxFarBlurAmount);// SET_POSTPROCESS_PROPERTY1(DOF, FocusType);// SET_POSTPROCESS_PROPERTY1(DOF, FocusInnerRadius);// SET_POSTPROCESS_PROPERTY1(DOF, FocusDistance);// SET_POSTPROCESS_PROPERTY1(DOF, FocusPosition); SET_POSTPROCESS_PROPERTY1(DOF, BokehTexture); SET_POSTPROCESS_DOFPROPERTY(DOF, FalloffExponent); SET_POSTPROCESS_DOFPROPERTY(DOF, BlurKernelSize); SET_POSTPROCESS_DOFPROPERTY(DOF, BlurBloomKernelSize); SET_POSTPROCESS_DOFPROPERTY(DOF, MaxNearBlurAmount); SET_POSTPROCESS_DOFPROPERTY(DOF, MinBlurAmount); SET_POSTPROCESS_DOFPROPERTY(DOF, MaxFarBlurAmount); SET_POSTPROCESS_DOFPROPERTY(DOF, FocusType); SET_POSTPROCESS_DOFPROPERTY(DOF, FocusInnerRadius); SET_POSTPROCESS_DOFPROPERTY(DOF, FocusDistance); SET_POSTPROCESS_DOFPROPERTY(DOF, FocusPosition);... // clamp DOF radius in reasonable bound DOFProperty.BlurKernelSize = Clamp(DOFProperty.BlurKernelSize, 0.0f, 128.0f);
#define LERP_DOFSETTINGS(Name) if( bOverride_##Name ) { ToOverride.##Name = Lerp(ToOverride.##Name, ##Name, Alpha); }void FDOFSetings::OverrideSettingsFor( FDepthOfFieldSettings& ToOverride, FLOAT Alpha=1.f) const{ // TOGGLE OVERRIDES if (Alpha <= 0.0f) { return; } LERP_DOFSETTINGS(FalloffExponent); LERP_DOFSETTINGS(BlurKernelSize); LERP_DOFSETTINGS(MaxNearBlurAmount); LERP_DOFSETTINGS(MinBlurAmount); LERP_DOFSETTINGS(MaxFarBlurAmount); LERP_DOFSETTINGS(FocusType); LERP_DOFSETTINGS(FocusInnerRadius); LERP_DOFSETTINGS(FocusDistance); LERP_DOFSETTINGS(FocusPosition); LERP_DOFSETTINGS(InterpolationDuration);}
void FNearCameraDOFSettings::OverrideSettings(const FCameraInfo& CI,FDepthOfFieldSettings& ToOverride) const{ FLOAT DistanceAlpha = 1.f; FLOAT PitchAlpha = 1.f; UBOOL bOveriride = FALSE; if (CameraInfoMin.bEdit_CameraDistance && CameraInfoMax.bEdit_CameraDistance) { DistanceAlpha = (CameraInfoMax.CameraDistance - CI.CameraDistance) / (CameraInfoMax.CameraDistance - CameraInfoMin.CameraDistance); bOveriride = TRUE; } if (CameraInfoMin.bEdit_CameraPitch && CameraInfoMax.bEdit_CameraPitch) { PitchAlpha = (CameraInfoMax.CameraPitch - CI.CameraPitch) / (CameraInfoMax.CameraPitch - CameraInfoMin.CameraPitch); bOveriride = TRUE; } if (bOveriride) { FLOAT Alpha = Min(DistanceAlpha,PitchAlpha); Settings.OverrideSettingsFor(ToOverride,Alpha); }}
Params.FalloffExponent = DOFProperty.FalloffExponent; Params.MaxNearBlurAmount = DOFProperty.MaxNearBlurAmount; Params.MinBlurAmount = DOFProperty.MinBlurAmount; Params.MaxFarBlurAmount = DOFProperty.MaxFarBlurAmount;
switch( DOFProperty.FocusType ) { case FOCUS_Position: { // world space focus point specified projected onto the view direction FocusPoint = (((DOFProperty.FocusPosition - View.ViewOrigin) | ViewDir) * ViewDir) + View.ViewOrigin; } break; case FOCUS_Distance: default: { // focus point based on view distance FocusPoint = (DOFProperty.FocusDistance * ViewDir) + View.ViewOrigin; } break; }; // transform to projected/clip space in order to get w depth values OutFocusDistance = Max<FLOAT>(0.f, View.WorldToScreen(FocusPoint).W); // Add radius to get the far focus point FVector FocusPointFar = (ViewDir * DOFProperty.FocusInnerRadius) + FocusPoint; FLOAT FocusDistanceFar = Max<FLOAT>(OutFocusDistance, View.WorldToScreen(FocusPointFar).W); OutFocusRadius = Max<FLOAT>((FLOAT)KINDA_SMALL_NUMBER, Abs<FLOAT>(FocusDistanceFar - OutFocusDistance));
GaussianBlurFilterBuffer(View, View.SizeX, DownsampledSizeX + AntiLeakBorder, DownsampledSizeY + AntiLeakBorder, DOFProperty.BlurKernelSize, 1.0f, SRTI_FilterColor0, SampleMaskMin, SampleMaskMax);... BlendPixelShader->PostProcessParameters.SetPS(*BlendPixelShader, DOFProperty.BlurKernelSize, DOFOcclusionTweak);
if (InEffect->bUseCamDOFSettings) InEffect->CamDOFSettings.OverrideSettings(CI,DOFProperty);
FCameraInfo CI; CI.bEdit_CameraPitch = TRUE; CI.CameraPitch = GCameraRotation.Pitch; FPostProcessSceneProxy* PostProcessSceneProxy = Effect->CreateSceneProxy( PostProcessSettings && Effect->bUseWorldSettings ? PostProcessSettings : NULL,CI );
inline INT ShortestRoute(INT Angle){ Angle = Angle & 65535; if(Angle >= 32768) Angle -= 65536; return Angle;
}
INT Max = ShortestRoute(CameraInfoMax.CameraPitch); INT Min = ShortestRoute(CameraInfoMin.CameraPitch); INT Cur = ShortestRoute(CI.CameraPitch); PitchAlpha = (FLOAT)(Max -Cur) / (FLOAT)(Max - Min);
- 上面只是节点上的相机参数融合
- 还有PPSettings还没有处理
- 添加一个PostProcessSettings作为相机参数
- AWorldInfo.GetPostProcessSettings 中处理Override
var(Camera) bool bUseCamDOFSettings;var(Camera) NearCameraDOFSettings CamDOFSettings<editcondition=bUseCamDOFSettings>;var(Camera) bool bUseCamAOSettings;var(Camera) NearCameraAOSettings CamAOSettings<editcondition=bUseCamAOSettings>;
if (CurrentWorldInfo->bUseCamDOFSettings) { FCameraInfo CI(TRUE,FALSE,ViewRotation.Pitch,0.f);; CurrentWorldInfo->CamDOFSettings.OverrideSettings(CI,OutPostProcessSettings); } if (CurrentWorldInfo->bUseCamAOSettings) { FCameraInfo CI(TRUE,FALSE,ViewRotation.Pitch,0.f);; CurrentWorldInfo->CamAOSettings.OverrideSettings(CI,OutPostProcessSettings); }
【运行】
3
!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>!--WizRtf2Html>
以上是关于17032002(动态AO DOF)的主要内容,如果未能解决你的问题,请参考以下文章