Now gave me this error:
E/com.jme3.app.AndroidHarness(23925): SEVERE Exception thrown in Thread[GLThread 2491,5,main]
E/com.jme3.app.AndroidHarness(23925): com.jme3.renderer.RendererException: Shader link failure, shader:Shader[numSources=2, numUniforms=18, shaderSources=[ShaderSource[name=/Shaders/Dice.vert, defines, type=Vertex, language=GLSL100], ShaderSource[name=/Shaders/Dice.frag, defines, type=Fragment, language=GLSL100]]] info:Uniform variable g_AmbientLightColor type/precision does not match in vertex and fragment shader
E/com.jme3.app.AndroidHarness(23925):
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.android.OGLESShaderRenderer.updateShaderData(OGLESShaderRenderer.java:958)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.android.OGLESShaderRenderer.setShader(OGLESShaderRenderer.java:970)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.material.Material.renderMultipassLighting(Material.java:837)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.material.Material.render(Material.java:1107)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:523)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:322)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:374)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:763)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:719)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:983)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.app.AndroidHarness.update(AndroidHarness.java:467)
E/com.jme3.app.AndroidHarness(23925): at com.jme3.system.android.OGLESContext.onDrawFrame(OGLESContext.java:349)
E/com.jme3.app.AndroidHarness(23925): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1542)
E/com.jme3.app.AndroidHarness(23925): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1266)
I believe the important info is this:
Shader link failure, shader:Shader[numSources=2, numUniforms=18, shaderSources=[ShaderSource[name=/Shaders/Dice.vert, defines, type=Vertex, language=GLSL100], ShaderSource[name=/Shaders/Dice.frag, defines, type=Fragment, language=GLSL100]]] info:Uniform variable g_AmbientLightColor type/precision does not match in vertex and fragment shader
I compared both files and they are of the same type but i don’t know how to compare precision.
Here it is dice.frag and dice.vert
Dice.frag
[java]#define ATTENUATION
//#define HQ_ATTENUATION
varying vec2 texCoord;
varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;
varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
#ifdef DIFFUSEMAP
uniform sampler2D m_DiffuseMap;
#endif
#ifdef DIFFUSEMAP_BACK
uniform sampler2D m_DiffuseMapBack;
varying vec2 backgroundTexCoord;
#endif
#ifdef PARALLAXMAP
uniform sampler2D m_ParallaxMap;
#endif
#ifdef NORMALMAP
uniform sampler2D m_NormalMap;
#else
varying vec3 vNormal;
#endif
#ifdef ALPHAMAP
uniform sampler2D m_AlphaMap;
#endif
#ifdef DECAL_COLOR
uniform vec4 m_DecalColor;
#endif
#ifdef ENVMAP
uniform sampler2D m_EnvMap;
uniform float m_DecalMetal;
uniform float m_BackMetal;
varying vec2 reflectTexCoord;
#endif
uniform vec4 g_AmbientLightColor;
uniform float m_Shininess;
uniform vec4 g_LightDirection;
varying vec3 lightVec;
float tangDot(in vec3 v1, in vec3 v2){
float d = dot(v1,v2);
#ifdef V_TANGENT
d = 1.0 - d*d;
return step(0.0, d) * sqrt(d);
#else
return d;
#endif
}
float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
#ifdef MINNAERT
float NdotL = max(0.0, dot(norm, lightdir));
float NdotV = max(0.0, dot(norm, viewdir));
return NdotL * pow(max(NdotL * NdotV, 0.1), -1.0) * 0.5;
#else
return max(0.0, dot(norm, lightdir));
#endif
}
float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
#if defined(WARDISO)
// Isotropic Ward
vec3 halfVec = normalize(viewdir + lightdir);
float NdotH = max(0.001, tangDot(norm, halfVec));
float NdotV = max(0.001, tangDot(norm, viewdir));
float NdotL = max(0.001, tangDot(norm, lightdir));
float a = tan(acos(NdotH));
float p = max(shiny/128.0, 0.001);
return NdotL * (1.0 / (4.0*3.14159265*p*p)) * (exp(-(a*a)/(p*p)) / (sqrt(NdotV * NdotL)));
#else
// Standard Phong
vec3 R = reflect(-lightdir, norm);
return pow(max(tangDot(R, viewdir), 0.0), shiny);
#endif
}
vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
specularFactor *= step(1.0, m_Shininess);
#ifdef HQ_ATTENUATION
float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0);
#else
float att = vLightDir.w;
#endif
specularFactor *= diffuseFactor;
return vec2(diffuseFactor, specularFactor) * vec2(att);
}
void main(){
vec2 newTexCoord;
#if (defined(PARALLAXMAP) || defined(NORMALMAP_PARALLAX)) && !defined(VERTEX_LIGHTING)
float h;
#ifdef PARALLAXMAP
h = texture2D(m_ParallaxMap, texCoord).r;
#else
h = texture2D(m_NormalMap, texCoord).a;
#endif
float heightScale = 0.05;
float heightBias = heightScale * -0.5;
vec3 normView = normalize(vViewDir);
h = (h * heightScale + heightBias) * normView.z;
newTexCoord = texCoord + (h * normView.xy);
#else
newTexCoord = texCoord;
#endif
vec4 diffuseColor;
#ifdef DIFFUSEMAP
float alp = texture2D(m_DiffuseMap, newTexCoord).a;
diffuseColor.rgb = m_DecalColor.rgb*alp;
diffuseColor.a = alp;
#else
diffuseColor = vec4(1.0);
#endif
// ***********************
// Read from textures
// ***********************
#if defined(NORMALMAP)
vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
vec3 normal = (normalHeight.xyz * vec3(2.0) - vec3(1.0));
#ifdef LATC
normal.z = sqrt(1.0 - (normal.x * normal.x) - (normal.y * normal.y));
#endif
//normal.y = -normal.y;
#else
vec3 normal = vNormal;
#if !defined(LOW_QUALITY) && !defined(V_TANGENT)
normal = normalize(normal);
#endif
#endif
//color.rgb = color.rgb*(1-alp) + m_DecalColor.rgb*(alp);
//color.a = color.a*(1-alp) + m_DecalColor.a*(alp);
//TODO: check how alfa plays with transparency
//TODO: make separate ‘metal’ factor for decal and for background
#ifdef ENVMAP
vec4 env = texture2D( m_EnvMap, reflectTexCoord.st);
float useMetal = (m_DecalMetal*diffuseColor.a) + (m_BackMetal*(1.0 - diffuseColor.a));
diffuseColor.rgb = diffuseColor.rgb * (1.0 - useMetal) + env.rgb * (useMetal);
diffuseColor.a = max(diffuseColor.a,useMetal);
#endif
float alpha = max(DiffuseSum.a, diffuseColor.a);
#ifdef ALPHAMAP
alpha = alpha * texture2D(m_AlphaMap, newTexCoord).r;
#endif
#ifndef VERTEX_LIGHTING
float spotFallOff = 1.0;
if(g_LightDirection.w != 0.0){
vec3 L = normalize(lightVec.xyz);
vec3 spotdir = normalize(g_LightDirection.xyz);
float curAngleCos = dot(-L, spotdir);
float innerAngleCos = floor(g_LightDirection.w) * 0.001;
float outerAngleCos = fract(g_LightDirection.w);
float innerMinusOuter = innerAngleCos - outerAngleCos;
spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;
if(spotFallOff <= 0.0){
gl_FragColor.rgb = AmbientSum * diffuseColor.rgb;
gl_FragColor.a = alpha;
return;
}else{
spotFallOff = clamp(spotFallOff, 0.0, 1.0);
}
}
#endif
vec4 lightDir = vLightDir;
lightDir.xyz = normalize(lightDir.xyz);
vec2 light = computeLighting(vPosition, normal, vViewDir.xyz, lightDir.xyz) * spotFallOff;
vec4 finalColor;
#ifdef DIFFUSEMAP_BACK
vec4 backColor = texture2D(m_DiffuseMapBack, backgroundTexCoord);
finalColor.rgb = (g_AmbientLightColor.rgb + vec3(1.0)* light.x) * diffuseColor.rgb * diffuseColor.a +
(AmbientSum.rgb + DiffuseSum.rgb * light.x) * (1.0-diffuseColor.a)*backColor.rgb +
SpecularSum.rgb * light.y;
#else
finalColor.rgb = (g_AmbientLightColor.rgb + vec3(1.0)* light.x) * diffuseColor.rgb * diffuseColor.a +
(AmbientSum.rgb + DiffuseSum.rgb * light.x) * (1.0-diffuseColor.a) +
SpecularSum.rgb * light.y;
#endif
finalColor.a = alpha;
gl_FragColor = finalColor;
}[/java]
Dice.vert
[java]#define ATTENUATION
//#define HQ_ATTENUATION
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix;
uniform mat3 g_NormalMatrix;
uniform mat4 g_ViewMatrix;
uniform vec4 m_Ambient;
uniform vec4 m_Diffuse;
uniform vec4 m_Specular;
uniform float m_Shininess;
uniform vec4 g_LightColor;
uniform vec4 g_LightPosition;
uniform vec4 g_AmbientLightColor;
varying vec2 texCoord;
#ifdef ENVMAP
varying vec2 reflectTexCoord;
#endif
#if defined(DIFFUSEMAP_BACK) || defined(HAS_GLOWMAP)
varying vec2 backgroundTexCoord;
#endif
varying vec3 AmbientSum;
varying vec4 DiffuseSum;
varying vec3 SpecularSum;
attribute vec3 inPosition;
attribute vec2 inTexCoord;
attribute vec3 inNormal;
varying vec3 lightVec;
attribute vec3 inTangent;
#ifndef NORMALMAP
varying vec3 vNormal;
#endif
varying vec3 vPosition;
varying vec3 vViewDir;
varying vec4 vLightDir;
// JME3 lights in world space
void lightComputeDir(in vec3 worldPos, in vec4 color, in vec4 position, out vec4 lightDir){
float posLight = step(0.5, color.w);
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
lightVec = tempVec;
#ifdef ATTENUATION
float dist = length(tempVec);
lightDir.w = clamp(1.0 - position.w * dist * posLight, 0.0, 1.0);
lightDir.xyz = tempVec / vec3(dist);
#else
lightDir = vec4(normalize(tempVec), 1.0);
#endif
}
void main(){
vec4 pos = vec4(inPosition, 1.0);
gl_Position = g_WorldViewProjectionMatrix * pos;
texCoord = inTexCoord;
vec3 wvPosition = (g_WorldViewMatrix * pos).xyz;
vec3 wvNormal = normalize(g_NormalMatrix * inNormal);
vec3 viewDir = normalize(-wvPosition);
//vec4 lightColor = g_LightColor[gl_InstanceID];
//vec4 lightPos = g_LightPosition[gl_InstanceID];
//vec4 wvLightPos = (g_ViewMatrix * vec4(lightPos.xyz, lightColor.w));
//wvLightPos.w = lightPos.w;
vec4 wvLightPos = (g_ViewMatrix * vec4(g_LightPosition.xyz,clamp(g_LightColor.w,0.0,1.0)));
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;
#if defined(NORMALMAP)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent);
vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal, wvNormal);
vPosition = wvPosition * tbnMat;
vViewDir = viewDir * tbnMat;
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
#else
vNormal = wvNormal;
vPosition = wvPosition;
vViewDir = viewDir;
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
#ifdef V_TANGENT
vNormal = normalize(g_NormalMatrix * inTangent);
vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
#endif
#endif
lightColor.w = 1.0;
#ifdef MATERIAL_COLORS
AmbientSum = (m_Ambient * g_AmbientLightColor).rgb;
DiffuseSum = m_Diffuse * lightColor;
SpecularSum = (m_Specular * lightColor).rgb;
#else
AmbientSum = vec3(0.2, 0.2, 0.2) * g_AmbientLightColor.rgb; // Default: ambient color is dark gray
DiffuseSum = lightColor;
SpecularSum = lightColor.rgb;
#endif
#ifdef ENVMAP
vec3 u = normalize( wvPosition );
vec3 n = wvNormal;
vec3 r = reflect( u, n );
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
reflectTexCoord.s = r.x/m + 0.5;
reflectTexCoord.t = r.y/m + 0.5;
#endif
#if defined(DIFFUSEMAP_BACK) || defined(HAS_GLOWMAP)
vec3 r2 = normalize(inPosition);
float m2 = 2.0 * sqrt( r2.x*r2.x + r2.y*r2.y + (r2.z+1.0)*(r2.z+1.0) );
backgroundTexCoord.s = r2.x/m2 + 0.5;
backgroundTexCoord.t = r2.y/m2 + 0.5;
#endif
}[/java]
How can I fix the precision since they are of the same type?
Thanks in advance!