[add] 모션 블러 추가 ( 방향성은 아직)

This commit is contained in:
kimnuri
2025-12-19 01:27:59 +09:00
parent 512da5fa14
commit 52389d8087
7 changed files with 111 additions and 63 deletions
@@ -231,7 +231,7 @@ float3 DecodeNormalFromRG(Texture2D NormalMap, SamplerState Samp, float2 uv)
// BackGround ForeGround 합은 1
float2 DepthCompare(float fCenterDepth, float fSampleDepth, float fDepthScale)
{
return saturate(0.5f + float2(fDepthScale, -fDepthScale) * (fSampleDepth - fCenterDepth));
return saturate(0.5f + 0.5f + 0.5f*(float2(fDepthScale, -fDepthScale) * (fSampleDepth - fCenterDepth)));
}
float2 SpreadCompare(float fOffsetLength, float2 fSpreadLength, float fPixelToSampleUnitsScale)
@@ -468,20 +468,25 @@ float4 BlendDiffuse(float4 vDiffuseA, Texture2D DiffuseBlendTexture, float2 vTex
return lerp(vDiffuseA, vDiffuseBlendColor, fRatio);
}
float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos)
float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos, float fIntensity = 1.f)
{
if (vCurrentProjPos.w <= FLT_EPSILON5 || vPreviousProjPos.w <= FLT_EPSILON5) {
return float2(0.0f, 0.0f);
if (vCurrentProjPos.w <= FLT_EPSILON5 || vPreviousProjPos.w <= FLT_EPSILON5)
{
return float2(0.5f, 0.5f);
}
float2 currentUV = (vCurrentProjPos.xy/vCurrentProjPos.w);
float2 previousUV = (vPreviousProjPos.xy / vCurrentProjPos.w);
float2 currentNDC = vCurrentProjPos.xy / vCurrentProjPos.w;
float2 previousNDC = vPreviousProjPos.xy / vPreviousProjPos.w;
currentUV.y *= -1.f;
previousUV.y *= -1.f;
return (currentUV - previousUV) * 0.5f + 0.5f;
currentNDC.y *= -1.f;
previousNDC.y *= -1.f;
// UV 델타
float2 velocityUV = (currentNDC - previousNDC) * 0.5f;
velocityUV *= fIntensity;
velocityUV = clamp(velocityUV, -1.0f, 1.0f);
return velocityUV * 0.5f + 0.5f; // 0 속도 -> 0.5
}
float3 DownSampleFast(Texture2D SrcTexture2D, float2 vCenterTexcoord, float2 vSrcTexelSize, float2 vResolution)
@@ -75,6 +75,7 @@ Texture2D g_ColorTexture;
Texture2D g_VelocityTexture;
int g_iMBSampleCount;
int g_iMBMaxSampleCount;
float g_fMBBlurRadius;
int g_iMBType;
float g_fMBSampleBias;
@@ -233,8 +234,9 @@ struct PS_OUT_SSAO_BLUR
// g_fFar
// g_fMBSampleBias
// g_fMBBlurRadius
// g_iMBType
// g_iMBSampleCount
// g_iMBMaxSampleCount
// g_iMBType
PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
{
PS_OUT_VELOCITYBLUR Out = (PS_OUT_VELOCITYBLUR) 0;
@@ -249,12 +251,12 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
float fSampleSpreadLength;
float2 uv = In.vTexcoord;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y * g_fFar; // 해당 셀의 깊이
float2 vCenterVelocityUV = g_VelocityTexture.Sample(PointSampler, uv).xy;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y; // 해당 셀의 깊이
float2 vCenterVelocityUV = (g_VelocityTexture.Sample(PointSampler, uv).xy * 2.f - 1.f);
float2 vCenterVelocityPixels = vCenterVelocityUV * g_vResolution.xy; // UV -> 픽셀
float fCenterSpreadLength = clamp(abs(vCenterVelocityPixels.x), 0.0f, g_fMBBlurRadius);
float2 vSrcTexelSize = float2(1.f / g_vResolution.x, 1.f / g_vResolution.y); // 소스 셀 사이즈 g_vResolution-> 현재는 colortexture 해상도
int iMaxMotionBlurSampleCount = min(g_iMBSampleCount, 7); /* 최대 속도 */
int iMaxMotionBlurSampleCount = min(g_iMBSampleCount, g_iMBMaxSampleCount); /* 최대 속도 */
float fPixelToSampleUnitsScale = (float) iMaxMotionBlurSampleCount / max(g_fMBBlurRadius, FLT_EPSILON5);
float fDepthScale = 0.5f / max(g_fMBSampleBias, FLT_EPSILON5);
@@ -273,8 +275,8 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
continue;
}
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y * g_fFar;
vSampledVelocityUV = g_VelocityTexture.Sample(PointSampler, vDestUV).xy;
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y;
vSampledVelocityUV = (g_VelocityTexture.Sample(PointSampler, vDestUV).xy * 2.f - 1.f);
vSampledVelocityPixels = vSampledVelocityUV * g_vResolution.xy;
fSampleSpreadLength = clamp(abs(vSampledVelocityPixels.x), 0.0f, g_fMBBlurRadius);
@@ -296,9 +298,17 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
float fTapCount = (float) (2 * iMaxMotionBlurSampleCount + 1);
float fCoverage = saturate(fWeight / max(fTapCount, 1.0f));
Out.vColor = float4(vBlurColor.rgb, fCoverage);
//Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity;
//Out.vColor = float4(vBlurColor.rgb, fCoverage);
Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity * 0.5f + 0.5f;
float2 vBlurVelocityPixels = vBlurVelocity * g_vResolution.xy;
if (length(vBlurVelocityPixels) < 0.5f) // 0.5px 이하면 정지 취급
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, uv);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
return Out;
}
PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
@@ -315,8 +325,8 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
float fSampleSpreadLength;
float2 uv = In.vTexcoord;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y * g_fFar; // 해당 셀의 깊이
float2 vCenterVelocityUV = g_VelocityTexture.Sample(PointSampler, uv).xy;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y; // 해당 셀의 깊이
float2 vCenterVelocityUV = (g_VelocityTexture.Sample(PointSampler, uv).xy * 2.f - 1.f);
float2 vCenterVelocityPixels = vCenterVelocityUV * g_vResolution.xy; // UV -> 픽셀
float fCenterSpreadLength = clamp(abs(vCenterVelocityPixels.y), 0.0f, g_fMBBlurRadius);
float2 vSrcTexelSize = float2(1.f / g_vResolution.x, 1.f / g_vResolution.y); // 소스 셀 사이즈 g_vResolution-> 현재는 colortexture 해상도
@@ -339,15 +349,14 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
continue;
}
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y * g_fFar;
vSampledVelocityUV = g_VelocityTexture.Sample(PointSampler, vDestUV).xy;
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y;
vSampledVelocityUV = (g_VelocityTexture.Sample(PointSampler, vDestUV).xy * 2.f - 1.f);
vSampledVelocityPixels = vSampledVelocityUV * g_vResolution.xy;
fSampleSpreadLength = clamp(abs(vSampledVelocityPixels.y), 0.0f, g_fMBBlurRadius);
// [Sample]
float fWeightCalculated = SampleWeight(fCenterDepth, fSampledDepth, float(abs(i)), fCenterSpreadLength, fSampleSpreadLength, fPixelToSampleUnitsScale, fDepthScale);
if (fWeightCalculated <= 0.0f)
{
if (fWeightCalculated <= 0.0f) {
continue;
}
vSampledColor = g_ColorTexture.Sample(ClampLinearSampler, vDestUV);
@@ -362,9 +371,17 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
float fTapCount = (float) (2 * iMaxMotionBlurSampleCount + 1);
float fCoverage = saturate(fWeight / max(fTapCount, 1.0f));
Out.vColor = float4(vBlurColor.rgb, fCoverage);
//Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity;
//Out.vColor = float4(vBlurColor.rgb, fCoverage);
Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity * 0.5f + 0.5f;
float2 vBlurVelocityPixels = vBlurVelocity * g_vResolution.xy;
if (length(vBlurVelocityPixels) < 0.5f) // 0.5px 이하면 정지 취급
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, uv);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
return Out;
}
PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
@@ -231,7 +231,7 @@ float3 DecodeNormalFromRG(Texture2D NormalMap, SamplerState Samp, float2 uv)
// BackGround ForeGround 합은 1
float2 DepthCompare(float fCenterDepth, float fSampleDepth, float fDepthScale)
{
return saturate(0.5f + float2(fDepthScale, -fDepthScale) * (fSampleDepth - fCenterDepth));
return saturate(0.5f + 0.5f + 0.5f*(float2(fDepthScale, -fDepthScale) * (fSampleDepth - fCenterDepth)));
}
float2 SpreadCompare(float fOffsetLength, float2 fSpreadLength, float fPixelToSampleUnitsScale)
@@ -468,20 +468,25 @@ float4 BlendDiffuse(float4 vDiffuseA, Texture2D DiffuseBlendTexture, float2 vTex
return lerp(vDiffuseA, vDiffuseBlendColor, fRatio);
}
float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos)
float2 CalcVelocityUV(float4 vCurrentProjPos, float4 vPreviousProjPos, float fIntensity = 1.f)
{
if (vCurrentProjPos.w <= FLT_EPSILON5 || vPreviousProjPos.w <= FLT_EPSILON5) {
return float2(0.0f, 0.0f);
if (vCurrentProjPos.w <= FLT_EPSILON5 || vPreviousProjPos.w <= FLT_EPSILON5)
{
return float2(0.5f, 0.5f);
}
float2 currentUV = (vCurrentProjPos.xy/vCurrentProjPos.w);
float2 previousUV = (vPreviousProjPos.xy / vCurrentProjPos.w);
float2 currentNDC = vCurrentProjPos.xy / vCurrentProjPos.w;
float2 previousNDC = vPreviousProjPos.xy / vPreviousProjPos.w;
currentUV.y *= -1.f;
previousUV.y *= -1.f;
return (currentUV - previousUV) * 0.5f + 0.5f;
currentNDC.y *= -1.f;
previousNDC.y *= -1.f;
// UV 델타
float2 velocityUV = (currentNDC - previousNDC) * 0.5f;
velocityUV *= fIntensity;
velocityUV = clamp(velocityUV, -1.0f, 1.0f);
return velocityUV * 0.5f + 0.5f; // 0 속도 -> 0.5
}
float3 DownSampleFast(Texture2D SrcTexture2D, float2 vCenterTexcoord, float2 vSrcTexelSize, float2 vResolution)
@@ -75,6 +75,7 @@ Texture2D g_ColorTexture;
Texture2D g_VelocityTexture;
int g_iMBSampleCount;
int g_iMBMaxSampleCount;
float g_fMBBlurRadius;
int g_iMBType;
float g_fMBSampleBias;
@@ -233,8 +234,9 @@ struct PS_OUT_SSAO_BLUR
// g_fFar
// g_fMBSampleBias
// g_fMBBlurRadius
// g_iMBType
// g_iMBSampleCount
// g_iMBMaxSampleCount
// g_iMBType
PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
{
PS_OUT_VELOCITYBLUR Out = (PS_OUT_VELOCITYBLUR) 0;
@@ -249,12 +251,12 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
float fSampleSpreadLength;
float2 uv = In.vTexcoord;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y * g_fFar; // 해당 셀의 깊이
float2 vCenterVelocityUV = g_VelocityTexture.Sample(PointSampler, uv).xy;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y; // 해당 셀의 깊이
float2 vCenterVelocityUV = (g_VelocityTexture.Sample(PointSampler, uv).xy * 2.f - 1.f);
float2 vCenterVelocityPixels = vCenterVelocityUV * g_vResolution.xy; // UV -> 픽셀
float fCenterSpreadLength = clamp(abs(vCenterVelocityPixels.x), 0.0f, g_fMBBlurRadius);
float2 vSrcTexelSize = float2(1.f / g_vResolution.x, 1.f / g_vResolution.y); // 소스 셀 사이즈 g_vResolution-> 현재는 colortexture 해상도
int iMaxMotionBlurSampleCount = min(g_iMBSampleCount, 7); /* 최대 속도 */
int iMaxMotionBlurSampleCount = min(g_iMBSampleCount, g_iMBMaxSampleCount); /* 최대 속도 */
float fPixelToSampleUnitsScale = (float) iMaxMotionBlurSampleCount / max(g_fMBBlurRadius, FLT_EPSILON5);
float fDepthScale = 0.5f / max(g_fMBSampleBias, FLT_EPSILON5);
@@ -273,8 +275,8 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
continue;
}
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y * g_fFar;
vSampledVelocityUV = g_VelocityTexture.Sample(PointSampler, vDestUV).xy;
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y;
vSampledVelocityUV = (g_VelocityTexture.Sample(PointSampler, vDestUV).xy * 2.f - 1.f);
vSampledVelocityPixels = vSampledVelocityUV * g_vResolution.xy;
fSampleSpreadLength = clamp(abs(vSampledVelocityPixels.x), 0.0f, g_fMBBlurRadius);
@@ -296,9 +298,17 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURX(PS_IN In)
float fTapCount = (float) (2 * iMaxMotionBlurSampleCount + 1);
float fCoverage = saturate(fWeight / max(fTapCount, 1.0f));
Out.vColor = float4(vBlurColor.rgb, fCoverage);
//Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity;
//Out.vColor = float4(vBlurColor.rgb, fCoverage);
Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity * 0.5f + 0.5f;
float2 vBlurVelocityPixels = vBlurVelocity * g_vResolution.xy;
if (length(vBlurVelocityPixels) < 0.5f) // 0.5px 이하면 정지 취급
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, uv);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
return Out;
}
PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
@@ -315,8 +325,8 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
float fSampleSpreadLength;
float2 uv = In.vTexcoord;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y * g_fFar; // 해당 셀의 깊이
float2 vCenterVelocityUV = g_VelocityTexture.Sample(PointSampler, uv).xy;
float fCenterDepth = g_DepthTexture.Sample(PointSampler, uv).y; // 해당 셀의 깊이
float2 vCenterVelocityUV = (g_VelocityTexture.Sample(PointSampler, uv).xy * 2.f - 1.f);
float2 vCenterVelocityPixels = vCenterVelocityUV * g_vResolution.xy; // UV -> 픽셀
float fCenterSpreadLength = clamp(abs(vCenterVelocityPixels.y), 0.0f, g_fMBBlurRadius);
float2 vSrcTexelSize = float2(1.f / g_vResolution.x, 1.f / g_vResolution.y); // 소스 셀 사이즈 g_vResolution-> 현재는 colortexture 해상도
@@ -339,15 +349,14 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
continue;
}
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y * g_fFar;
vSampledVelocityUV = g_VelocityTexture.Sample(PointSampler, vDestUV).xy;
fSampledDepth = g_DepthTexture.Sample(PointSampler, vDestUV).y;
vSampledVelocityUV = (g_VelocityTexture.Sample(PointSampler, vDestUV).xy * 2.f - 1.f);
vSampledVelocityPixels = vSampledVelocityUV * g_vResolution.xy;
fSampleSpreadLength = clamp(abs(vSampledVelocityPixels.y), 0.0f, g_fMBBlurRadius);
// [Sample]
float fWeightCalculated = SampleWeight(fCenterDepth, fSampledDepth, float(abs(i)), fCenterSpreadLength, fSampleSpreadLength, fPixelToSampleUnitsScale, fDepthScale);
if (fWeightCalculated <= 0.0f)
{
if (fWeightCalculated <= 0.0f) {
continue;
}
vSampledColor = g_ColorTexture.Sample(ClampLinearSampler, vDestUV);
@@ -362,9 +371,17 @@ PS_OUT_VELOCITYBLUR PS_MOTIONBLURY(PS_IN In)
float fTapCount = (float) (2 * iMaxMotionBlurSampleCount + 1);
float fCoverage = saturate(fWeight / max(fTapCount, 1.0f));
Out.vColor = float4(vBlurColor.rgb, fCoverage);
//Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity;
//Out.vColor = float4(vBlurColor.rgb, fCoverage);
Out.vColor = vBlurColor;
Out.vVelocity = vBlurVelocity * 0.5f + 0.5f;
float2 vBlurVelocityPixels = vBlurVelocity * g_vResolution.xy;
if (length(vBlurVelocityPixels) < 0.5f) // 0.5px 이하면 정지 취급
{
Out.vColor = g_ColorTexture.Sample(ClampLinearSampler, uv);
Out.vVelocity = float2(0.5f, 0.5f);
return Out;
}
return Out;
}
PS_OUT_LIGHT PS_MAIN_DIRECTIONAL(PS_IN In)
@@ -873,6 +873,9 @@ void CRenderer::Render_PostProcessing()
if (FAILED(m_pShader->Bind_RawValue("g_iMBSampleCount", &m_iMBSampleCount, sizeof(_int)))) {
assert(false); return;
}
if (FAILED(m_pShader->Bind_RawValue("g_iMBMaxSampleCount", &m_iMBMaxSampleCount, sizeof(_int)))) {
assert(false); return;
}
if (FAILED(m_pShader->Bind_RawValue("g_iMBType", &m_iMBType, sizeof(_int)))) {
assert(false); return;
}
@@ -674,8 +674,8 @@ 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, 16.f, "%.1f");
GUI::SliderInt("g_iMBSampleCount", &m_iMBSampleCount, 0, 28, "%d");
GUI::SliderFloat("g_fMBBlurRadius", &m_fMBBlurRadius, 0.1f, (_float)m_iMBMaxSampleCount, "%.1f");
GUI::SliderInt("g_iMBSampleCount", &m_iMBSampleCount, 0, m_iMBMaxSampleCount, "%d");
}
if (GUI::CollapsingHeader("End_Padding")) {
}
+4 -3
View File
@@ -62,11 +62,12 @@ class CRenderer final : public CBase
/* TunningParam */
// MotionBlur
_float m_fMBBlurRadius = { 8.f };
_float m_fMBBlurRadius = { 28.f };
_float m_fMBSampleBias = { 0.005f };
_int m_iMBSampleCount = { 14 };
_int m_iMBMaxSampleCount = { 28 };
_int m_iMBSampleCount = { m_iMBMaxSampleCount };
_int m_iMBType = { 0 };
_bool m_bMB = { true };
_bool m_bMB = { true };
// ToneMapping
_int m_iToneMappingType = { 2 };