creativelifeform / three-nebula

WebGL based particle system engine for three.js
https://three-nebula.org/
MIT License
908 stars 75 forks source link

perfomance vs SPE #102

Open cjsjy123 opened 3 years ago

cjsjy123 commented 3 years ago

spe CODE:

` var particleGroup = new SPE.Group({ texture: { value: Resources.Load("resource/img/star.png").data } });

    var emitter = new SPE.Emitter({
        // maxAge: {
        //     value: 2
        // },
        // position: {
        //     value: new Vector3(0, 0, -50),
        //     spread: new Vector3(0, 0, 0)
        // },

        // acceleration: {
        //     value: new Vector3(0, -10, 0),
        //     spread: new Vector3(10, 0, 10)
        // },

        velocity: {
            value: new Vector3(0, 0, 0),
            spread: new Vector3(100, 75, 100)
        },

        color: {
            randomise:true,
            // value: [new Color('white'), new Color('red')]
        },

        size: {
            value: 100
        },
        alive:0.25,
        particleCount: 10,
    });

    particleGroup.addEmitter(emitter);
    scene.add(particleGroup.mesh);

    render.proton = particleGroup;`

Nebula GPURender code: ` private createNormalNebula(render: SceneRenderGroup, scene: Scene) {

    let proton = new Nebula.System();
    render.proton = proton
    proton.addEmitter(this.createNebulaEmitter());
    //    proton.addRenderer(new Nebula.SpriteRenderer(scene, THREE));
    //@ts-ignore
    proton.addRenderer(new Nebula.GPURenderer(scene, THREE));
}

private createNebulaEmitter() {
    let emitter = new Nebula.Emitter();
    emitter.rate = new Nebula.Rate(10, 0.25);
    // emitter.addInitializer(new Nebula.Mass(1));
    emitter.addInitializer(new Nebula.Radius(100));
    emitter.addInitializer(new Nebula.Life(2));
    emitter.addInitializer(new Nebula.Body(this.createSprite()));
    emitter.addInitializer(new Nebula.Position(new Nebula.BoxZone(100)));
    // emitter.addInitializer(new Nebula.RadialVelocity(200, new Nebula.Vector3D(0, 1, 1), 180));

    // //emitter.addBehaviour(new Proton.RandomDrift(30, 30, 30, .05));
    emitter.addBehaviour(new Nebula.Rotate("random", "random"));
    emitter.addBehaviour(new Nebula.Scale(0.75));
    // emitter.addBehaviour(new Nebula.Alpha(1));

    //emitter.addBehaviour(new Proton.CrossZone(zone2, "bound"));
    //emitter.addBehaviour(new Proton.Collision(emitter,true));
    emitter.addBehaviour(new Nebula.Color(0xff0000, 'random', Infinity));

    emitter.emit();
    return emitter;
}

private createSprite() {
    var map = Resources.Load("resource/img/dot.png").data
    var material = new SpriteMaterial({
        map: map,
        color: 0xff0000,
    });
    return new Sprite(material);
}

` result:

SPE faster

Nebula image

SPE image

any idea to imporve it?

rohan-deshpande commented 3 years ago

Interesting. A bit difficult to know what could be causing this, do you mind investigating a little bit deeper and see which function calls are most expensive?

Keep in mind that SPE is a different engine and while it may perform better, it also doesn't have the same feature set / API as Nebula so there may be trade offs here. Of course I want Nebula to be as performant as it can be so I am very interested in a possible solution.

One other thing to consider is that Nebula is a mixed solution. It uses the CPU for everything other than the render call when using the GPURenderer. This has been done to make certain parts of the API much easier to deal with. I can't really remember what the architecture of SPE is, but it could be that because it is more heavily GPU focused for everything, it will perform better, but certain other features may be harder to implement.

Any thoughts on this @manthrax?

cjsjy123 commented 3 years ago

有趣。很难知道是什么原因造成的,您是否愿意进行更深入的研究,看看哪些函数调用最昂贵?

请记住,SPE是一个不同的引擎,尽管它可能会表现更好,但它也没有与Nebula相同的功能集/ API,因此这里可能需要权衡取舍。当然,我希望Nebula表现出色,因此我对可能的解决方案非常感兴趣。

要考虑的另一件事是星云是混合解决方案。使用时,它将CPU用作除render调用以外的所有功能GPURenderer。这样做是为了使API的某些部分更易于处理。我真的不记得SPE的体系结构是什么,但是可能是因为它更加专注于GPU的所有工作,它的性能会更好,但是某些其他功能可能很难实现。

对这个@manthrax有什么想法吗?

profilerdata.zip I like Nebula's api very much, it gives me more possibilities, but SPE is not. I can't fully simulate Nebula's particle effects with SPE, but performance is also our concern. According to the sampling results, their update costs vary greatly. Update seems to be much more expensive than SPE

rohan-deshpande commented 3 years ago

I understand that it might be more expensive, I'm really interested in making it as performant as possible so I'll try to investigate why.

rohan-deshpande commented 3 years ago

I'd like to know if any of the recent changes have alleviated the issues you've experienced at all.

There's been a number of updates to the GPURenderer and there was some performance improvements.