load static method

Future<FragmentShader> load(
  1. String shaderName
)

Loads a fragment shader by shaderName.

The shaderName corresponds to the .frag file name without extension inside lib/shaders/glsl/. For example, passing 'glitch' loads packages/glow_effects/lib/shaders/glsl/glitch.frag.

The compiled FragmentProgram is cached so repeated calls with the same name do not recompile. A new FragmentShader instance is returned each time.

Throws a descriptive error if the shader asset cannot be found or compiled.

Implementation

static Future<FragmentShader> load(String shaderName) async {
  try {
    final program = _cache[shaderName] ??= await FragmentProgram.fromAsset(
      'packages/glow_effects/lib/shaders/glsl/$shaderName.frag',
    );
    return program.fragmentShader();
  } catch (e) {
    log(
      'GKShaderLoader: Failed to load shader "$shaderName". '
      'Ensure the .frag file exists and is listed in pubspec.yaml '
      'under flutter > shaders.',
      name: 'FlutterShaderEffects',
    );
    rethrow;
  }
}