axcord.ws
-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
C++:
struct MotionBlurHistory
{
MotionBlurHistory() noexcept
{
lastTimeUpdate = 0.0f;
previousPitch = 0.0f;
previousYaw = 0.0f;
previousPositon = Vector{ 0.0f, 0.0f, 0.0f };
noRotationalMotionBlurUntil = 0.0f;
}
float lastTimeUpdate;
float previousPitch;
float previousYaw;
Vector previousPositon;
float noRotationalMotionBlurUntil;
};
void Visuals::motionBlur(ViewSetup* setup) noexcept
{
if (!localPlayer || !config->visuals.motionBlur.enabled)
return;
static MotionBlurHistory history;
static float motionBlurValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
if (setup)
{
const float timeElapsed = memory->globalVars->realtime - history.lastTimeUpdate;
const auto viewangles = setup->angles;
const float currentPitch = Helpers::normalizeYaw(viewangles.x);
const float currentYaw = Helpers::normalizeYaw(viewangles.y);
Vector currentSideVector;
Vector currentForwardVector;
Vector currentUpVector;
Vector::fromAngleAll(setup->angles, ¤tForwardVector, ¤tSideVector, ¤tUpVector);
Vector currentPosition = setup->origin;
Vector positionChange = history.previousPositon - currentPosition;
if ((positionChange.length() > 30.0f) && (timeElapsed >= 0.5f))
{
motionBlurValues[0] = 0.0f;
motionBlurValues[1] = 0.0f;
motionBlurValues[2] = 0.0f;
motionBlurValues[3] = 0.0f;
}
else if (timeElapsed > (1.0f / 15.0f))
{
motionBlurValues[0] = 0.0f;
motionBlurValues[1] = 0.0f;
motionBlurValues[2] = 0.0f;
motionBlurValues[3] = 0.0f;
}
else if (positionChange.length() > 50.0f)
{
history.noRotationalMotionBlurUntil = memory->globalVars->realtime + 1.0f;
}
else
{
const float horizontalFov = setup->fov;
const float verticalFov = (setup->aspectRatio <= 0.0f) ? (setup->fov) : (setup->fov / setup->aspectRatio);
const float viewdotMotion = currentForwardVector.dotProduct(positionChange);
if (config->visuals.motionBlur.forwardEnabled)
motionBlurValues[2] = viewdotMotion;
const float sidedotMotion = currentSideVector.dotProduct(positionChange);
float yawdiffOriginal = history.previousYaw - currentYaw;
if (((history.previousYaw - currentYaw > 180.0f) || (history.previousYaw - currentYaw < -180.0f)) &&
((history.previousYaw + currentYaw > -180.0f) && (history.previousYaw + currentYaw < 180.0f)))
yawdiffOriginal = history.previousYaw + currentYaw;
float yawdiffAdjusted = yawdiffOriginal + (sidedotMotion / 3.0f);
if (yawdiffOriginal < 0.0f)
yawdiffAdjusted = std::clamp(yawdiffAdjusted, yawdiffOriginal, 0.0f);
else
yawdiffAdjusted = std::clamp(yawdiffAdjusted, 0.0f, yawdiffOriginal);
const float undampenedYaw = yawdiffAdjusted / horizontalFov;
motionBlurValues[0] = undampenedYaw * (1.0f - (fabsf(currentPitch) / 90.0f));
const float pitchCompensateMask = 1.0f - ((1.0f - fabsf(currentForwardVector[2])) * (1.0f - fabsf(currentForwardVector[2])));
const float pitchdiffOriginal = history.previousPitch - currentPitch;
float pitchdiffAdjusted = pitchdiffOriginal;
if (currentPitch > 0.0f)
pitchdiffAdjusted = pitchdiffOriginal - ((viewdotMotion / 2.0f) * pitchCompensateMask);
else
pitchdiffAdjusted = pitchdiffOriginal + ((viewdotMotion / 2.0f) * pitchCompensateMask);
if (pitchdiffOriginal < 0.0f)
pitchdiffAdjusted = std::clamp(pitchdiffAdjusted, pitchdiffOriginal, 0.0f);
else
pitchdiffAdjusted = std::clamp(pitchdiffAdjusted, 0.0f, pitchdiffOriginal);
motionBlurValues[1] = pitchdiffAdjusted / verticalFov;
motionBlurValues[3] = undampenedYaw;
motionBlurValues[3] *= (fabs(currentPitch) / 90.0f) * (fabs(currentPitch) / 90.0f) * (fabs(currentPitch) / 90.0f);
if (timeElapsed > 0.0f)
motionBlurValues[2] /= timeElapsed * 30.0f;
else
motionBlurValues[2] = 0.0f;
motionBlurValues[2] = std::clamp((fabsf(motionBlurValues[2]) - config->visuals.motionBlur.fallingMin) / (config->visuals.motionBlur.fallingMax - config->visuals.motionBlur.fallingMin), 0.0f, 1.0f) * (motionBlurValues[2] >= 0.0f ? 1.0f : -1.0f);
motionBlurValues[2] /= 30.0f;
motionBlurValues[0] *= config->visuals.motionBlur.rotationIntensity * .15f * config->visuals.motionBlur.strength;
motionBlurValues[1] *= config->visuals.motionBlur.rotationIntensity * .15f * config->visuals.motionBlur.strength;
motionBlurValues[2] *= config->visuals.motionBlur.rotationIntensity * .15f * config->visuals.motionBlur.strength;
motionBlurValues[3] *= config->visuals.motionBlur.fallingIntensity * .15f * config->visuals.motionBlur.strength;
}
if (memory->globalVars->realtime < history.noRotationalMotionBlurUntil)
{
motionBlurValues[0] = 0.0f;
motionBlurValues[1] = 0.0f;
motionBlurValues[3] = 0.0f;
}
else
{
history.noRotationalMotionBlurUntil = 0.0f;
}
history.previousPositon = currentPosition;
history.previousPitch = currentPitch;
history.previousYaw = currentYaw;
history.lastTimeUpdate = memory->globalVars->realtime;
return;
}
const auto material = interfaces->materialSystem->findMaterial("dev/motion_blur", "RenderTargets", false);
if (!material)
return;
const auto MotionBlurInternal = material->findVar("$MotionBlurInternal", nullptr, false);
MotionBlurInternal->setVecComponentValue(motionBlurValues[0], 0);
MotionBlurInternal->setVecComponentValue(motionBlurValues[1], 1);
MotionBlurInternal->setVecComponentValue(motionBlurValues[2], 2);
MotionBlurInternal->setVecComponentValue(motionBlurValues[3], 3);
const auto MotionBlurViewPortInternal = material->findVar("$MotionBlurViewportInternal", nullptr, false);
MotionBlurViewPortInternal->setVecComponentValue(0.0f, 0);
MotionBlurViewPortInternal->setVecComponentValue(0.0f, 1);
MotionBlurViewPortInternal->setVecComponentValue(1.0f, 2);
MotionBlurViewPortInternal->setVecComponentValue(1.0f, 3);
DRAW_SCREEN_EFFECT(material)
}