모션블러 속도에 따라 선형적으로 블러되게끔 변

This commit is contained in:
kimnuri
2026-01-29 18:05:14 +09:00
parent b6b64a701c
commit 1dd48f1c9f
6 changed files with 42 additions and 37 deletions
@@ -600,7 +600,7 @@ float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos, float fIn
float2 velocityUV = (currentNDC - previousNDC) * 0.5f;
velocityUV *= fIntensity;
velocityUV = clamp(velocityUV, -1.0f, 1.0f);
length(velocityUV);
return velocityUV * 0.5f + 0.5f; // 0 속도 -> 0.5
}
float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos)
@@ -82,7 +82,7 @@ Texture2D g_TileVelocityTexture;
int g_iMBSampleCount;
int g_iMBMaxSampleCount;
float g_fMBBlurRadius;
float g_fMBMaxBlurRadius;
int g_iMBType;
int g_iMBTileSize;
float g_fMBSampleBias;
@@ -254,8 +254,8 @@ struct PS_OUT_SSAO_BLUR
// g_fFar
// g_fMBSampleBias
// g_fMBBlurRadius
// g_iMBSampleCount
// g_iMBMaxSampleCount
// g_iMBSampleCount 실제 현재 프레임 모션블러 픽셀
// g_iMBMaxSampleCount 허용가능한 모션블러 픽셀
// g_iMBType
PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
{
@@ -269,9 +269,9 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
bool bBorrowedVelocityFromTile = false;
float2 vBlurVelo = vCenterVelo;
float2 vBlurVeloPixel = vCenterVeloPixel;
float2 vBlurVeloPixel = vCenterVeloPixel; // 프레임당 픽셀 이동량
float fVelocityEpsilon = 30.f;
float fVelocityEpsilon = 0.5f;
if (length(vBlurVeloPixel) < fVelocityEpsilon)
{
@@ -287,28 +287,30 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
float fPixelSpeed = length(vBlurVeloPixel);
float2 vBlurDirPixel = (vBlurVeloPixel / max(length(vBlurVeloPixel), FLT_EPSILON5));
int iMaxRadius = min(g_iMBSampleCount, g_iMBMaxSampleCount);
float2 vBlurDirPixel = (vBlurVeloPixel / max(fPixelSpeed, FLT_EPSILON5));
// 픽셀별 블러 반경 (핵심)
float fBlurRadiusPixel = clamp(fPixelSpeed * 0.4f , 0.f, g_fMBMaxBlurRadius);
fBlurRadiusPixel = max(fBlurRadiusPixel, 1.f);
int iMaxRadius = (int)ceil(fBlurRadiusPixel);
iMaxRadius = clamp(iMaxRadius, 1, min(g_iMBSampleCount, g_iMBMaxSampleCount));
// 샘플링 당 이동 픽셀
float fSamplePixelSpeed = g_fMBBlurRadius / max((float) iMaxRadius, 1.f);
float fSamplePixelSpeed = fBlurRadiusPixel / max((float) iMaxRadius, 1.f);
// 샘플유닛의 크기
float fScalePixelToSampleUnit = (float) iMaxRadius / max(g_fMBBlurRadius, FLT_EPSILON5);
float fScalePixelToSampleUnit = (float) iMaxRadius / max(fBlurRadiusPixel, FLT_EPSILON5);
float fScaleDepth = 0.5f / max(g_fMBSampleBias, FLT_EPSILON5);
float4 vAccColorSum = float4(0.f, 0.f, 0.f, 0.f);
float2 vAccVeloSum = float2(0.f, 0.f);
float fAccWeight = 0.f;
// 센터의 스프레드 길이
float2 vReferenceVelocityPixel = vCenterVeloPixel;
if (true == bBorrowedVelocityFromTile)
{
vReferenceVelocityPixel = vBlurVeloPixel;
}
float fCenterSpreadLengthPixel = clamp(abs(dot(vReferenceVelocityPixel, vBlurDirPixel)), 0.f, g_fMBBlurRadius);
float2 vReferenceVelocityPixel = bBorrowedVelocityFromTile ? vBlurVeloPixel : vCenterVeloPixel; // 빌린놈이면 빌린 타일이 속도 레퍼런스, 아니면 센터가 속도 레퍼런스가 됨
float fCenterSpreadLengthPixel = clamp(abs(dot(vReferenceVelocityPixel, vBlurDirPixel)), 0.f, fBlurRadiusPixel); //
[loop]
for (int iInterval = -iMaxRadius; iInterval <= iMaxRadius; ++iInterval) {
float fOffset = (float) abs(iInterval);
@@ -324,7 +326,7 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
// 샘플의 스프레드 길이
float fBlurSampleAccurate = abs(dot(vSampledVeloPixel, vBlurDirPixel));
float fSampleSpreadLengthPixel = clamp(fBlurSampleAccurate, 0.f, g_fMBBlurRadius);
float fSampleSpreadLengthPixel = clamp(fBlurSampleAccurate, 0.f, fBlurRadiusPixel);
if (true == bBorrowedVelocityFromTile)
{
fSampleSpreadLengthPixel = max(fSampleSpreadLengthPixel, fCenterSpreadLengthPixel);
@@ -355,6 +357,7 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
Out.vVelocity = vBlurredVelo * 0.5f + 0.5f;
return Out;
}
PS_OUT_VELOCITYTILE PS_MOTIONBLUR_TILESAMPLE(PS_IN In)
{
PS_OUT_VELOCITYTILE Out = (PS_OUT_VELOCITYTILE) 0;
@@ -82,7 +82,7 @@ Texture2D g_TileVelocityTexture;
int g_iMBSampleCount;
int g_iMBMaxSampleCount;
float g_fMBBlurRadius;
float g_fMBMaxBlurRadius;
int g_iMBType;
int g_iMBTileSize;
float g_fMBSampleBias;
@@ -254,8 +254,8 @@ struct PS_OUT_SSAO_BLUR
// g_fFar
// g_fMBSampleBias
// g_fMBBlurRadius
// g_iMBSampleCount
// g_iMBMaxSampleCount
// g_iMBSampleCount 실제 현재 프레임 모션블러 픽셀
// g_iMBMaxSampleCount 허용가능한 모션블러 픽셀
// g_iMBType
PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
{
@@ -269,7 +269,7 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
bool bBorrowedVelocityFromTile = false;
float2 vBlurVelo = vCenterVelo;
float2 vBlurVeloPixel = vCenterVeloPixel;
float2 vBlurVeloPixel = vCenterVeloPixel; // 프레임당 픽셀 이동량
float fVelocityEpsilon = 0.5f;
@@ -287,28 +287,30 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
float fPixelSpeed = length(vBlurVeloPixel);
float2 vBlurDirPixel = (vBlurVeloPixel / max(length(vBlurVeloPixel), FLT_EPSILON5));
int iMaxRadius = min(g_iMBSampleCount, g_iMBMaxSampleCount);
float2 vBlurDirPixel = (vBlurVeloPixel / max(fPixelSpeed, FLT_EPSILON5));
// 픽셀별 블러 반경 (핵심)
float fBlurRadiusPixel = clamp(fPixelSpeed * 0.4f , 0.f, g_fMBMaxBlurRadius);
fBlurRadiusPixel = max(fBlurRadiusPixel, 1.f);
int iMaxRadius = (int)ceil(fBlurRadiusPixel);
iMaxRadius = clamp(iMaxRadius, 1, min(g_iMBSampleCount, g_iMBMaxSampleCount));
// 샘플링 당 이동 픽셀
float fSamplePixelSpeed = g_fMBBlurRadius / max((float) iMaxRadius, 1.f);
float fSamplePixelSpeed = fBlurRadiusPixel / max((float) iMaxRadius, 1.f);
// 샘플유닛의 크기
float fScalePixelToSampleUnit = (float) iMaxRadius / max(g_fMBBlurRadius, FLT_EPSILON5);
float fScalePixelToSampleUnit = (float) iMaxRadius / max(fBlurRadiusPixel, FLT_EPSILON5);
float fScaleDepth = 0.5f / max(g_fMBSampleBias, FLT_EPSILON5);
float4 vAccColorSum = float4(0.f, 0.f, 0.f, 0.f);
float2 vAccVeloSum = float2(0.f, 0.f);
float fAccWeight = 0.f;
// 센터의 스프레드 길이
float2 vReferenceVelocityPixel = vCenterVeloPixel;
if (true == bBorrowedVelocityFromTile)
{
vReferenceVelocityPixel = vBlurVeloPixel;
}
float fCenterSpreadLengthPixel = clamp(abs(dot(vReferenceVelocityPixel, vBlurDirPixel)), 0.f, g_fMBBlurRadius);
float2 vReferenceVelocityPixel = bBorrowedVelocityFromTile ? vBlurVeloPixel : vCenterVeloPixel; // 빌린놈이면 빌린 타일이 속도 레퍼런스, 아니면 센터가 속도 레퍼런스가 됨
float fCenterSpreadLengthPixel = clamp(abs(dot(vReferenceVelocityPixel, vBlurDirPixel)), 0.f, fBlurRadiusPixel); //
[loop]
for (int iInterval = -iMaxRadius; iInterval <= iMaxRadius; ++iInterval) {
float fOffset = (float) abs(iInterval);
@@ -324,7 +326,7 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLUR(PS_IN In)
// 샘플의 스프레드 길이
float fBlurSampleAccurate = abs(dot(vSampledVeloPixel, vBlurDirPixel));
float fSampleSpreadLengthPixel = clamp(fBlurSampleAccurate, 0.f, g_fMBBlurRadius);
float fSampleSpreadLengthPixel = clamp(fBlurSampleAccurate, 0.f, fBlurRadiusPixel);
if (true == bBorrowedVelocityFromTile)
{
fSampleSpreadLengthPixel = max(fSampleSpreadLengthPixel, fCenterSpreadLengthPixel);
+1 -1
View File
@@ -1052,7 +1052,7 @@ void CRenderer::Render_PostProcessing()
if (FAILED(m_pShader->Bind_RawValue("g_fFar", m_pGameInstance->Get_CurrentCameraFar(), sizeof(_float)))) {
assert(false); return;
}
if (FAILED(m_pShader->Bind_RawValue("g_fMBBlurRadius", &m_fMBBlurRadius, sizeof(_float)))) {
if (FAILED(m_pShader->Bind_RawValue("g_fMBMaxBlurRadius", &m_fMBMaxBlurRadius, sizeof(_float)))) {
assert(false); return;
}
if (FAILED(m_pShader->Bind_RawValue("g_fMBSampleBias", &m_fMBSampleBias, sizeof(_float)))) {
@@ -683,7 +683,7 @@ void CRenderer::Describe_Entitiy()
if (GUI::CollapsingHeader("MotionBlurr")) {
GUI::Checkbox("m_bMB", &m_bMB);
GUI::SliderFloat("g_fMBSampleBias", &m_fMBSampleBias, -1.f, 1.f, "%.3f");
GUI::SliderFloat("g_fMBBlurRadius", &m_fMBBlurRadius, 0.1f, (_float)m_iMBMaxSampleCount, "%.1f");
GUI::SliderFloat("m_fMBMaxBlurRadius", &m_fMBMaxBlurRadius, 0.1f, (_float)m_iMBMaxSampleCount, "%.1f");
GUI::SliderInt("g_iMBSampleCount", &m_iMBSampleCount, 0, m_iMBMaxSampleCount, "%d");
}
if (GUI::CollapsingHeader("End_Padding")) {
+1 -1
View File
@@ -81,7 +81,7 @@ class CRenderer final : public CBase
_float m_fMinShadowBrightness = { 0.47f };
// MotionBlur
_float m_fMBBlurRadius = { 28.f };
_float m_fMBMaxBlurRadius = { 28.f };
_float m_fMBSampleBias = { 0.005f };
_int m_iMBMaxSampleCount = { 28 };
_int m_iMBSampleCount = { m_iMBMaxSampleCount };