diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Engine_Shader_Functions.hlsli b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Engine_Shader_Functions.hlsli index 7a38a5cd2..24768db46 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Engine_Shader_Functions.hlsli +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Engine_Shader_Functions.hlsli @@ -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) diff --git a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl index 169f02e32..edbfa7382 100644 --- a/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl +++ b/Jusin154_Team3D/Editor/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl @@ -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; diff --git a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl index 931e5b96a..edbfa7382 100644 --- a/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl +++ b/Jusin154_Team3D/Engine/Bin/Resources/ShaderFiles/Shader_Deferred.hlsl @@ -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); diff --git a/Jusin154_Team3D/Engine/Private/Renderer.cpp b/Jusin154_Team3D/Engine/Private/Renderer.cpp index 6604f3181..33c559975 100644 --- a/Jusin154_Team3D/Engine/Private/Renderer.cpp +++ b/Jusin154_Team3D/Engine/Private/Renderer.cpp @@ -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)))) { diff --git a/Jusin154_Team3D/Engine/Private/Renderer_Declare.cpp b/Jusin154_Team3D/Engine/Private/Renderer_Declare.cpp index 0931ce662..1cb081e09 100644 --- a/Jusin154_Team3D/Engine/Private/Renderer_Declare.cpp +++ b/Jusin154_Team3D/Engine/Private/Renderer_Declare.cpp @@ -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")) { diff --git a/Jusin154_Team3D/Engine/Public/Renderer.h b/Jusin154_Team3D/Engine/Public/Renderer.h index e2a9582f7..8db80b6ce 100644 --- a/Jusin154_Team3D/Engine/Public/Renderer.h +++ b/Jusin154_Team3D/Engine/Public/Renderer.h @@ -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 };