I am still having trouble with Lighting.j3md
Surely other people don’t have this problem or you wouldn’t get far on Android at all, so is there something wrong with this code?:
I started a new basic game, then added this.
[java]
@Override
public void simpleInitApp() {
Spatial box = new Geometry(“My Box”, new Box(1,1,1));
Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
box.setMaterial(mat);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
rootNode.addLight(sun);
rootNode.attachChild(box);
}
[/java]
Gives this exception:
12-01 20:02:31.939: ERROR/AndroidHarness(19487): com.jme3.renderer.RendererException: Shader link failure, shader:Shader[language=GLSL100, numSources=2, numUniforms=12, shaderSources=[ShaderSource[name=Common/MatDefs/Light/Lighting.vert, defines, type=Vertex], ShaderSource[name=Common/MatDefs/Light/Lighting.frag, defines, type=Fragment]]] info:Error: varying variables do not fit in 8 vectors.
12-01 20:02:31.939: ERROR/AndroidHarness(19487): Error: varying variables do not fit in 8 vectors.
12-01 20:02:31.969: ERROR/AndroidHarness(19487): SEVERE AndroidHarness 8:02:31 PM Exception thrown in Thread[GLThread 12,5,main]: at com.jme3.renderer.android.OGLESShaderRenderer.updateShaderData(1195)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.android.OGLESShaderRenderer.setShader(1239)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.material.Material.renderMultipassLighting(799)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.material.Material.render(1026)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.RenderManager.renderGeometry(657)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.queue.RenderQueue.renderGeometryList(299)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.queue.RenderQueue.renderQueue(351)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.RenderManager.renderViewPortQueues(894)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.RenderManager.flushQueue(850)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.RenderManager.renderViewPort(1126)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.renderer.RenderManager.render(1168)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.app.SimpleApplication.update(266)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at com.jme3.system.android.OGLESContext.onDrawFrame(418)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at android.opengl.GLSurfaceView$GLThread.guardedRun(1363)
12-01 20:02:31.969: ERROR/AndroidHarness(19487): at android.opengl.GLSurfaceView$GLThread.run(1118)
If I use [java]new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);[/java] it works, so I am almost certain it’s the lighting shaders.
I have Desire HD, running andoird 2.3.3
OK, I have resolved this.
8 varying vectors is obviously the limit for android, or maybe my hardware, interesting if others know this?
So I looked at the shaders and picked one of the defines to set that affects the number of varying vectors.
In code I have to do this:
[java]
Material mat = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat.setBoolean(“VertexLighting”, true);
[/java]
That’s just one define, there’s a bunch listed in the Lighting.j3md.
This comes directly from the ogl es 2 specification:
“The minimum number of varying vectors that an implementation of OpenGL ES 2.0 can support is eight.”
Of course different hardware can support more than eight.
@weston2k said:
OK, I have resolved this.
8 varying vectors is obviously the limit for android, or maybe my hardware, interesting if others know this?
So I looked at the shaders and picked one of the defines to set that affects the number of varying vectors.
In code I have to do this:
[java]
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("VertexLighting", true);
[/java]
That's just one define, there's a bunch listed in the Lighting.j3md.
Yeah we have to clean up the lighting material or do a specific one for android.
It's a known issue.
VertexLighting to true means you'll have a lower shading quality (lighting is computed per vertex instead of per pixel) but it will give you better performances.
And that's quite valuable on this kind of devices.