I have copypasted a shader code from a jme 3.0 project (GitHub - nickidebruyn/galago: A easy to use and complete game development framework build for jMonkeyEngine3.0) into a 3.1 project. This is the code:
MaterialDef Default GUI {
MaterialParameters {
Int NumSamples
Int NumSamplesDepth
Texture2D Texture
Texture2D NoiseTexture
Color Color
Vector3 DistortionOffsets
Float DistortionTime
Float DistortionFrequency
}
Technique {
VertexShader GLSL100: Common/MatDefs/Post/Post.vert
FragmentShader GLSL100: MatDefs/chromatic-aberration.frag
WorldParameters {
WorldViewProjectionMatrix
}
}
}
uniform sampler2D m_Texture;
uniform sampler2D m_NoiseTexture;
uniform vec3 m_DistortionOffsets;
uniform float m_DistortionTime;
uniform float m_DistortionFrequency;
uniform vec4 m_Color;
varying vec2 texCoord;
void main() {
//vec4 texVal = texture2D(m_Texture, texCoord);
//gl_FragColor = texVal * m_Color;
float distortion = texture(m_NoiseTexture, vec2( (texCoord.t + m_DistortionTime) * m_DistortionFrequency, 0.5)).r;
vec3 offsets = distortion * m_DistortionOffsets;
vec3 color = vec3 (
texture(m_Texture, vec2(texCoord.s + offsets.r, texCoord.t)).r,
texture(m_Texture, vec2(texCoord.s + offsets.g, texCoord.t)).g,
texture(m_Texture, vec2(texCoord.s + offsets.b, texCoord.t)).b);
gl_FragColor = vec4(color,1);
}
And this is the error result:
Bad compile of:
1 #version 110
2 #define FRAGMENT_SHADER 1
3 uniform sampler2D m_Texture;
4 uniform sampler2D m_NoiseTexture;
5
6 uniform vec3 m_DistortionOffsets;
7 uniform float m_DistortionTime;
8 uniform float m_DistortionFrequency;
9
10 uniform vec4 m_Color;
11 varying vec2 texCoord;
12
13 void main() {
14 //vec4 texVal = texture2D(m_Texture, texCoord);
15 //gl_FragColor = texVal * m_Color;
16
17 float distortion = texture(m_NoiseTexture, vec2( (texCoord.t + m_DistortionTime) * m_DistortionFrequency, 0.5)).r;
18 vec3 offsets = distortion * m_DistortionOffsets;
19
20 vec3 color = vec3 (
21 texture(m_Texture, vec2(texCoord.s + offsets.r, texCoord.t)).r,
22 texture(m_Texture, vec2(texCoord.s + offsets.g, texCoord.t)).g,
23 texture(m_Texture, vec2(texCoord.s + offsets.b, texCoord.t)).b);
24
25 gl_FragColor = vec4(color,1);
26
27
28 }
mag 23, 2017 4:55:55 PM com.jme3.app.LegacyApplication handleError
GRAVE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=MatDefs/chromatic-aberration.frag, defines, type=Fragment, language=GLSL100]
ERROR: 0:17: 'texture' : no matching overloaded function found - implicit conversion not allowed
ERROR: 0:17: 'r' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:21: 'texture' : no matching overloaded function found - implicit conversion not allowed
ERROR: 0:21: 'r' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:22: 'texture' : no matching overloaded function found - implicit conversion not allowed
ERROR: 0:22: 'g' : field selection requires structure, vector, or matrix on left hand side
ERROR: 0:23: 'texture' : no matching overloaded function found - implicit conversion not allowed
ERROR: 0:23: 'b' : field selection requires structure, vector, or matrix on left hand side
at com.jme3.renderer.opengl.GLRenderer.updateShaderSourceData(GLRenderer.java:1200)
at com.jme3.renderer.opengl.GLRenderer.updateShaderData(GLRenderer.java:1227)
Googled the error, and it looks like I’m trying to read from a 2D sampler using 3D coordinates. But… how was it working with 3.0 then, and how should I fix it?
Thanks!