Lwjgl parse error

Hello,



I made a simple shader demonstration for a friend, and gave him the source code. When he executes it on his jMonkeyPlatform (updated to last stable), he gets an error :



[java]Grave: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

com.jme3.renderer.RendererException: compile error in:ShaderSource[name=OffsetTextured.vert, defines, type=Vertex] error:ERROR: 0:3: ‘m_offsetX’ : syntax error parse error

at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderSourceData(LwjglRenderer.java:1007)

at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderData(LwjglRenderer.java:1045)

at com.jme3.renderer.lwjgl.LwjglRenderer.setShader(LwjglRenderer.java:1127)

at com.jme3.material.Material.render(Material.java:1100)

at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:658)

at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:301)

at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:350)

at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:919)

at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:850)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1126)

at com.jme3.renderer.RenderManager.render(RenderManager.java:1174)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:254)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:722)[/java]



It’s on a GEForce 310M.


Graphics Capabilities
FrameBuffer
FrameBufferMRT
OpenGL20
OpenGL21
ARBprogram
GLSL100
GLSL110
GLSL120
VertexTextureFetch
TextureArray
FloatTexture
FloatColorBuffer
FloatDepthBuffer
PackedFloatTexture
SharedExponentTexture
PackedFloatColorBuffer
NonPowerOfTwoTextures
MeshInstancing
VertexBufferArray


Here is the Material def :

OffsetTextured.j3md :
MaterialDef Colored Textured {

MaterialParameters {
Texture2D ColorMap
Color Color

Float offsetX
Float offsetY
Float sizeX
Float sizeY
}

Technique {
VertexShader GLSL100: OffsetTextured.vert
FragmentShader GLSL100: OffsetTextured.frag

WorldParameters {
WorldViewProjectionMatrix
}
}

Technique FixedFunc {
}

}


OffsetTextured.vert :
uniform mat4 g_WorldViewProjectionMatrix;

uniform Float m_offsetX;
uniform Float m_offsetY;
uniform Float m_sizeX;
uniform Float m_sizeY;

attribute vec3 inPosition;
attribute vec2 inTexCoord;

varying vec2 texCoord;

void main(){
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

Float x = inTexCoord.x * m_sizeX + m_offsetX;
Float y = inTexCoord.y * m_sizeY + m_offsetY;

texCoord = vec2( x, y );
}


OffsetTextured.frag :

varying vec2 texCoord;

uniform sampler2D m_ColorMap;
uniform vec4 m_Color;

void main(){
vec4 texColor = texture2D(m_ColorMap, texCoord);
gl_FragColor = vec4(mix(m_Color.rgb, texColor.rgb, texColor.a), 1.0);
}

And the main.java :
[java]public class Main extends SimpleApplication
{
public static void main( String[] args )
{
// Let's go !
AppSettings appSettings = new AppSettings( true );
appSettings.setVSync( true );

SimpleApplication sa = new Main( args );
sa.setSettings( appSettings );
sa.start();
}

public Main( String[] args )
{
}

@Override
public void simpleInitApp()
{
assetManager.registerLocator( "./assets/", FileLocator.class );
Texture texture = assetManager.loadTexture( "test.jpg" );
Quad quad = new Quad( 100, 100 );
Geometry geometry = new Geometry( "test", quad );

Material material = new Material( assetManager, "OffsetTextured.j3md" );
material.setTexture( "ColorMap", texture );
material.setColor( "Color", ColorRGBA.Red );
material.setFloat( "offsetX", 0.25f );
material.setFloat( "offsetY", 0.25f );
material.setFloat( "sizeX", 0.25f );
material.setFloat( "sizeY", 0.25f );

geometry.setMaterial( material );
geometry.setLocalTranslation(320 , 240, 0 );

guiNode.attachChild( geometry );
}
}
[/java]

Of course, it works on my computer... Is it a driver incompatibility problem ?

Thanks

not sure but for those 2 lines

[java]

Float x = inTexCoord.x * m_sizeX + m_offsetX;

Float y = inTexCoord.y * m_sizeY + m_offsetY;

[/java]

the f in float should be lower case



Edit : actually even for the uniforms declaration

1 Like

Right ! It works now. Thank you a lot nehon :slight_smile:



The strange part is it works on my computer with both Float or float. How is it possible ? o.o

Some drivers are more permissive than others. Ati drivers are reputed very strict, while nvidia ones are kinda loose, but it depends on the drivers/hardware version etc…

But IMO the most strict you can get is Ati drivers on OSX.

If your shader works on mac with an ati card, you’re pretty sure it’s working anywhere.

1 Like

This is a good thing to know.

I will have to be careful when coding Shaders on the permissive NVidia driver. :slight_smile:

@nehon said:
But IMO the most strict you can get is Ati drivers on OSX.
If your shader works on mac with an ati card, you're pretty sure it's working anywhere.

normally the card shouldn't even matter, the opengl implementation used is the same for both cards, apples own one instead of any of the drivers implementations. cards even need(ed) a special hardware extension apple.pixelbuffer or smth from times when there was no proper framebuffer support in gl yet.

I understood what caused the confusion in my mind.



j3md files requires you to write “Float” with an uppercase F (it refuses “float”). But in the shader, you have to write “float” with a lowercase.



Shouldn’t j3md files use “float” in lowercase to match the Shader syntax ?

@ozonegrif said:
Shouldn't j3md files use "float" in lowercase to match the Shader syntax ?

The grammar for j3md files is different than shader files (.vert/.frag). It's as simple as that.

It would be nice if j3md files supported both float and Float though to allow consistency while being backwardly compatible…

@zarch said:
It would be nice if j3md files supported both float and Float though to allow consistency while being backwardly compatible...

There was never a consistency between j3md and shaders and there shouldn't be. In some cases j3md binds directly to fixed function pipeline in OpenGL with no shaders at all. In some cases it binds to OpenGL ES shaders which have precision qualifiers like "lowp float". Also we have completely different names for other things as well. Matrix4Array has nothing to do with "mat4[]", and Texture2D has nothing to do with "sampler2D".
In other words, consistency is not possible to be achieved.
1 Like