If I remove a parameter from a shader’s .j3md file, I have found that it will cause all of the materials using that shader to crash if they still have a value assigned to that paramater in the material file.
As a result, it can become impossible to remove broken or deprecated variables from a shader without having to also update every single material that uses that shader - which sometimes is not possible if the material is embedded into the j3o
Here is the error that is thrown when a material detects a variable defined to a paramater that is not defined in the .j3md file:
com.jme3.asset.AssetLoadException: An exception has occurred while loading asset: /Materials/Vehicles/Mountains.j3m
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:262)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:374)
at com.jme3.asset.DesktopAssetManager.loadMaterial(DesktopAssetManager.java:395)
at com.jayfella.jme.vehicle.examples.worlds.Mountains.load(Mountains.java:98)
at com.jayfella.jme.vehicle.World.attach(World.java:97)
at com.jayfella.jme.vehicle.simpledemo.HelloMav.simpleInitApp(HelloMav.java:113)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:239)
at com.jme3.system.lwjgl.LwjglWindow.initInThread(LwjglWindow.java:513)
at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:625)
at com.jme3.system.lwjgl.LwjglWindow.create(LwjglWindow.java:466)
at com.jme3.app.LegacyApplication.start(LegacyApplication.java:463)
at com.jme3.app.LegacyApplication.start(LegacyApplication.java:424)
at com.jme3.app.SimpleApplication.start(SimpleApplication.java:127)
at com.jayfella.jme.vehicle.simpledemo.HelloMav.main(HelloMav.java:92)
Caused by: java.io.IOException: The material parameter: ProbeColor is undefined.
at com.jme3.material.plugins.J3MLoader.readValueParam(J3MLoader.java:422)
at com.jme3.material.plugins.J3MLoader.readExtendingMaterialParams(J3MLoader.java:441)
at com.jme3.material.plugins.J3MLoader.loadFromRoot(J3MLoader.java:771)
at com.jme3.material.plugins.J3MLoader.load(J3MLoader.java:800)
at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(DesktopAssetManager.java:260)
... 13 more
Specifically this line is where it is happening:
at com.jme3.material.plugins.J3MLoader.readValueParam(J3MLoader.java:422)
This is the code that lies there to check if the param is null, and for some reason throws an error if so:
I think that it would be better to replace this code with a warning instead. Otherwise refactoring old shaders to remove unused variables will not be possible without a lot of extra work editing each material file.
I am curious what the rest of you may think about this proposed change?