jmonkeyengine
jmonkeyengine copied to clipboard
Glsl150ShaderGenerator should include GLSLCompat for GLES3
trafficstars
Glsl150ShaderGenerator should include GLSLCompat in the shaders, or otherwise manually set the default precisions otherwise shadernodes for GLES3 will fail compilation with
com.jme3.renderer.RendererException: compile error in: ShaderSource[name=Default.frag, defines, type=Fragment, language=GLSL300]
ERROR: 0:11: '' : No precision specified for (float)
ERROR: 0:13: '' : No precision specified for (float)
ERROR: 0:14: '' : No precision specified for (float)
ERROR: 0:15: '' : No precision specified for (float)
...
Workaround
- add this patched generator to the app
package com.animotiv.designertest.system;
import com.jme3.asset.AssetManager;
import com.jme3.material.ShaderGenerationInfo;
import com.jme3.shader.Glsl300ShaderGenerator;
import com.jme3.shader.Shader;
public class GLES300ShaderGenerator extends Glsl300ShaderGenerator {
public GLES300ShaderGenerator(AssetManager assetManager) {
super(assetManager);
}
protected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) {
source.append( "#ifdef GL_ES\n" +
" #ifdef FRAGMENT_SHADER\n" +
" precision highp float;\n" +
" precision highp int;\n" +
" #if __VERSION__ >= 130\n" +
" precision highp sampler2DArray; \n" +
" #endif\n" +
" precision highp sampler2DArray;\n" +
" precision highp sampler2DShadow;\n" +
" precision highp samplerCube;\n" +
" precision highp sampler3D;\n" +
" precision highp sampler2D;\n" +
" #if __VERSION__ >= 310\n" +
" precision highp sampler2DMS;\n" +
" #endif\n" +
" #endif\n" +
"#endif\n");
super.generateUniforms(source, info, type);
}
}
- pass it in the
assetManagerat the beginning ofsimpleInitApp
assetManager.setShaderGenerator(new GLES300ShaderGenerator(assetManager));
@riccardobl Thank you for documenting the issue and the workaround.