Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unwanted Motion Blur  (Read 227 times)

0 Members and 1 Guest are viewing this topic.

Dwindows

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Unwanted Motion Blur
« on: March 02, 2024, 05:39:42 pm »
Hi! (and thank u for reading this  ;D)

Now that I've implemented interpolation and I have a very smooth movement, I encountered a problem while moving my rectangle.
If I move it slowly, it goes perfectly; but when I move it fast, there's like a motion blur effect that makes it strange.
I'm using Windows 10 with an Nvidia GPU (GeForce RTX 2060) and my program uses SFML 2.6.1.

Minimal Example of code:
#include <SFML/Graphics.hpp>
#include <Kairos/Timestep.hpp>

sf::Vector2f lerpV(sf::Vector2f a, sf::Vector2f b, float t)
{
    return a * (1 - t) + b * t;
}

void Update(sf::Shape* s, float dt, sf::Vector2f* vel, sf::Vector2f* pos)
{
    float mass = 1.f;
    float f = 100.f;
    sf::Vector2f force = sf::Vector2f(0.f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        force += sf::Vector2f(0.f, -f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        force += sf::Vector2f(-f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        force += sf::Vector2f(0.f, f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        force += sf::Vector2f(f, 0.f);

    // Inertia:
    force += sf::Vector2f(-vel->x * 1.f * mass * 9.81f, -vel->y * 1.f * mass * 9.81f);

    float acceleration_x = force.x / mass;
    float acceleration_y = force.y / mass;
    *vel += sf::Vector2f(acceleration_x * dt, acceleration_y * dt);
    *pos += *vel;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(1200, 800), "Motion Blur Problem");
    window.setVerticalSyncEnabled(false);
    window.setFramerateLimit(144);

    sf::RectangleShape shape(sf::Vector2f(200.f, 200.f));
    shape.setFillColor(sf::Color::Green);
    sf::Vector2f velocity = sf::Vector2f(0.f, 0.f);

    sf::Vector2f pre = shape.getPosition();
    sf::Vector2f position = shape.getPosition();

    kairos::Timestep timestep;
    timestep.setStep(1.f / 60.f);
    timestep.setMaxAccumulation(0.25f);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        timestep.addFrame();
        while (timestep.isUpdateRequired())
        {
            pre = position;
            float dt = timestep.getStepAsFloat();

            Update(&shape, dt, &velocity, &position);
        }
        float interpolation = timestep.getInterpolationAlphaAsFloat();

        window.clear();
       
        shape.setPosition(lerpV(pre, position, interpolation));
        window.draw(shape);

        window.display();
    }

    return 0;
}

My main questions are:
1. is this an optical illusion made by its movement? (so I should only move it slowly)
2. is this a problem of my monitor or my eyes? (so I should cry)
3. or is this a bug? and if yes, how can I fix it?
« Last Edit: March 02, 2024, 07:16:09 pm by Dwindows »

kojack

  • Sr. Member
  • ****
  • Posts: 327
  • C++/C# game dev teacher.
    • View Profile
Re: Unwanted Motion Blur
« Reply #1 on: March 03, 2024, 02:32:38 am »
This sounds like monitor ghosting. Have a look here: https://www.youtube.com/watch?v=MwfMtfBB07w
Basically pixels don't change colour instantly. It takes time for them to transition between colours. Different monitors will have different ratings, often measured as GTG (Grey To Grey), which is how many milliseconds it takes to change between two different shades of grey. The higher the GTG, the longer the motion trails left behind by moving objects.
The panel type can affect this too. VA panel monitors will have worse ghosting than IPS panels.

Some monitors let you turn on things like pixel overdrive, where they pump higher voltage into the pixels to change them faster, but that can overshoot and give different artifacts.

Another thing you can do is make the background look more like the moving object, the ghosting will be less noticeable.

Dwindows

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Unwanted Motion Blur
« Reply #2 on: March 03, 2024, 09:55:08 pm »
Thanks man!  ;D

I didn’t know what Monitor Ghosting was  :P  and you really helped me!