GitXplorerGitXplorer
b

flutter_gpu_shaders

public
12 stars
3 forks
0 issues

Commits

List of commits on branch master.
Verified
a70436ae2e2756cbc7ca584d4615586bbb1a4a04

Merge pull request #5 from dcharkes/upgrade-native-assets-cli

bbdero committed a month ago
Unverified
4c4aa46989f5ffdee1fb9b1bae5406fb11f63a0a

fix changelog

ddcharkes committed a month ago
Unverified
81b6993c65b12da6922c71235a51bf6e9dec3179

Upgrade to native_assets_cli 0.10.0

ddcharkes committed a month ago
Unverified
b454b35b5ebed04a55a9fc204c9e1d29208f2156

Upgrade to native_assets_cli 0.9.0 (breaking)

bbdero committed 2 months ago
Unverified
dd7ddf35d08a0e0daaabef24f8ac4c39299b2259

Cap native_assets_cli version to <0.9.0

bbdero committed 2 months ago
Unverified
429174206434120be2c3f25b74f9d0ffd2cd2ccb

Relax the native_assets_cli version pinning

bbdero committed 3 months ago

README

The README file for this repository.

Build tools for Flutter GPU shader bundles/libraries.

Features

Use native asset build hooks to import Flutter GPU shader bundle assets.

Getting started

  1. This package requires the experimental "native assets" feature to be enabled. Enable it with the following command:
    flutter config --enable-native-assets
  2. Place some Flutter GPU shaders in your project. For this example, we'll assume the existence of two shaders: shaders/my_cool_shader.vert and shaders/my_cool_shader.frag.
  3. Create a shader bundle manifest file in your project. The filename must end with .shaderbundle.json. For this example, we'll assume the following file is saved as my_cool_bundle.shaderbundle.json:
    {
        "CoolVertex": {
            "type": "vertex",
            "file": "shaders/my_cool_shader.vert"
        },
        "CoolFragment": {
            "type": "fragment",
            "file": "shaders/my_cool_shader.frag"
        }
    }
  4. Next, define a build hook in your project that builds the shader bundle using buildShaderBundleJson. The build hook must be named hook/build.dart in your project; this script will be automatically invoked by Flutter when the "native assets" feature is enabled:
    import 'package:native_assets_cli/native_assets_cli.dart';
    import 'package:flutter_gpu_shaders/build.dart';
    
    void main(List<String> args) async {
      await build(args, (config, output) async {
        await buildShaderBundleJson(
            buildConfig: config,
            buildOutput: output,
            manifestFileName: 'my_cool_bundle.shaderbundle.json');
      });
    }
  5. In your project's pubspec.yaml, add an asset import rule to package the built shader bundles (this will become unnecessary once "native assets" supports DataAsset in a future release of Flutter):
    flutter:
      assets:
        - build/shaderbundles/*.shaderbundle.json
  6. You can now import the built shader bundle as a library using gpu.ShaderLibrary.fromAsset in your project. For example:
    import 'package:flutter_gpu/gpu.dart' as gpu;
    
    final String _kBaseShaderBundlePath =
        'packages/my_project/build/shaderbundles/my_cool_bundle.shaderbundle';
    
    gpu.ShaderLibrary? _baseShaderLibrary = null;
    gpu.ShaderLibrary get baseShaderLibrary {
      if (_baseShaderLibrary != null) {
        return _baseShaderLibrary!;
      }
      _baseShaderLibrary = gpu.ShaderLibrary.fromAsset(_kBaseShaderBundlePath);
      if (_baseShaderLibrary != null) {
        return _baseShaderLibrary!;
      }
    
      throw Exception(
          "Failed to load base shader bundle! ($_kBaseShaderBundlePath)");
    }