State of vertex attributes with render.enable_material()

Hello!
I am not sure if it is an intended behaviour:

I have a sprite with “material_A” assigned in editor.
In render script I do this:

render.enable_material("material_B")
	
render.draw(self.my_pred, {frustum = frustum})

render.disable_material("material_B")

The sprite is rendered with material_B indeed. But the issue is that vertex attributes with semantic type Position are not set in this case (and texcoords also).


F.e. position_local defaults to vec2(0.0, 0.0) in this case.

Is there a workaround for that? Thank you!

Hm that should work; do you have a small repro I can look at?

Sure!

Notice how sprite with material_B set in editor is rendered differently from sprite with material_B set from render script. position_local VA is zeroed in the later. texcoords though are set correctly in both.

Thanks! I’ve added an issue regarding this: Custom vertex attributes doesn't work together with render.enable_material · Issue #9246 · defold/defold · GitHub

The reason it doesn’t work is that components are not aware of the overridden material that has been set on the renderer, so it will not produce vertices in the format that the overridden material expects. I’ll take a look at a fix for it before next release, thanks!

3 Likes

Thank you very much!