Getting the particle world position in the fragment shader

Hello,

I would like to add some sort of cubemap based lighting to my CPU particles, by using a custom fragment shader.
My first attempt would be to remap the world position into a geometric shape, which I would use for calculating a normal vector.

I have seen that the particle vertex shader passes the particle’s world position to the fragment shader via the vPositionW parameter. But it is always zero, because the inverse view matrix is zero.

Is there a simple way to fix that?

I’m still using Babylon 5.

Many thanks
Helmut

cc @sebavan @Evgeni_Popov

Could you reproduce the problem in the Playground?

The invView matrix is only used in the BILLBOARDMODE_ALL mode, and I just tested a PG using this mode and was able to verify with Spector that the invView matrix was not empty:

2 Likes

Hello Evgeni,

thank you for looking into that. Your assumption was correct, the BILLBOARDMODE_ALL was indeed missing. The reason for this was the way I have invoked engine.createEffectForParticles():

    let effect = engine.createEffectForParticles("part3effect",
    [], // uniforms
    [], // samplers
    "#define ANIMATESHEET", // define string,
    null, // fallbacks
    null, // on compiled,
    null, // on error
    this.particleSystem);

the define string was set in order to fix the issue described here:

I have now applied the second solution proposed by rdurnin, which fixes both issues:

    let defines = [];
    this.particleSystem.fillDefines(defines, this.particleSystem.blendMode);

    let effect = engine.createEffectForParticles("part3effect",
    [], // uniforms
    [], // samplers
    defines.join('\n'), // define string,
    null, // fallbcks
    null, // on compiled,
    null, // on error
    this.particleSystem);

Best
Helmut

2 Likes