Shader compilation problem in 3.1.0beta1

I’m trying to upgrade to 3.1.0beta1 from 3.0.10 and I’m hitting an error when my game starts. Here is the error:

Aug 13, 2016 12:37:49 AM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
WARNING: Bad compile of:
1	#version 110
2	#define FRAGMENT_SHADER 1
3	#define HAS_COLORMAP 1
4	#define HAS_VERTEXCOLOR 1
5	#define DISCARD_ALPHA 0.1
6	#if defined(HAS_GLOWMAP) || defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
7	    #define NEED_TEXCOORD1
8	#endif
9	
10	#if defined(DISCARD_ALPHA)
11	    uniform float m_AlphaDiscardThreshold;
12	#endif
13	
14	uniform vec4 m_Color;
15	uniform sampler2D m_ColorMap;
16	uniform sampler2D m_LightMap;
17	uniform float m_dayNightLighting;
18	
19	varying vec2 texCoord1;
20	varying vec2 texCoord2;
21	
22	varying vec4 vertColor;
23	varying float light;
24	
25	attribute vec3 inNormal;
26	void main(){
27	    vec4 color = vec4(1.0);
28		
29	    #ifdef HAS_COLORMAP
30	        color *= texture2D(m_ColorMap, texCoord1);     
31	    #endif
32	
33	    #ifdef HAS_COLOR
34	        color *= m_Color;
35	    #endif
36	
37	    #ifdef HAS_VERTEXCOLOR
38	        color *= vertColor;
39	    #endif
40	
41	    #ifdef HAS_LIGHTMAP
42	        #ifdef SEPARATE_TEXCOORD
43	            color.rgb *= texture2D(m_LightMap, texCoord2).rgb;
44	        #else
45	            color.rgb *= texture2D(m_LightMap, texCoord1).rgb;
46	        #endif
47	    #endif
48	
49	    #if defined(DISCARD_ALPHA)
50	        if(color.a < m_AlphaDiscardThreshold){
51	           discard;
52	        }
53	    #endif
54	    
55	    gl_FragColor = color;
56	}

Aug 13, 2016 12:37:49 AM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=MatDefs/Blocks.frag, defines, type=Fragment, language=GLSL100]
0(25) : error C7513: OpenGL does not allow attribute variables in fragment shaders

	at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
	at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
	at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:94)
	at com.jme3.material.Technique.render(Technique.java:167)
	at com.jme3.material.Material.render(Material.java:966)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:616)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:870)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:781)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1097)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Unknown Source)

Aug 13, 2016 12:37:50 AM com.chappelle.jcraft.GameSettings save
INFO: Saving options to C:\Users\jchappelle\AppData\Roaming\.jcraft\jcraft-options.txt

I’m not an expert in shaders. This is a voxel game and it’s actually the only shader I have ever written. It’s for day/night lighting and it works very well in 3.0.10.

I don’t doubt this is pointing to a real problem or a potential problem. However, it says Open GL doesn’t allow something that obviously it does because I’m running just fine in 3.0.10.

Any help or guidance is greatly appreciated.

Do you run an nVidia card by any chance? Is your j3md specifying GLSL100 as the version for the .frag shader?

Edit: because if that’s true then you were allowed to get away with it before but it would break on other cards. I can explain why in more detail but in case you get this answer before I see a response then you can at least fix the problem in your shader in the mean time.

in allowed only in vertex shader (.vert). “inNormal” is not used in your code, so simply remove the line 25.

@pspeed,

Yes it is an NVIDIA Quadro 1000M. I use a Windows 10 laptop. In my display drivers it also shows an Intel® HD Graphics 3000. I guess one is for my attached monitor and the other for when I connect an external monitor. I’m guessing the attached monitor is using the NVIDIA one.

@david_bernard_31,

I removed the inNormal variable and when I run now I get a different error. It seems to be complaining about my Blocks.vert now so I think your suggestion fixed the frag shader. Below I’m listing the full log at startup including the error.

Aug 13, 2016 3:01:12 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.1-beta1
 * Branch: HEAD
 * Git Hash: 310f4db
 * Build Date: 2016-04-25
Aug 13, 2016 3:01:13 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 2.9.3 context running on thread jME3 Main
 * Graphics Adapter: igdumd64
 * Driver Version: 9.17.10.4229
 * Scaling Factor: 1
Aug 13, 2016 3:01:13 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: Quadro 1000M/PCIe/SSE2
 * OpenGL Version: 4.5.0 NVIDIA 353.62
 * GLSL Version: 4.50 NVIDIA
 * Profile: Compatibility
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
Aug 13, 2016 3:01:13 PM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
Aug 13, 2016 3:01:13 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.15.1
 * Supported channels: 64
 * ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
 * AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
Aug 13, 2016 3:01:13 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
WARNING: Pausing audio device not supported.
Aug 13, 2016 3:01:13 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Aug 13, 2016 3:01:13 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 4
Aug 13, 2016 3:01:14 PM com.jme3.material.plugins.J3MLoader readTechnique
WARNING: Fixed function technique was ignored
Aug 13, 2016 3:01:14 PM com.jme3.material.plugins.J3MLoader readTechnique
WARNING: Fixed function technique 'Default' was ignored for material MatDefs/Blocks.j3md
Aug 13, 2016 3:01:14 PM com.chappelle.jcraft.BlockApplication initBlockTerrain
INFO: Using world seed: 1470193765295
Aug 13, 2016 3:01:14 PM com.chappelle.jcraft.BlockApplication initBlockTerrain
INFO: Loading world JCraftWorld
Aug 13, 2016 3:01:14 PM com.chappelle.jcraft.BlockApplication initBlockTerrain
INFO: Creating new world...get ready!
Aug 13, 2016 3:01:16 PM com.chappelle.jcraft.BlockApplication simpleInitApp
INFO: ****************************************************************************
Aug 13, 2016 3:01:16 PM com.chappelle.jcraft.BlockApplication simpleInitApp
INFO: Press F1 for fullscreen, F3 to toggle debug, F4 to toggle profiler.
Aug 13, 2016 3:01:16 PM com.chappelle.jcraft.BlockApplication simpleInitApp
INFO: See key bindings in JCraft class for other controls
Aug 13, 2016 3:01:16 PM com.chappelle.jcraft.BlockApplication simpleInitApp
INFO: ****************************************************************************
Aug 13, 2016 3:01:16 PM com.chappelle.jcraft.BlockApplication simpleInitApp
INFO: 


Aug 13, 2016 3:01:16 PM com.jme3.renderer.opengl.GLRenderer updateShaderSourceData
WARNING: Bad compile of:
1	#version 110
2	#define VERTEX_SHADER 1
3	#define HAS_COLORMAP 1
4	#define HAS_VERTEXCOLOR 1
5	#define DISCARD_ALPHA 0.1
6	// -- begin import Common/ShaderLib/Skinning.glsllib --
7	#ifdef NUM_BONES
8	
9	#if NUM_BONES < 1 || NUM_BONES > 255
10	#error NUM_BONES must be between 1 and 255.
11	#endif
12	
13	#define NUM_WEIGHTS_PER_VERT 4
14	 
15	attribute vec4 inHWBoneWeight;
16	attribute vec4 inHWBoneIndex;
17	uniform mat4 m_BoneMatrices[NUM_BONES];
18	
19	void Skinning_Compute(inout vec4 position){
20	    if (inHWBoneWeight.x != 0.0) {
21	#if NUM_WEIGHTS_PER_VERT == 1
22	        position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
23	#else
24	        mat4 mat = mat4(0.0);
25	        mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
26	        mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
27	        mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
28	        mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
29	        position = mat * position;
30	#endif
31	    }
32	}
33	 
34	void Skinning_Compute(inout vec4 position, inout vec3 normal){
35	    if (inHWBoneWeight.x != 0.0) {
36	#if NUM_WEIGHTS_PER_VERT == 1
37	        position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
38	        normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
39	                       m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
40	                       m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
41	#else
42	        mat4 mat = mat4(0.0);
43	        mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
44	        mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
45	        mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
46	        mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
47	        position = mat * position;
48	
49	        mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
50	        normal = rotMat * normal;
51	#endif
52	    }
53	}
54	 
55	void Skinning_Compute(inout vec4 position, inout vec3 tangent, inout vec3 normal){
56	    if (inHWBoneWeight.x != 0.0) {
57	#if NUM_WEIGHTS_PER_VERT == 1
58	        position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
59	        tangent = m_BoneMatrices[int(inHWBoneIndex.x)] * tangent;
60	        normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
61	                       m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
62	                       m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
63	#else
64	        mat4 mat = mat4(0.0);
65	        mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
66	        mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
67	        mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
68	        mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
69	        position = mat * position;
70	
71	        mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
72	        tangent = rotMat * tangent;
73	        normal = rotMat * normal;
74	#endif
75	    }
76	}
77	
78	#endif
79	// -- end import Common/ShaderLib/Skinning.glsllib --
80	
81	uniform mat4 g_WorldViewProjectionMatrix;
82	attribute vec3 inPosition;
83	
84	#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
85	    #define NEED_TEXCOORD1
86	#endif
87	
88	attribute vec2 inTexCoord;
89	attribute vec2 inTexCoord2;
90	attribute vec4 inColor;
91	attribute vec3 inNormal;
92	
93	varying vec2 texCoord1;
94	varying vec2 texCoord2;
95	varying float light;
96	varying vec4 vertColor;
97	
98	uniform float m_dayNightLighting;
99	uniform float lightTable[] = float[16](0.05f, 0.067f, 0.085f, 0.106f, 0.129f, 0.156f, 0.186f, 0.221f, 0.261f, 0.309f, 0.367f, 0.437f, 0.525f, 0.638f, 0.789f, 1.0f);
100	
101	void main()
102	{
103		float skyLight = lightTable[int(inColor.a)] * m_dayNightLighting;
104		float blockLight = lightTable[int(inColor.g)];
105		light = max(blockLight, skyLight);
106		if(inNormal.x != 0)
107		{
108			light*=0.8;
109		}
110		else if(inNormal.z != 0)
111		{
112			light*=0.6;
113		}
114		else if(inNormal.y == -1)
115		{
116			light*=0.5;
117		}
118		inColor.r = light;
119		inColor.g = light;
120		inColor.b = light;
121		inColor.a = 1.0;
122		
123	    #ifdef NEED_TEXCOORD1
124	        texCoord1 = inTexCoord;
125	    #endif
126	
127	    #ifdef SEPARATE_TEXCOORD
128	        texCoord2 = inTexCoord2;
129	    #endif
130	
131	    #ifdef HAS_VERTEXCOLOR
132	        vertColor = inColor;
133	    #endif
134	
135	    vec4 modelSpacePos = vec4(inPosition, 1.0);
136	    #ifdef NUM_BONES
137	        Skinning_Compute(modelSpacePos);
138	    #endif
139	    gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
140	}

Aug 13, 2016 3:01:16 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=MatDefs/Blocks.vert, defines, type=Vertex, language=GLSL100]
0(99) : error C7551: OpenGL first class arrays require #version 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions below 120
0(99) : error C7583: Initialization of uniform variables requires #version 120 or later
0(106) : error C7011: implicit cast from "int" to "float"
0(110) : error C7011: implicit cast from "int" to "float"
0(114) : error C7011: implicit cast from "int" to "float"
0(118) : error C7564: assignment to attribute inColor
0(119) : error C7564: assignment to attribute inColor
0(120) : error C7564: assignment to attribute inColor
0(121) : error C7564: assignment to attribute inColor

	at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
	at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
	at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:94)
	at com.jme3.material.Technique.render(Technique.java:167)
	at com.jme3.material.Material.render(Material.java:966)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:616)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:870)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:781)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1097)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Unknown Source)

Well, it’s telling you what the exact errors are and they are all simple to solve.

The issue you had with 3.0 is that by specifying GLSL100, JME 3.0 wouldn’t put any #version in the shader. That’s not a real GLSL version. This ends up putting nvidia cards into compatibility mode which lets you do a bunch of things that will break on other graphics cards. Things like float f = 1 instead of float f = 1.0, etc…

JME used the GLSL100 as a non-version so you could write shaders that were compatible with mobile and desktop. However, in 3.1 we fixed it so that it knows the platform and puts the proper version in, in this case. Better for everyone since now they get proper errors on nvidia cards.

So, you always had OpenGL errors in your shaders… they were just being hidden before.

Ok I got it down to this error pretty quickly but it’s apparent I need to learn more about writing shaders to proceed. Which is fine. I don’t expect to be spoon fed. I’m just posting the error in case anyone wants to throw me a bone. If I’m really stuck I’ll post a more specific question about the remaining error. By the look of the errors I should be able to figure it out when I understand the types of all these variables and how to specify gl version.

Thanks for the help everyone!

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=MatDefs/Blocks.vert, defines, type=Vertex, language=GLSL100]
0(99) : error C7551: OpenGL first class arrays require #version 120
0(99) : error C7583: Initialization of uniform variables requires #version 120 or later
0(106) : error C7011: implicit cast from "int" to "float"
0(110) : error C7011: implicit cast from "int" to "float"
0(114) : error C7011: implicit cast from "int" to "float"
0(118) : error C7564: assignment to attribute inColor
0(119) : error C7564: assignment to attribute inColor
0(120) : error C7564: assignment to attribute inColor
0(121) : error C7564: assignment to attribute inColor

	at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
	at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
	at com.jme3.renderer.opengl.GLRenderer.setShader(GLRenderer.java:1291)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.render(DefaultTechniqueDefLogic.java:94)
	at com.jme3.material.Technique.render(Technique.java:167)
	at com.jme3.material.Material.render(Material.java:966)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:616)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:266)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:305)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:870)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:781)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1097)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1145)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:253)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Unknown Source)

Well, partially I’m not sure why the errors are unclear…

On line 99 of the (not included) shader source you are using a feature that is only available in GLSL120.

…same with the next error you list.

Continuing…

On line 106 you are treating an int as a float. Probably something like 0 when you meant 0.0.

On line 118 you must be trying to assign something to an attribute. You can’t do that. Note how none of the JME shaders do this and instead pull the attribute into a local variable to modify that local variable instead.

Just a bit of a side point to the thrust of this discussion, but thought I would clarify something.

The arrangement you have here is pretty typical of higher-performance Intel based laptops. The HD Graphics 3000 is actually integrated into the CPU package, (I think its on the same die) while the Nvidia card is, of course, a stand-alone graphics card. Both of them can drive any display connected to your laptop, including the built-in one.

In theory, it works like this: When GPU load is light, such as during normal desktop work, the integrated chip handles the load. This is an energy-saving feature, as it pulls less power than the Nvidia. When adding heavier loads, such as playing a big FPS, the Nvidia card steps in to get you good graphics performance.

Some packages, such as JOCL, (Jogamp’s openCL java binding) will be able to see both cards, and can assign tasks to them simultaneously.

I was finally able to get rid of the errors but the way in which I did it causes the shader to not function. The result is a black screen.

@pspeed,

I agree the errors were pretty straightforward. As you know I was more interested in experimenting with Lemur and since it’s not compatible with 3.0.10 I decided to upgrade to 3.1.

The first class array error was because of this line:
uniform float lightTable[] = float[16](0.05f, 0.067f, 0.085f, 0.106f, 0.129f, 0.156f, 0.186f, 0.221f, 0.261f, 0.309f, 0.367f, 0.437f, 0.525f, 0.638f, 0.789f, 1.0f);

Apparently you are supposed to declare and initialize like so(note: i’ve reverted my changes so I’m going off of memory)
uniform float lightTable[16] = float[](0.05, 0.067, 0.085, 0.106, 0.129, 0.156, 0.186, 0.221, 0.261, 0.309, 0.367, 0.437, 0.525, 0.638, 0.789, 1.0);

I also found the implicit cast and I’ve already changed that so it won’t be in the following shader code. The part that I’m still unsure of is perhaps the most important because I’m pretty sure my solution(or attempted solutions) is what caused my scene to go dark.

In my vertex shader I’m calculating color for a specific vertex of my blocks. I only wanted to do this calculation for each vertex which is why I don’t do that calculation in my fragment shader. At the time it seemed like a good idea to just set the inColor rgba values. Apparently that’s a no no. I’m just not sure how to pass that variable along to my fragment shader. I have a varying light variable that is the result of the calculation and I thought my fragment shader would be able to access that. So I accessed it and basically set the rgba of the gl_FragColor variable in my fragment shader instead. I tried a couple of other things like adding “out” after varying in my vertex shader and “in” after varying in my fragment shader’s declaration of the light variable but still no luck.

I realize this is pretty basic stuff but it’s pretty hard to debug a shader because it’s all or nothing. One little bug and the screen is black or it blows up. You can’t System.out the variable values either. Any advice on how you guys do this would be great.

Here’s the shaders as they are in 3.0.10. Please note that a couple of the syntax errors I listed before have been fixed. The main one that hasn’t is the attribute assignment problem.

There’s probably a lot of fluff that I don’t need in these since I think I copied from an existing material.

Thanks for the replies thus far!

Blocks.frag

#if defined(HAS_GLOWMAP) || defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
    #define NEED_TEXCOORD1
#endif

#if defined(DISCARD_ALPHA)
    uniform float m_AlphaDiscardThreshold;
#endif

uniform vec4 m_Color;
uniform sampler2D m_ColorMap;
uniform sampler2D m_LightMap;
uniform float m_dayNightLighting;

varying vec2 texCoord1;
varying vec2 texCoord2;

varying vec4 vertColor;
varying float light;

attribute vec3 inNormal;
void main(){
    vec4 color = vec4(1.0);
	
    #ifdef HAS_COLORMAP
        color *= texture2D(m_ColorMap, texCoord1);     
    #endif

    #ifdef HAS_COLOR
        color *= m_Color;
    #endif

    #ifdef HAS_VERTEXCOLOR
        color *= vertColor;
    #endif

    #ifdef HAS_LIGHTMAP
        #ifdef SEPARATE_TEXCOORD
            color.rgb *= texture2D(m_LightMap, texCoord2).rgb;
        #else
            color.rgb *= texture2D(m_LightMap, texCoord1).rgb;
        #endif
    #endif

    #if defined(DISCARD_ALPHA)
        if(color.a < m_AlphaDiscardThreshold){
           discard;
        }
    #endif
    
    gl_FragColor = color;
}

Blocks.vert

#import "Common/ShaderLib/Skinning.glsllib"

uniform mat4 g_WorldViewProjectionMatrix;
attribute vec3 inPosition;

#if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
    #define NEED_TEXCOORD1
#endif

attribute vec2 inTexCoord;
attribute vec2 inTexCoord2;
attribute vec4 inColor;
attribute vec3 inNormal;

varying vec2 texCoord1;
varying vec2 texCoord2;
varying float light;
varying vec4 vertColor;

uniform float m_dayNightLighting;
uniform float lightTable[] = float[16](0.05f, 0.067f, 0.085f, 0.106f, 0.129f, 0.156f, 0.186f, 0.221f, 0.261f, 0.309f, 0.367f, 0.437f, 0.525f, 0.638f, 0.789f, 1.0f);

void main()
{
	float skyLight = lightTable[int(inColor.a)] * m_dayNightLighting;
	float blockLight = lightTable[int(inColor.g)];
	light = max(blockLight, skyLight);
	if(inNormal.x != 0)
	{
		light*=0.8;
	}
	else if(inNormal.z != 0)
	{
		light*=0.6;
	}
	else if(inNormal.y == -1)
	{
		light*=0.5;
	}
	inColor.r = light;
	inColor.g = light;
	inColor.b = light;
	inColor.a = 1.0;
	
    #ifdef NEED_TEXCOORD1
        texCoord1 = inTexCoord;
    #endif

    #ifdef SEPARATE_TEXCOORD
        texCoord2 = inTexCoord2;
    #endif

    #ifdef HAS_VERTEXCOLOR
        vertColor = inColor;
    #endif

    vec4 modelSpacePos = vec4(inPosition, 1.0);
    #ifdef NUM_BONES
        Skinning_Compute(modelSpacePos);
    #endif
    gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
}

Blocks.j3md

MaterialDef Blocks {

    MaterialParameters {
    	Float dayNightLighting;
        Texture2D ColorMap
        Texture2D LightMap
        Color Color (Color)
        Boolean VertexColor (UseVertexColor)
        Boolean SeparateTexCoord

        // Texture of the glowing parts of the material
        Texture2D GlowMap
        // The glow color of the object
        Color GlowColor

        // For hardware skinning
        Int NumberOfBones
        Matrix4Array BoneMatrices

        // Alpha threshold for fragment discarding
        Float AlphaDiscardThreshold (AlphaTestFallOff)

        //Shadows
        Int FilterMode
        Boolean HardwareShadows

        Texture2D ShadowMap0
        Texture2D ShadowMap1
        Texture2D ShadowMap2
        Texture2D ShadowMap3
        //pointLights
        Texture2D ShadowMap4
        Texture2D ShadowMap5
        
        Float ShadowIntensity
        Vector4 Splits
        Vector2 FadeInfo

        Matrix4 LightViewProjectionMatrix0
        Matrix4 LightViewProjectionMatrix1
        Matrix4 LightViewProjectionMatrix2
        Matrix4 LightViewProjectionMatrix3
        //pointLight
        Matrix4 LightViewProjectionMatrix4
        Matrix4 LightViewProjectionMatrix5
        Vector3 LightPos

        Float PCFEdge

        Float ShadowMapSize
    }

    Technique {
        VertexShader GLSL100:   MatDefs/Blocks.vert
        FragmentShader GLSL100: MatDefs/Blocks.frag

        WorldParameters {
            WorldViewProjectionMatrix
        }

        Defines {
            SEPARATE_TEXCOORD : SeparateTexCoord
            HAS_COLORMAP : ColorMap
            HAS_LIGHTMAP : LightMap
            HAS_VERTEXCOLOR : VertexColor
            HAS_COLOR : Color
            NUM_BONES : NumberOfBones
            DISCARD_ALPHA : AlphaDiscardThreshold
        }
    }

    Technique {
    }

    Technique PreNormalPass {

          VertexShader GLSL100 :   Common/MatDefs/SSAO/normal.vert
          FragmentShader GLSL100 : Common/MatDefs/SSAO/normal.frag

          WorldParameters {
              WorldViewProjectionMatrix
              WorldViewMatrix
              NormalMatrix
          }

          Defines {
              NUM_BONES : NumberOfBones
          }
   }

    Technique PreShadow {

        VertexShader GLSL100 :   Common/MatDefs/Shadow/PreShadow.vert
        FragmentShader GLSL100 : Common/MatDefs/Shadow/PreShadow.frag

        WorldParameters {
            WorldViewProjectionMatrix
            WorldViewMatrix
        }

        Defines {
            COLOR_MAP : ColorMap
            DISCARD_ALPHA : AlphaDiscardThreshold
            NUM_BONES : NumberOfBones
        }

        ForcedRenderState {
            FaceCull Off
            DepthTest On
            DepthWrite On
            PolyOffset 5 3
            ColorWrite Off
        }

    }


    Technique PostShadow15{
        VertexShader GLSL150:   Common/MatDefs/Shadow/PostShadow.vert
        FragmentShader GLSL150: Common/MatDefs/Shadow/PostShadow15.frag

        WorldParameters {
            WorldViewProjectionMatrix
            WorldMatrix
        }

        Defines {
            HARDWARE_SHADOWS : HardwareShadows
            FILTER_MODE : FilterMode
            PCFEDGE : PCFEdge
            DISCARD_ALPHA : AlphaDiscardThreshold           
            COLOR_MAP : ColorMap
            SHADOWMAP_SIZE : ShadowMapSize
            FADE : FadeInfo
            PSSM : Splits
            POINTLIGHT : LightViewProjectionMatrix5
            NUM_BONES : NumberOfBones
        }

        ForcedRenderState {
            Blend Modulate
            DepthWrite Off                 
            PolyOffset -0.1 0
        }
    }

    Technique PostShadow{
        VertexShader GLSL100:   Common/MatDefs/Shadow/PostShadow.vert
        FragmentShader GLSL100: Common/MatDefs/Shadow/PostShadow.frag

        WorldParameters {
            WorldViewProjectionMatrix
            WorldMatrix
        }

        Defines {
            HARDWARE_SHADOWS : HardwareShadows
            FILTER_MODE : FilterMode
            PCFEDGE : PCFEdge
            DISCARD_ALPHA : AlphaDiscardThreshold           
            COLOR_MAP : ColorMap
            SHADOWMAP_SIZE : ShadowMapSize
            FADE : FadeInfo
            PSSM : Splits
            POINTLIGHT : LightViewProjectionMatrix5
            NUM_BONES : NumberOfBones
        }

        ForcedRenderState {
            Blend Modulate
            DepthWrite Off   
            PolyOffset -0.1 0  
        }
    }

    Technique Glow {

        VertexShader GLSL100:   MatDefs/Blocks.vert
        FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag

        WorldParameters {
            WorldViewProjectionMatrix
        }

        Defines {
            NEED_TEXCOORD1
            HAS_GLOWMAP : GlowMap
            HAS_GLOWCOLOR : GlowColor
            NUM_BONES : NumberOfBones
        }
    }
}

ChunkMaterial.java

public class ChunkMaterial extends Material
{
    public ChunkMaterial(AssetManager assetManager, String blockTextureFilePath)
    {
    	super(assetManager, "MatDefs/Blocks.j3md");
    	
    	Texture texture = assetManager.loadTexture(blockTextureFilePath);
    	texture.setMagFilter(Texture.MagFilter.Nearest);
    	texture.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
    	setTexture("ColorMap", texture);

    	setBoolean("VertexColor", true);
    	getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    	setFloat("dayNightLighting", 1.0f);
    	setFloat("AlphaDiscardThreshold", 0.1f);
    }
}

This is a side project and my day job isn’t game development. All things considered I’ve actually made good progress on the game. Here’s a screenshot if you’re interested. Had to share with someone since my wife couldn’t care less :slight_smile:

2 Likes

You can’t do this. This will only work on nVidia cards on windows, basically… and only if compatibility mode is switched on. (ie: it may suddenly stop working even on nvidia cards.

Since you ultimately just do this:
vertColor = inColor;

…just put the color setup after and set them on vertColor instead.

vertColor.r = light;
vertColor.g = light;
vertColor.b = light;
vertColor.a = 1.0;

The two are functionally identical except that this one will work on more than just a subset of graphics cards.

If your shader stops working then it wasn’t because of that. It’s interesting to note that your .vert has the #ifdef HAS_VERTEXCOLOR commented out but the .frag doesn’t. Based on your code that shouldn’t matter, though.

To debug, you have to get tricky with the frag shader and start commenting things out, setting colors funny or whatever that helps verify assumptions about what’s working and what isn’t.

Given that the code was invalid before, it could be that nVidia’s interpretation was accidentally leaving some stuff out that the right way is now running and clearing your color. Else I’d expect everything to be white.

Thanks for the suggestions. The errors went away but the dreaded black screen is back. I even switched to using Unshaded.j3md and set the color to blue just like in HelloMaterial but still no luck. That tells me the black screen is not a shader problem.

I can click and break blocks because I have a sound that plays when that happens so that tells me collision and chunk loading is working. My game loop seems to be functioning correctly. It makes me think that my chunk nodes aren’t being added to the scene but I seriously doubt that’s the case.

I’m going to have to just take HelloMaterial and start adding features to it until it renders a portion of my game to see what’s going on.

I’ll report back with my findings.

don’t underestimate the power of running a heap dump in jvisualvm or similar, and then following the references around…

I finally solved it.

In my project I had committed the lwjgl64.dll file that gets copied out into the working directory when my game runs. I’m not sure why that happens. It didn’t seem to happen when I run simple examples like HelloMaterial.

At any rate, I deleted that file, I noticed a new one got copied out there when the app was running but that fixed my black screen problem. I’m certain that was it because I copied it back out there after deleting it and ran it again and it showed the black screen again.

I have a couple more things to unwind since I went on a commenting rampage while trying to figure this out.

Thanks everyone for your help!