Building a Sync Tool for Blender to Defold

Awesome. Thanks for all the feedback. Its extremely helpful and useful. I appreciate your patience with the fixes.

1 Like

Continue my experiments with blender:)

I need to make earth rectangle.
1)I make cube with my texture.
2)I make a rectangle with that cubes, than i join rectangles to one mesh
3)In blender that look like smooth rectangle
3.1)In editor/game it looks like rects


2022-11-28_13-12-01

Any ideas? Something with normals? or lights in my shader?

Or mb there are other ways to repeat/tile texture on mesh, that will worked in blender and defold?

I think this is lighting. If you are using the simple one I posted. It is based on the model material. The fragment shader on these lines does this:

    // Diffuse light calculations
    vec3 ambient_light = vec3(0.2);
    vec3 diff_light = vec3(normalize(var_light.xyz - var_position.xyz));
    diff_light = max(dot(var_normal,diff_light), 0.0) + ambient_light;
    diff_light = clamp(diff_light, 0.0, 1.0);

The first line sets an ambient light level - 0.2. The second line calculates the normalized light direction vector. The third line then does a dot product between the normal of the mesh surface and the light direction, then adds the ambient light. And finally the last line clamps the light results between 0.0 and 1.0.

What could be happening is that you are seeing the ambient lighting overriding the small changes in lighting. Try changing ambient from 0.2 to 0.0 to see if there is any significant difference.

Another possibility is that the normal for the surface is incorrect. A way to test/check this is to change the last line in the fragment shader from:

gl_FragColor = vec4(color.rgb*diff_light*lightmap.rgb,1.0);
to
gl_FragColor = vec4(var_normal, 1.0);

Which should show different colours for each surface direction.
Hope this helps. Will try out a couple of scenes to replicate it.

1 Like

Ok. Just spent some time staring at your picture and I think I know what the answer is.
Smoothing groups. Its actually looks like Blender smoothing groups are creating ‘rounded’ surface normals. Try ticking “face normals” in the exporter or force the normals in blender to be face normals.

1 Like

I try face normals but it create something broken:)

Thanks i will try:)

Oh boy that is broken. I’ll take a look now. Need coffee. Will let you know what I find.

2 Likes

Ok. Using a the Default model shader and a really basic scene, it is definitely not consistent - Ive broken something in the generation stage I think (possibly normal related).
In Blender:


In Defold:

When using PBR material its a little better:

I’ll hopefully have a fix soon.

And face normals arent right either:

Thanks i fixed it in my case)
It was problem with multiple vertices in same position.


1 Like

Ok. Thats better. Fairly certain there is still and issue. Will sort it out, might be tomorrow though.

2 Likes

New release (sorry its been so quiet for so long).

Gltf is now getting better (working). Thanks to @lincerely for reporting the bug. Please let me know if you have problems with it. At the moment the gltf only supports 1:1 gltf to bin file mapping, which should be fine (for most situation).

Im now working on a camera fix, so that the incoming camera is correctly oriented and set as default in the collection.

11 Likes

Another new release adding more camera functionality. Now supports fov, near and far settings from Blender. Also fixes cameras and objects rotations and positioning if using gltf meshes.

< Addition >
A little note about this. If you want to change textures at runtime, you must use resource.settexture once youve updated the buffer. You may need to do something similar with meshes - havent tested per frame updates too much. There is a simple example I added that does, but changing the vertices per frame, so it seems to work. Let me know if you have troubles with this.

12 Likes

What does this error mean actually? I tried to export a scene but every object has the error in the log

Unknown material type used.

Thats a great question :slight_smile:
Im fairly certain this happens when the materials you are using in PBR export are not of the type “Principled BSD”.

Ideally I could support far more materials, and its something I do want to expand. If you have specific materials that would be useful, let me know and I’ll see if I can get them integrated.

Just an update. This weekend I’ll try and add some more common ones. I did create a test version a while back that was a little unstable, but had about 5 material types. Im pretty sure a couple of them could be easily added.

4 Likes

Material looks like this, should I send you files or is this enough? I think you just make a new material and change surface to Emission. It’s used for 3D models with nearest neighbor pixel art textures.

1 Like

Yeah. Emission materials are not supported in the current exporter.
You need to use Principled BSD. If you change the type it should work (the emission field should be filled with the color value you have there).
I’ll try to add that one on the weekend - it should be possible since Principled BSD has emission :slight_smile:
Only problem with some of these materials, is that not all the features of it will be supported - they have to be able to be converted into the PBR shader I use in Defold. Which means there can be limitations.

2 Likes

Ok. Fairly big update today, and possibly a much bigger one coming soon.
New Blender shader nodes supported:

  • Diffuse BSDF
  • Emission
  • MixShader
  • ColorRamp

Noting that MixShader and ColorRamp have limited capability.
MixShader only supports input nodes that are supported.
ColorRamp only supports simple color setting from a value (not dynamic).

Here’s a screenshot (its not overly meaningful)

The cube is a mix shader of Red and Green input colors.
The Cone is a Diffuse BSDF with a ColorRamp as input.
The Cylinder is a textured Emission Shader.
The Background is a Principled BSDF.
This scene I will add to the repo at some stage for reference.


Now onto the good bits. After discussion with @Pkeod and working on some of these shaders I was wondering if Blender still had the ability to convert the shader to glsl (Old Blender did this).
Sadly that wasnt the case, but there have been people converting Blender to glsl manually (which is a bit nuts) and here is an example repo I found:

After thinking about what defender is doing, and looking at some of the ideas in this script, I think it might be possible to generate shaders from Blender to work directly in a Defold project.
Im going to do some little experiments on a branch in the defender repo (if you want to look/try) and see where that goes.

It would be very interesting to be able to get a good amount of shaders automatically generated for Defold. Even allowing people to make templates to use their own created shaders to replace generated ones. This would be an extremely powerful tool.

Dont expect this to be done quickly… I hope to have some prototypes ready in the next few weeks.

19 Likes

Wow, great job!

2 Likes