I want to use functionality similar to ShadowOnlyMaterial but in BabylonJS version 4. How can I achieve that?

I have to use BabylonJS version 4 due to other dependencies. But I need effect similar to ShadowOnlyMaterial which only works above BabylonJS version 5. I have tried some tweaks to change transparency and alpha value of the ground but nothing seems to work. Any help would be a lot.

Welcome aboard!

I’m surprised, because it seems the ShadowOnlyMaterial class has been created before the release of 4.0:

  • the history of the packages/dev/materials/src/shadowOnly/shadowOnlyMaterial.ts file shows that it has been added to the Github repository in Sep 28, 2018.
  • we released 4.0 in May 2019

Are you sure it doesn’t work for you because of a dependency problem? You need the babylonjs.material package (or whatever the name was at that time) to be able to use this class.

I cannot import ShadowOnlyMaterial in BabylonJS version 4.2.0.


ShadowOnlyMaterial is in an external package, babylonjs-materials, not in core. See:

Also:

https://doc.babylonjs.com/setup/frameworkPackages/CDN/

I have installed babylonjs-materials using npm i babylonjs-materials and also added CDN in my html:

<script src="https://cdn.babylonjs.com/materialsLibrary/babylon.shadowOnlyMaterial.js"></script>
<script src="https://cdn.babylonjs.com/materialsLibrary/babylonjs.materials.min.js"></script>
<script src="https://cdn.babylonjs.com/materialsLibrary/babylonjs.materials.js"></script>

But still same error occurs. How do I import the ShadowOnlyMaterial package then?

cc @RaananW, who knows a lot more than me about packaging!

1 Like

It seems like you are mixing the es6 and the UMD packages.
You can import from the @babylonjs/materials package, if you use the @babylonjs/core package. If you want to share your project it will be simpler to provide a proper resolution, because I am just fishing information from previous messages and screenshots.

2 Likes