function init(self)
…
self.tile_pred = render.predicate({“tile”})
…
end
function update(self)
…
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.draw(self.tile_pred)
…
end
The predicate “tile” is used everywhere in the game for sprites and I can set Add / Alpha using the editor switch. However if I use a model component, there is no switch in the editor and it seems to me that the engine always use Add…
How could I use Alpha with model?
Probably I am missing something. Any help is highly appreciated.
Render transparent objects after all the opaque objects have been rendered.
Enable depth test, but disable depth write.
Use blend func render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA if not premultiplied, replace first arg with render.BLEND_ONE if premultiplied.
Render transparent objects in back-to front order from the camera.
Oh, and you probably want to enable back-face culling.
I haven’t tested any of this. I’m thinking that maybe @Dragosha, @d954mas or @Pkeod have some ideas as well.
looks like premultiplied alpha with black background?
How you turn on ADD blend for models? I noticed that if model/mesh renders after sprite with ADD blend the model/mesh inherits blend mode
Looks like Mats pulled it out of the bag! I followed the advice, but couldn’t find the “disable depth write”, and two predicates doesn’t seem necessary. The result:
In a new project, using the same render script as above, I’ve noticed that when the Rendercam game object is tilted downwards (using a negative x angle) the transparency fails - but only on textures surrounded by transparency. When not tilted it works.
On my PC I see black borders in both cases, tilted or not.
It’s happened because for textures with alpha channel you need to make 2 pass in render. First for all models without alpha, second for models with alpha. (just add second predicate )
Thanks! How would I modify the above project for it to work? I have tried a few things, but I don’t fully understand how draw calls and rendering work. So far I’ve tried these things:
Add a new “self.model_alpha_pred” predicate with a “model_alpha” tag.
Create a new material with the model_alpha tag.
Add code to render the model_alpha_pred in the .render_script.
I had exactly the same issue (with the rotation of the sprite / tilted - not tilted), but I was able to solve it in a couple of hours of studying the topic
The algorithm is very simple:
Create a new material (copied from sprite) with new name and new tag
Added a predicate for this tag to the render script
Set rendering (draw call) immediately after rendering the tile predicate
(!!!) Of course depth test included before draw call: