Non transparent particlefx material (SOLVED)

I don’t get why the built-in particlefx material is creating a transparent particlefx while using rendercam lighting example :frowning: Could you please help me to create a non transparent, vivid particlefx material or modify render script?
My current particlefx fragment program is currently just:

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;

uniform lowp sampler2D DIFFUSE_TEXTURE;
uniform lowp vec4 tint;

void main()
{
	lowp vec4 tint_pm = vec4(tint.xyz, tint.w);]
	gl_FragColor = texture2D(DIFFUSE_TEXTURE, var_texcoord0.xy) * tint_pm;//* var_color;
}

And I do want to modify the color by setting tint constant in script.

I’m not sure what you’re after exactly, but you can set alpha values and blending for particles directly in the particlefx editor.

26

37

Tinting in the shader could be useful if you want to change the tint in runtime though.

Yes, I do set it in particlefx editor (1,1,1,1) and then I want to change it in runtime via particlefx.set_constant(). Even without setting the constant the results are upsetting:
In built-in render script the particlefx are vivid, the contrast is high:

image

while my particles are so transparent, that I can barely see them:

image

Maybe, how the fragment program depends on Life Red, Life Green, … setting?

From the looks of it the custom render script you are using has a different alpha blend state set. Check for any calls to

render.set_blend_func

in your render script. The default render script sets

render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)

in each update before drawing.

EDIT
Also, the first image you posted has a black background compared to the blue-ish background in the second picture. Depending on the blending used, what you are getting might be correct for that blend mode/func.

5 Likes

I’ve checked render scripts and it calls those both functions. I tried without background image and indeed the contrast is higher and transparency is lower. So, how can I achieve higher contrast on background? Separate somehow drawing of particles?

Cool! So we’ve isolated the problem, it’s related to alpha blending.

Did you try fiddling with the alpha blend mode in the particlefx editor?

It’s kinda hard to give specific advice without having the whole picture. If it’s alright you can share the project with me and I’ll have a look, if it’s on Defold dashboard you can invite johan.beck-noren@king.com, otherwise zip up the project directory (minus the /build/and /.git folders) and send it as an attachment.

2 Likes

I tried, but except Multiply (which gives no particles at all o.O), any other blend mode gives the similar result. I’ve just sent a zip, thanks @Johan_Beck-Noren :wink:

The first time the blend func is set, that block of code is just copied from the default render script. The second time I’m not sure. I wrote that a while ago, but I recall there being an issue with the blend mode getting “stuck”, and I called set_blend_func again to reset it to normal. That may not be correct, that’s just my memory.

It’s hard to tell from your screenshot, are the particles rendered under dark lighting? Is your material using the “particles” tag? Maybe you want to render them as “lights” instead? Or render them after all the lighting stuff entirely?

1 Like

Yes, particle tag is used. I tried to draw them later (after lights) and yes - they are sharp then, like GUI for example, but I do want them to be interactive with lights, so, to be drawn before lights rendering :frowning: Maybe that’s the main problem :confused:

Compare the editor view with the runtime;

42

There doesn’t seem to be any lights affecting the scene, all we get is the blue-ish ambient light, which would of course affect the particles as well. I’m not that familiar with the rendercam-lights pipeline, but adding the builtin particle blob on a sprite with a material tag “lights” yields what I would expect;

15

3 Likes

Yes, it was more of a prototype/tech-demo than a finished product. The ambient light color is hard-coded in the init function of the render script. You could add an extra bit to the on_message function to handle changing it at runtime. It looks like you have a daylight scene here, so you probably want to turn up the ambient light. If you set it to (0.125, 0.125, 0.125, 0.125), that should show all your sprites pretty much normally.

The shader I made for the lights divides all their values by 8, so it can have multiple lights overlapping without losing all the information. Then the funky shader for the render target scales the final color back up again in a more or less arbitrary and rather complicated way that I thought looked pretty good. :slight_smile: Unfortunately all that messing around causes some ugly banding, like you can see in Johan’s last image.

If you want simpler lighting, you can delete everything in “render target.fp” except the top two code lines, and put gl_FragColor = base * light; at the bottom. And then for your lights just use a copy of the default sprite/particle shader except with the “lights” tag.

3 Likes

Thanks @Johan_Beck-Noren and @ross.grams for explanations and help, now everything seems to be a lot clearer! :wink: I ended up with additional lights under particlefx and it looks how I was imagining it (even more cooler) :smiley: I understand now better this render pipeline, so thanks again! :wink:

4 Likes

I need to get back to this issue, as the workaround with applying a contrast background is not what I can do for some particle fxs, I want :confused: I need sharp particle material, that would not be blended with the background like this (default material):

image

I tried to remove tint from the default material but it affects only particles themselves, the blending with the background is still visible: :confused:

image

I don’t know what else can I do, I’m using a modified render_script (sharp_render), where I tried many things - changing blend_func and even moved drawing particle_pred in the part where GUI is rendered, but effect is always as above :confused:

Here are my struggles:

Empty Project.zip (23.7 KB)

I noticed that you never got an answer to this question. What was it that you needed exactly? I’m not 100% sure of the effect you are after from reading this thread.

1 Like

Thank you for getting back to this! :grinning: So my issue is, that I want those red particles to be “above” the black and white (or whatever there is) background. It doesn’t matter if the particlefx is in go above or in gui.

image

It doesn’t happen when I don’t change the colors in Particle Editor. I thought I could utilize one fully white image or image like the default particle_blob.png and modify colors in pallete, but the case with this transparency is annoying me :confused: I don’t understand why is that.

In game it is like that:

image
In the red circle there is a pfx with 100% alpha and it’s not blending togheter with the background, it’s sharp and clear. Nevermind that I’m decreasing the transparency overtime (orange arrow). But I hope it is visible here, that the pfx in the green circle is transparent and not so clear - in that case I’m using one image (1x1 white pixel) and I’m modifying its color to match the selected element (red for fire, blue for water, etc.)

EDIT: And it is not regarding Rendercam! It happens when I’m using default render script, modified render script (as above) and Defold-Orthographic and Lumiere too.

Which blend mode have you set on the emitter?

1 Like

Indeed!
I was tinkering with materials, render scripts and so on and didn’t ever noticed this property:

image

This forced me to educate further at least :man_facepalming: Thank you! :gift_heart:

2 Likes