Building a Sync Tool for Blender to Defold

Ok. Initial tinkering complete. Erm. It works.
Heres the Blender scene - shown above:


And here is the Defold, exported with Node compilation straight into Defold.

Some notes:

  • There is no lighting implementation. its only shaders, textures and colors.
  • Some nodes are not included, but a huge amount are. I added one myself, and it seems fairly easy to extend.

For those who are interested go to my repo and grab the “blender-node-compiler” branch.
Im a little surprised if Im honest, I expected it to be alot more problematic to do this.

Going to add some simple lighting etc to see how that goes. Also going to try out a more complex scene to see how badly it goes :slight_smile: If you have any questions or ideas, let me know. This could end up being very neat.

11 Likes

A Quick test with the junk shop demo scene from blender surprised me also:


While missing a few textures here and there (alphas, and metallics it mostly looks like) it still did a good job. Most importantly, this method of export is around 4-5x faster than my previous methods - Im not sure if thats due to the missing textures, but it was very fast (around 30-40 secs to export to Defold).

I’ll get the texture problem fixed - its to do with textures that are early in the node layout, its not picking them up. And I’ll add a little pbr like lighting to the shaders, and will see how this goes. Its going to save me coding alot of individual node shader support.

8 Likes

More progress. All the textures are now coming in correctly.


I need to now think about how lighting will be used for the shaders. Might take a little while before I resolve this. Since I am thinking of bringing in Blender lights and light probes as well, allowing for almost a complete Blender scene render.

Im also interested in making some of the more ‘odd’ shaders like the BSDF hair shader - that would be fun. As well as adding in ways to provide templated shaders for people wanting to supplant their own custom shaders in place of Blender ones.

Once I get this reasonably stable, I think this will probably end up on the master branch, since I will be able to support far more complex Shader Node layouts and thus quite complex scene generation.

8 Likes

This will easily make Defold a highly desirable option for applications beyond only games. Being able to make a scene in Blender, import it to Defold, and having it run in a webapp for example is so useful. We will need to make tutorials of the process and explain all of the use cases and post that information on appropriate forums and so on so people realize how amazing this is!

The ability to use Blender node graph for shaders is also a game changer.

4 Likes

Agreed. It will streamline the art process very nicely. There will be some important points to consider:

  • Lighting and shadows: This may want to be custom, thus Im considering generating render scripts that people can provide their own replacements for.
  • Animation: This is working, but it gets more complex the more animation types that need support, especially if things like spline following and such (which Id like :slight_smile: ).
  • Special Shader Nodes: There are apparently over 80 shader nodes in Blender. The list I currently have based on the compiler code Im using, is around 20-30 (more may work depends on their inputs and outputs). This will grow, and base nodes should allow a huge capability but supporting some of the more complex nodes may be tricky.
  • Vulkan and other support: Eventually this will probably need to be more Vulkan friendly and potentially support other API’s - maybe even DX (HLSL etc) for Windows builds. This is more likely a future capability but it will be important for many people.
  • Data management: At the moment the system is quite simplistic and naïve. It is more likely this will need proper asset management databases with versioning etc. This is something Im working towards anyway, but it probably wont be free (its going to have cloud/data costs associated).

Finally, the PBR implementation Im doing for the metallic, etc will be similar to the previous one so its likely people may want to replace this as well. Im going to make the PBR → fragColor a function that people can provide their own solution for as well. I should have this ready in the next day, with basic lighting (no shadows).

5 Likes

Would be incredible to make cutscenes in Blender that just work in Defold. :star_struck:

I dont see why that shouldnt be possible. In theory it should be. But as you can imagine, the big question here would be performance. I think over time, as each segment of the compiler (for each node) is optimised for glsl, this could be doable for even reasonably complex scenes.

2 Likes

Added some lighting and material handling.


Still need to fix alpha and a few nodes so they work correctly.
Will do some more this weekend.

8 Likes

Another quick update (couldnt help myself). Fixed normals and added 4x lights (test ones). Alpha/Transparency still broken, because I need to add support for proper mix shader that uses the Factor Maximum math type.


Going to allow users to select up to 4 lights in the scene (initally) and may add probe/static lights (will see).

