Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt, particle system and additive blending
Forum Updated to NodeBB v4.3 + New Features

Qt, particle system and additive blending

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 178 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    black_gay
    wrote on last edited by
    #1

    I’m creating a particle system using Qt and c++. I want to blend colours of the particles that overlap each other – adding the RGB values on top of each other, so colours would get brighter, something like this:
    Desired effect
    My code looks like this:

    In custom QGraphicsScene class:
        QPixmap* pixmap2 = new QPixmap("E:\\Qt_workspace\\1\\smoke5.png");
        pixmap2->setDevicePixelRatio(0.5);
        QPointF origin2 = {250, 100};
        QPainter pix2(pixmap2);
        pix2.setCompositionMode(QPainter::CompositionMode_Plus);
        pix2.drawPixmap(origin2, *pixmap2);
        pix2.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, true);
        particleSystem2 = new ParticleSystem(this, pixmap2, origin2);
        v_particleSystem.push_back(particleSystem2);
    

    And i create particles in a loop:

    void Level1::advance()
    {
        for (int i = 0; i < v_particleSystem.size(); ++i) {
            v_particleSystem\[i\]->applyForce(gravity);
            QVector2D v = { (float)player->x(), (float)player->y() };
            repeller->update(v);
            v_particleSystem[i]->applyReppeler(repeller);
     
            v_particleSystem[i]->addParticle();
            v_particleSystem[i]->run();
        }
        update(sceneRect); ///so items dont leave any artifacts though works without it when 
    using m_view->viewport()->repaint();
        m_view->viewport()->repaint();
    
    

    And Particle class derives from QGraphicsPixmapItem.
    But im getting this result:
    Achieved effect
    Any idea how to achieve additive blending?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved