2
$\begingroup$

I'm new to Blender and 3D in general.

I have a single object (mesh), a plane, and no lights and I've set an environment (world?) for my scene. Now, I want to export the scene to GLTF and want to bake the shadows on the plane (the very soft shadows of the object resulted from the environment lights).

I've enabled transparency in Film section and have also made the plane a shadow catcher:

Image showing shadow catcher enabled

When I bake the ambient occlusion for the plane (note that it seems to be important for the color space of the image node to be Non-Color), it results in black and white image. The black is good. I want the white to be transparent:

Image showing the result of ambient occlusion bake

And here is the result GLTF in the browser (using Three.js library):

GLTF version of the scene in browser

So, again, how can I have the plane with only its shadows and the rest transparent?

$\endgroup$

2 Answers 2

3
$\begingroup$

Since we're using the glTF exporter, the "Invert" node is not going to fix the problem. Instead, manually invert the baked ambient occlusion image, using Blender's image editor:

invert screenshot

Be sure to "Pack" or "Save As..." your image after this. It will look quite odd, with the shadows white and the empty parts black, that's OK for now.

Next, set up a node graph that uses this manually-inverted image as the "alpha" input, paired with a fully black "base color" setting. Set metallic and roughness both to 1.0. Make sure the "color" output of the image is being used (as this image contains no alpha of its own), as shown below.

node graph screenshot

Finally, one last important step! Before exporting to glTF, we must set the "blend mode" to "Alpha Blend." To do this, you must temporarily switch your rendering engine from Cycles to Eevee, and make the change in Eevee's material settings. You can switch back to Cycles as soon as this change is done, and Blender will remember that this happened even though it's gone from the UI.

blend mode screenshot

The glTF exporter will find this blend mode, regardless of the selected rendering engine at the time of export.

So now, you should have an all-black material with an opaque (white alpha) alpha channel in places where the shadow should appear, and transparent (black alpha) everywhere the shadow should not appear. It's set to alpha blend mode, because otherwise glTF will ignore the alpha entirely.

Hopefully if you get these steps correct, the export should work. Good luck!

$\endgroup$
2
  • $\begingroup$ Thank you very much. it works. There is only a small problem. the shadows are now more intense. They were very subtle in the image I showed in my question (I had directly connected the image node to "Material Output" node for that). Do you happen know how to make it work? $\endgroup$
    – Mahozad
    Mar 23 at 7:33
  • $\begingroup$ In the inverted image connected to the alpha channel, remember white means fully opaque, and black means transparent. If you decrease the brightness of the whole image, the white parts will become gray, meaning the opaque parts become partially translucent. You may need to either do that outside of Blender, or change the way the image was originally baked. $\endgroup$
    – emackey
    Mar 23 at 12:52
0
$\begingroup$

use a principled bsdf node and place the backed texture into the alpha and base color input of the node, insert a ramp in between the alpha and texture and invert/adjust the contrast until you get the transparency you want and ensure you set the roughness to 1 so their isn't any reflections.

$\endgroup$
2
  • $\begingroup$ Unfortunately I couldn't get it to work. The result is inverted, meaning the shadow pixels are transparent and the rest of the plane is visible. And I could not fix it with an "invert" node. $\endgroup$
    – Mahozad
    Mar 22 at 19:38
  • $\begingroup$ invert the ramp node $\endgroup$ Mar 24 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.