Non transparent particlefx material with rendercam lighting (SOLVED)


#1

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.


#2

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.


#3

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?


#4

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

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?


#6

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.


#7

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:


#8

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?


#9

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:


#10

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


#11

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.


#12

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: