Blender render experiments

I’ve been putting off using Blender since over 5 years, being intimidated by the complex UI and workflow, until this month when I mustered courage to go through Andrew Price’s Doughnut tutorials. My aim was to learn how to do photo-realistic renders of KiCad boards.

I started off with the Open Hardware Summit 2020 badge (which I had a bit role in designing). KiCad’s in-built ray-tracer does a decent job, but there is no way to adjust lighting, background and other parameters. This is what it looks like in KiCad.

Normal 3D view from KiCad
Google Photos

Raytraced render from KiCad - bottom side
Google Photos
This is the bottom of the PCB, so the “floor” is not visible, and the overall render looks darker than expected.

Raytraced render from KiCad - top side
As a comparison, here’s what the top view looks like. You can see shadows on the floor. There are multiple light sources (multiple shadows), and the scene looks washed out due to excess light.
Google Photos

Unfortunately, KiCad raytrace option does not allow us to set lighting, floor and other scene parameters, hence Blender. So my next step was to export VRML and STEP file models from KiCad.

The STEP export from KiCad is useful in MCAD for designing enclosures and such, but it doesn’t have copper and silk layers, and no material textures too. So it isn’t much use for realistic renders.

STEP import in FreeCAD
Google Photos

VRML import in FreeCAD
Google Photos

One important difference between the raytrace render as seen in KiCad v/s the exported VRML is the “MASK” layer. Look at the “W” in the OSHW logo and the “qwiic” logo. In the KiCad design, there’s a mask opening over these elements so that the underlying Copper/Gold is visible in KiCad 3D. In the VRML export, this mask window gets covered over. So the VRML export from KiCad is not a faithful representation of the board.

I ran another test by using KiCad StepUp Tools workbench in FreeCAD to import the Board with parts and Copper and Silk layers. Once again, the result was the same - the mask openings do not show up as in the pic below.

KSU Tools import in FreeCAD with Copper and Silk
Google Photos

At this moment, I not sure how to resolve this - so anyone have suggestions, please comment away.

Anyway, next step was to move to Blender and try getting better renders. Here’s what the KiCad VRML import looks like in Blender.

VRML import in Blender
Google Photos

According to @maui in this thread, from Blender ver 2.8 onwards, the WRL/X3D importer has been changed causing the lack of color/texture import.

Opening the KiCad VRML file in Meshlab produces expected results.

VRML import in Meshlab
Google Photos

A workaround to this that I stumbled upon is to use the online 3D file format converter at CADexchanger and convert the KiCad VRML file to a Collada DAE format. Importing the DAE format in Blender results in glorious color renders.

COLLADA DAE import in Blender
Google Photos

And now we can fine tune the colors, roughness (shininess), subsurface (internal reflectance / translucency ?) for the PCB fiberglass material (PCB edge), mask, copper, silk, adjust the lighting, change the background etc.

Google Photos

Google Photos

Google Photos

Google Photos

So the workflow looks good now, and it’s possible to get nice renders using Blender. At the moment, render quality is only hampered by my very limited knowledge of Blender (about 2 weeks old) - so more experienced Blender power users will be able to do much better.

Also, FreeCAD ver 0.19 Render workbench has a Blender option now, with Cycles rendering, but I haven’t yet got around to figuring out how to use it.
Google Photos

The one issue which needs to be resolved is the inaccurate “mask” layer export from KiCad and I’m hoping anyone with more insight on this can tell us how to get it right.

Next up, i’m going to try making the initial footprint models more realistic by adding device information on the packages and such.

In a later post, I’ll describe the Blender workflow needed to get :
– Colors for the various PCB elements – fibreglass body, solder mask, copper, silk legend
– Adjusting light and camera (although there are a lot more better, detailed tutorials on this that you can find)

If someone can figure out a way to avoid the KiCad VRML <> CadExchanger COLLADA DAE conversion, it would be awesome.

11 Likes

In the future v6 will have a bit more possibilities, but Blender may still be the way to go. Post-v5 new features and development news.

1 Like

The 3D render is a good visual check and useful as an integral tool. I’d prefer the developers spend more time on the PCB layout part. So, yeah, making the output Blender friendly would be the better option in my opinion.

2 Likes

I’m starting to think the FAQ may need a tutorial section? Not sure something like this is ‘frequently asked’. :wink:

