[SOLVED] Cannot load Custom Material and Shaders

Hi guys! I just started working with JME yesterday, so bear with me on this one. Basically, there is some sort of issue when loading my custom glsl shader files from a .j3md file. Am using version 3.5.1-stable and eclipse

This is the error I get:

Apr 11, 2022 9:58:04 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ClassCastException: class java.io.InputStreamReader cannot be cast to class java.lang.String (java.io.InputStreamReader and java.lang.String are in module java.base of loader 'bootstrap')
	at com.jme3.material.TechniqueDef.loadShader(TechniqueDef.java:514)
	at com.jme3.material.TechniqueDef.getShader(TechniqueDef.java:529)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.makeCurrent(DefaultTechniqueDefLogic.java:59)
	at com.jme3.material.Technique.makeCurrent(Technique.java:152)
	at com.jme3.material.Material.render(Material.java:1037)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:651)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:273)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:312)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:928)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:823)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1184)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1248)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:278)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:201)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:833)

This is the code I used to create the material.

Material terr = new Material(manager.getSimpleApp().getAssetManager(), "assets/MatDefs/LowPolyTerrain.j3md");

This is the LowPolyTerrain.j3md file

MaterialDef LowPolyTerrain {
	MaterialParameters {
	Technique {
		VertexShader GLSL100 GLSL150:   assets/Shaders/vterrain.glsl
		FragmentShader GLSL100 GLSL150: assets/Shaders/fterrain.glsl
		WorldParameters {

This is the vterrain.glsl

attribute vec3 inPosition;
uniform mat4 g_WorldViewProjectionMatrix;
void main() {
	gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

And this is the fterrain.glsl

void main() {
	gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0);

Ok so some things I know

  • The issue lies in either the vertex/fragment shader bc it worked properly when I used the Lighting.j3md from the core engine in the LowPolyTerrain.j3md
  • The error does not come about directly after the material is generated, it happens during some rendering stage, so I’m guessing it loads the shaders right before it renders, or something like that.
  • I am assuming that it has something to do with actually loading the files because nothing changed by my copying and pasting the contents of the Lighting frag and vert shaders to the new shaders I am making.
  • I tried changing capitalization in the pathnames to no avail
  • I also know that all files are being read because when they are incorrect, it won’t throw this error and instead tells me they are incorrect.

It seems like it just doesn’t want me to be using my own glsl shaders. Let me know if any additional information is needed!

Any help would be very appreciated :slight_smile:

At least with default project setup one omits the assets. So it would be just MatDefs/LowPolyTerrain.j3md. Same in the shaders then if this is correct. But on the other hand, I would imagine if this is the case, you would get the error sooner or different error.

Perhaps the thing is that there is no asset loader to handle glsl type? Or it is not of expected type. Since typically VertexShader is .vert and FragmentShader is .frag. Asset loaders are registered per file extension.

1 Like

Thank you kind, fellow programmer. It seems that .glsl isn’t recognized, and changing it to vert and frag fixed it. Maybe I missed it somewhere on the docs, but it’d be a nice improvement if this was emphasized a bit more on the docs or maybe there was a different error message xD

jME is pretty flexible. One could actually register an assetLoader for glsl and I guess extend everything like that too. And it clearly opened the asset so… complicated but everything has its own meaning. Well, anyway, glad you got it resolved!

1 Like