Is it possible to create exact copies of some particlefx?

How do I create multiple particlefx that are exact copies of each other? All of these particle fx will be spawned through collection factory at the same time. It will be used for parallax effect, like stars. If they’re random to each other, then the parallax change will be noticeable. Is it possible to make it more deterministic?

I guess you could render it to a render target and use that on multiple sprites.

Alrite that would work too, thanks!

Apparently it seems difficult for me to do. I’m not really sure how to render the particlefx to a render target, and have that render target rendered into a sprite. Can you help me on how I should do it?

My steps were like this but it just did not work:

  1. I created a custom particlefx material called parallax_particlefx.material, changed the tag “particle” to “parallax_particle”, then use it for my particlefx
  2. I created a custom sprite material called parallax_sprite.material, changed the tag “tile” to “parallax_sprite”, then use it for my dummy sprite to render to. The dummy sprite size is set manually to 640 x 640, and it has a default image of a 32 x 32 rectangular white dot
  3. I added some code that I got from API example on how to create render target and how to use it to my project’s default render script, with a little assumption over how the texture draw to the sprite works:
function init(self)
    self.parallax_particle_pred = render.predicate({"parallax_particle"})
    self.parallax_sprite_pred = render.predicate({"parallax_sprite"})
    local color_params = { format = render.FORMAT_RGBA,
    width = 640,
    height = 640,
    min_filter = render.FILTER_LINEAR,
    mag_filter = render.FILTER_LINEAR,
    u_wrap = render.WRAP_CLAMP_TO_EDGE,
    v_wrap = render.WRAP_CLAMP_TO_EDGE }
    local depth_params = { format = render.FORMAT_DEPTH,
    width = 640,
    height = 640,
    u_wrap = render.WRAP_CLAMP_TO_EDGE,
    v_wrap = render.WRAP_CLAMP_TO_EDGE }
    self.parallax_render_target = render.render_target({
        [render.BUFFER_COLOR_BIT] = color_params, [render.BUFFER_DEPTH_BIT] = depth_params })

function update(self)
    ... -- after render models

    render.enable_texture(0, self.parallax_render_target, render.BUFFER_COLOR_BIT)

    ... -- before the render sprites, label, particles

I’m honestly not sure what configuration I need when creating the render target, but I’m just ensuring that the render target size is as big as the dummy sprite size, assuming that matters. Secondly, as I said before I have zero idea how to render the render target to sprite, so I am assuming that texture 0 is what I need to set for the render target, that the sprite would use it (?), then draw it.

Well that doesn’t work, as in, none of the particles are rendered. :joy:

So I tried moving the enable texture/draw parallax sprite pred/disable texture into within the “render sprites, label, particles” part, but of course it also doesn’t work. Like this:

    -- render sprites, label, particles
    render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)

    -- here still won't work
    render.enable_texture(0, self.parallax_render_target, render.BUFFER_COLOR_BIT)


It’s too expensive to use particlefx for this anyway in mobile so I decided to just use simple repeating textures instead.
Also if anyone can point me a very simple example of render texture in Defold please let me know because I’m still not successful to make it work (the anaglyphic example is definitely not the simple example!), thanks!