Side note. New params that will become available:

  • Exposure (ala camera exposure)
  • HDR/Tone map selection
  • Various lighting and eventually shadow params.

And finally, a render script will be needed for all this. Wil need to have an uber shader of some sorts to maximize perf too. The methodology here makes things alot easier because of the shader generation.

9 Likes

Almost there. Reflections missing (will add tomorrow).


The 4 lights have been manually set to 4 lights in the scene. This will change.
I’ll update the UI on blender side for some of the new settings.
I intend to run about 3 demo blender scenes through this - in the past this require a large amount of adjusting scene materials. Hopefully this should greatly improve that process.

4 Likes

And this is with AES Filmic Tone Mapping.
I hope to have a few selections for the tone mapping settings.

10 Likes

Due to some family things (my daughter is getting married soon :slight_smile: ) this has slowed a little. I hope to get some of this done this week. Specifically the light control from blender side and the render output settings like the tone mapping (I have five or six that can be used).

At the current time the branch is usable, but the scenes it produce in defold are a little slow because of all the shaders that get generated individually, meaning there are alot of context changes going on. I want to merge this into a handful of shaders to make this rendering a little more efficient.

Hopefully in the coming days there should be more progress here. Id like to merge this back into master by the end of the week.

12 Likes

Ok. Better late than never :slight_smile:
I have eight tonemap settings (9 if you include none :slight_smile: ). Also now exposed is a max texture setting. This is very useful if you need quick exports to check in Defold. Or if you are only wanting to support up to specific sized textures.
Heres some screenshots of the ui updates.

And heres some screenshots (in Defold) of three tonemaps: None, ACES Filmic and Uncharted 2.



Theres alot to cleanup before a release. The lights are still needing some love, but I hope to have a release ready by Wednesday ish.
Note: These are Defold editor shots, not runtime. So some of the shader features dont appear (transparency etc)

9 Likes



After sync all object transform is changed(
Can you return transform back after sync?

Yeah this is a little problematic. The transforms get collapsed because of the change in axis between Blender and Defold. I’ll have a look to see if I can do something about that. If you make the object a child of an object in the collection, it should maintain its translation values.

2 Likes

Ctrl+z return values back. Not sure is it possible to use ctrl+z from plugin.

I do not use child object. Only collection as a root, and objects inside collection.

For my project I return to 1.3.1, because it doesn’t change transform.

Yeah the reason is, if you look on the Defold side, there is a “temp” root object that applies a rotation to get the axis in the right position. The more recent versions are aimed at getting rid of that node, because there are scene structures where that doesnt work.

What I think I can do, is do as you suggest and revert after export. Or possibly collapse the object matrix without collapsing the the scene itself - this might be a bit manual I suspect.

I havent had much time recently (daughter getting married sunday) but after that, I hope to have alot more free time to work on this, and finish the rendering Im doing. The new node and render system should give people lots of options. You will be able to control how the scene is rendered using a RenderManager and this allow you to add your own shader passes, control the PBR elements and generally manage how the blender scene gets rendered in Defold.

The main reason for the new render system is to support lighting (many point lights for example) and include a shadow render pass. ATM this new system will reside on the branch for a while until I think it is suitable for upgrading the main codebase.

@d954mas - I will try to get to helping you out with this on Monday. I have a public holiday, so I hope to have some free time, and I should be able to come up with something to help.

3 Likes

Thanks. You already did a good job, for my case plugin worked in 1.3.1 so this issue is not blocking for me.

Not sure about new export, but in 1.3.1 if objects use same .buffer, file name can be different but if content of buffer file is same, engine will keep only one file.

But in new export looks like you apply all transforms and buffer file will be different for same objects. Because all vertices now in world position not in local. So engine will need to take all buffer files. And size of game will be bigger.

1 Like

1.3.1

Last from git

Same object but every instance need it own buffer.(because vertices are in world space)
2023-09-28_17-36-05

Yes this is a side effect of pushing into the verts. Maybe I can make this an export option.
The impact should only be on root level objects. If you want to keep hierarchy then put them under a root object (this will apply the axis transform) and the child objects should be the same as previously.
Will have a look at this next week. sorry I dont have time atm.

1 Like