2 Likes

This is certainly a bug IMO, please report it.

1 Like

Seems like an open issue since 5 years, and confirmed by you about 6 month ago.

I’ll add my response there, but I guess we ought to wait and see how things turn out in v6.

I figured out an easy workaround to the mask opening over copper areas issue for VRML export from KiCad.

For any footprint with copper area that needs a mask opening (such as Logos, which typically won’t have any pads), the solution is to edit the footprint and add a copper “anchor” pad. The pad doesn’t have to be numbered or assigned to any net. Adding a small SMD pad is sufficient.

Google Photos

1 Like

Could you point which one are the openings that differ in both pictures ?

I am assuming that those are the ones here:

But I do not know the board, moreover in your last render where you mentioned your workaround (beautiful btw!), they are purple not copper color.

Just interested, thanks.

Yes, the parts you marked are the ones I was referring to.
Problem with the last render is PEBKAC - I still have to learn a lot about the lighting and rendering part. But here’s a better view.

Google Photos

Google Photos

1 Like

Got it, thanks a lot for sharing. It looks stunning!

1 Like

Now you need to check on the placement of the qwiic logo. It appears to be shorting the I2C lines in your render. (And looks larger relative to the other board features compared to your previous renderings in this thread.)

But kudos on finding a workaround.

Logo shorting the tracks - yes, indeed. I was just focussed on solving the immediate problem (but I fixed it later).
While I was at it, I redesigned the footprint from scratch via FreeCAD stepup tools, which is also why it appears larger in the latest renders.
The badges have already been produced, so luckily whatever changes I make to my version of the board will be virtual.

This is really neat! Thanks for taking the time to document your process. With all the badges still trapped at NYC, it is nice to see they can live in full 3D in cyberspace :slight_smile:

1 Like

Another option to convert the .wrl to .dae is to use blender 2.79 i.e. import .wrl to blender 2.79 then export from blender 2.79 to a .dae file.

Note the blender does not need to be installed. So you can just copy blender 2.79 to your local drive and run it directly. Therefore, you can have multiple blenders on the same computer.

Having said that, I really hope the latest blender can fix the .wrl issue. I took a look at the import_x3d.py but could not figure it out due to my poor .wrl knowledge.

1 Like

Having used blender for one week, this is the best result I got so far. I only use the Principled BSDF shader. Several tricks I learned along the way:

  1. For the metal parts including component pad/solder pad/other metal part, use metal=1, roughness=0.2 or 0.3
  2. For transparent glass like the LED, use metal=0.2, roughness=0.1, transmission=1
  3. For translucent plastic part like the JST connector, use metal=0, subsurface=1, and choose subsurface color accordingly
  4. For hard plastic part like the IC component, use metal=0.3, roughness=0.5, subsurface=1

3 Likes

you can find a workaround here:
https://developer.blender.org/T71232

1 Like

Thank you! It works very well.

For anyone who is looking for a solution, you need to replace the appearance_CreateMaterial() function definition in import_x3d.py with the following:

def appearance_CreateMaterial(vrmlname, mat, ancestry, is_vcol):
bpymat = bpy.data.materials.new(vrmlname)
diff_color = mat.getFieldAsFloatTuple('diffuseColor', [0.5, 0.5, 0.5, 1], ancestry)

if(len(diff_color) == 3):
    # .wrl does not have alpha, we need to add 4th element
    diff_color = diff_color+[1]
bpymat.diffuse_color = diff_color
spec_color = mat.getFieldAsFloatTuple('specularColor', [0.0, 0.0, 0.0], ancestry)
bpymat.specular_color = spec_color
return bpymat

The import_x3d.py file can be found in [blender install path]\2.90\scripts\addons\io_scene_x3d

2 Likes

Just to state the obvious:
There are several tutorials for using Blender for rendering KiCad boards on:
https://www.youtube.com/results?search_query=%2Bblender+%2Bkicad

[Rant]
For some kind of irritating reason it seems to be “modern” to use logical or instead of logical and in search engines these days. With the result that you get more clutter if you try to narrow down your search. Just another way in which the Internet is ever more deteriorating.
[/rant]

Here is a comparative render of @Anool files from his Kicad->Blender workshop with the current development of KiCad:

2 Likes

Wow !! V6 I hope :smirk: :stuck_out_tongue: