标签:weight front rar 编辑器 lam oca 初始 9.png 中间
【目标】
摄像机相关的AO DOF
【思路】
1 方案1:
2 方案2:
4 整个后期数据流程:
5 主要的数据控制在ULocalPlayer中
6 Blend计算
10 高中低配置方案:
11 相机相关后期方案:
12 问题:在平视角 但是需要远景时怎么办(如Matineee中)?
13 在ULocalPlayer 中有个后期链列表
14 问题:对话 主角界面这种使用PPSettings还是后期链?
【步骤】
1 修改\ue3\Development\Src\Engine\Classes\UberPostProcessEffect.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 \ue3\Development\Src\Engine\Classes\PostProcessEffect.uc
virtual UBOOL GetPPSettingsForCamera(const FRotator& ViewRotation,FPostProcessSettings& PPS) { }
ue3\Development\Src\Engine\Classes\UberPostProcessEffect.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);
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);
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);
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
标签:weight front rar 编辑器 lam oca 初始 9.png 中间
原文地址:https://www.cnblogs.com/username/p/9223927.html