Skip to content

Add highPrecisionShader application setting for mobile optimization #1390

@obiot

Description

@obiot

Summary

Add a highPrecisionShader boolean to Application settings that controls the default WebGL shader float precision.

  • true (default) — uses the highest available precision (current behavior)
  • false — forces mediump precision, which is faster on mobile GPUs that support highp but run faster at mediump

Motivation

Mobile GPUs often support highp but execute mediump shaders 2-4x faster in fragment shaders. Currently melonJS auto-detects the highest precision and always uses it. Developers targeting mobile have no way to opt into lower precision for a performance boost without configuring each shader individually.

PixiJS v8 offers preferredFragmentPrecision / preferredVertexPrecision per-shader. A global boolean is simpler and covers the common case.

Implementation

  • Add highPrecisionShader: boolean to ApplicationSettings (default true)
  • Add to defaultApplicationSettings
  • Pass through to the WebGL renderer as settings.highPrecisionShader
  • In GLShader constructor, when no explicit precision parameter: use "mediump" if highPrecisionShader === false, otherwise auto-detect via getMaxShaderPrecision()
  • The per-shader precision parameter still overrides the global setting

References

  • GLShader: src/video/webgl/glshader.js — already accepts precision parameter
  • ShaderEffect: src/video/webgl/shadereffect.js — passes precision to GLShader
  • getMaxShaderPrecision: src/video/webgl/utils/precision.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions