jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

Glsl150ShaderGenerator should include GLSLCompat for GLES3

Open riccardobl opened this issue 8 months ago • 2 comments
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)
 ...

riccardobl avatar Mar 14 '25 17:03 riccardobl

Workaround

  1. 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);
    }
}

  1. pass it in the assetManager at the beginning of simpleInitApp
        assetManager.setShaderGenerator(new GLES300ShaderGenerator(assetManager));

riccardobl avatar Mar 14 '25 17:03 riccardobl

@riccardobl Thank you for documenting the issue and the workaround.

stephengold avatar Mar 14 '25 18:03 stephengold